Skip to content

Commit 4848451

Browse files
committed
add more unit tests
1 parent 721985c commit 4848451

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

deep_code/tests/tools/test_publish.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from pathlib import Path
55
from unittest.mock import MagicMock, mock_open, patch
66

7+
import pytest
78
import yaml
89
from pystac import Catalog
910

1011
from deep_code.tools.publish import Publisher
12+
from deep_code.utils.ogc_api_record import LinksBuilder
1113

1214

1315
class TestPublisher(unittest.TestCase):
@@ -107,3 +109,59 @@ def test_read_config_files(self):
107109
# Assertions
108110
self.assertEqual(self.publisher.dataset_config, dataset_config)
109111
self.assertEqual(self.publisher.workflow_config, workflow_config)
112+
113+
114+
class TestParseGithubNotebookUrl:
115+
@pytest.mark.parametrize(
116+
"url,repo_url,repo_name,branch,file_path",
117+
[
118+
(
119+
"https://github.com/deepesdl/cube-gen/blob/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
120+
"https://github.com/deepesdl/cube-gen",
121+
"cube-gen",
122+
"main",
123+
"Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
124+
),
125+
(
126+
"https://github.com/deepesdl/cube-gen/tree/release-1.0/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
127+
"https://github.com/deepesdl/cube-gen",
128+
"cube-gen",
129+
"release-1.0",
130+
"Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
131+
),
132+
(
133+
"https://raw.githubusercontent.com/deepesdl/cube-gen/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
134+
"https://github.com/deepesdl/cube-gen",
135+
"cube-gen",
136+
"main",
137+
"Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb",
138+
),
139+
],
140+
)
141+
def test_valid_urls(self, url, repo_url, repo_name, branch, file_path):
142+
got_repo_url, got_repo_name, got_branch, got_file_path = LinksBuilder._parse_github_notebook_url(
143+
url
144+
)
145+
assert got_repo_url == repo_url
146+
assert got_repo_name == repo_name
147+
assert got_branch == branch
148+
assert got_file_path == file_path
149+
150+
def test_invalid_domain(self):
151+
url = "https://gitlab.com/deepesdl/cube-gen/-/blob/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb"
152+
with pytest.raises(ValueError) as e:
153+
LinksBuilder._parse_github_notebook_url(url)
154+
assert "Only GitHub URLs are supported" in str(e.value)
155+
156+
def test_unexpected_github_format_missing_blob_or_tree(self):
157+
# Missing the "blob" or "tree" segment
158+
url = "https://github.com/deepesdl/cube-gen/main/Permafrost/Create-CCI-Permafrost-cube-EarthCODE.ipynb"
159+
with pytest.raises(ValueError) as e:
160+
LinksBuilder._parse_github_notebook_url(url)
161+
assert "Unexpected GitHub URL format" in str(e.value)
162+
163+
def test_unexpected_raw_format_too_short(self):
164+
url = "https://raw.githubusercontent.com/deepesdl/cube-gen/main"
165+
with pytest.raises(ValueError) as e:
166+
LinksBuilder._parse_github_notebook_url(url)
167+
assert "Unexpected raw.githubusercontent URL format" in str(e.value)

0 commit comments

Comments
 (0)