Skip to content

Commit eeb7af8

Browse files
committed
Use format=None to return raw Python data structure
1 parent 7652bba commit eeb7af8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/norwegianblue/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def error_404_text(product: str, suggestion: str) -> str:
3030

3131
def norwegianblue(
3232
product: str = "all",
33-
format: str = "pretty",
33+
format: str | None = "pretty",
3434
color: str = "yes",
3535
show_title: bool = False,
36-
) -> str:
36+
) -> str | list[dict]:
3737
"""Call the API and return result"""
3838
if format == "md":
3939
format = "markdown"
@@ -85,6 +85,9 @@ def norwegianblue(
8585

8686
data: list[dict] = list(res)
8787

88+
if format is None:
89+
return data
90+
8891
if product == "all":
8992
return "\n".join(data)
9093

tests/test_norwegianblue.py

+24
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ def test_norwegianblue_formats(
103103
# Assert
104104
assert output.strip() == expected.strip()
105105

106+
@freeze_time("2023-11-23")
107+
@respx.mock
108+
def test_norwegianblue_no_format(self) -> None:
109+
# Arrange
110+
mocked_url = "https://endoflife.date/api/ubuntu.json"
111+
mocked_response = SAMPLE_RESPONSE_JSON_UBUNTU
112+
test_format = None
113+
114+
# Act
115+
respx.get(mocked_url).respond(content=mocked_response)
116+
output = norwegianblue.norwegianblue(product="ubuntu", format=test_format)
117+
118+
# Assert
119+
assert output[0] == {
120+
"cycle": "22.04",
121+
"codename": "Jammy Jellyfish",
122+
"support": "2027-04-02",
123+
"eol": "2032-04-01",
124+
"lts": True,
125+
"latest": "22.04",
126+
"link": "https://wiki.ubuntu.com/JammyJellyfish/ReleaseNotes/",
127+
"releaseDate": "2022-04-21",
128+
}
129+
106130
@mock.patch.dict(os.environ, {"NO_COLOR": "TRUE"})
107131
@respx.mock
108132
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)