Skip to content

Commit

Permalink
Add tests for format_url.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nf679 committed Jan 13, 2025
1 parent 567c2cc commit 6a5732b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nlds/utils/format_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def format_url(url_parts, query_params=None):
Returns:
base (str): The constructed URL.
"""

if not isinstance(url_parts, list):
raise TypeError("url_parts must be a list")

if not url_parts:
return ""

Expand Down
21 changes: 21 additions & 0 deletions tests/nlds/utils/test_format_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from nlds.utils.format_url import format_url
import pytest


def test_no_parts():
Expand Down Expand Up @@ -34,3 +35,23 @@ def test_complex_query_params():
query_params = {"q": "test search", "page": "1", "sort": "asc"}
expected_url = "http://example.com/search?q=test+search&page=1&sort=asc"
assert format_url(url_parts, query_params) == expected_url


def test_string():
with pytest.raises(TypeError):
format_url("not-a-list")


def test_int():
with pytest.raises(TypeError):
format_url(1)


def test_float():
with pytest.raises(TypeError):
format_url(1.0)


def test_dict():
with pytest.raises(TypeError):
format_url({"url_parts": "www.example.com"})

0 comments on commit 6a5732b

Please sign in to comment.