Skip to content

Commit d1409ce

Browse files
committed
fix test by skipping unsupported test for version 5.0 of the API
1 parent 90233aa commit d1409ce

15 files changed

+133
-379
lines changed

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_run_template.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import pathlib
99
import pytest
10-
from unittest.mock import MagicMock, patch, mock_open
11-
from io import BytesIO
10+
from unittest.mock import MagicMock, patch
1211
from zipfile import BadZipfile, ZipFile
1312

1413
import cosmotech_api
@@ -17,8 +16,12 @@
1716
from cosmotech_api.exceptions import ServiceException
1817

1918
from cosmotech.coal.cosmotech_api.run_template import load_run_template_handlers
19+
from cosmotech.coal.utils.semver import semver_of
2020

2121

22+
@pytest.mark.skipif(
23+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
24+
)
2225
class TestRunTemplateFunctions:
2326
"""Tests for top-level functions in the run_template module."""
2427

@@ -66,7 +69,6 @@ def test_load_run_template_handlers_success(self):
6669
patch("cosmotech.coal.cosmotech_api.run_template.WorkspaceApi", return_value=mock_workspace_api),
6770
patch("cosmotech.coal.cosmotech_api.run_template.SolutionApi", return_value=mock_solution_api),
6871
patch("cosmotech.coal.cosmotech_api.run_template.ZipFile", return_value=mock_zipfile_context),
69-
patch("cosmotech.coal.cosmotech_api.run_template.BytesIO") as mock_bytesio,
7072
patch("cosmotech.coal.cosmotech_api.run_template.pathlib.Path") as mock_path_class,
7173
):
7274
mock_path_class.return_value = mock_path

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@
1414

1515
import pytest
1616
import requests
17-
from cosmotech_api import DatasetApi, RunnerApi, DatasetTwinGraphQuery
18-
19-
from cosmotech.coal.cosmotech_api.twin_data_layer import (
20-
get_dataset_id_from_runner,
21-
send_files_to_tdl,
22-
load_files_from_tdl,
23-
CSVSourceFile,
24-
_process_csv_file,
25-
_get_node_properties,
26-
_get_relationship_properties,
27-
_execute_queries,
28-
_write_files,
29-
ID_COLUMN,
30-
SOURCE_COLUMN,
31-
TARGET_COLUMN,
17+
18+
from cosmotech.coal.utils.semver import semver_of
19+
from cosmotech_api import DatasetApi, RunnerApi
20+
if semver_of('cosmotech_api').major < 5:
21+
from cosmotech_api import DatasetTwinGraphQuery
22+
23+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
24+
get_dataset_id_from_runner,
25+
send_files_to_tdl,
26+
load_files_from_tdl,
27+
CSVSourceFile,
28+
_process_csv_file,
29+
_get_node_properties,
30+
_get_relationship_properties,
31+
_execute_queries,
32+
_write_files,
33+
ID_COLUMN,
34+
SOURCE_COLUMN,
35+
TARGET_COLUMN,
36+
)
37+
38+
pytestmark = pytest.mark.skipif(
39+
semver_of('cosmotech_api').major >= 5, reason='not supported under version 5'
3240
)
3341

3442

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_auth.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414

1515
import pytest
1616
import requests
17-
from cosmotech_api import DatasetApi, RunnerApi, DatasetTwinGraphQuery
17+
18+
from cosmotech.coal.utils.semver import semver_of
19+
from cosmotech_api import DatasetApi, RunnerApi
20+
if semver_of('cosmotech_api').major < 5:
21+
from cosmotech_api import DatasetTwinGraphQuery
22+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
23+
send_files_to_tdl,
24+
load_files_from_tdl,
25+
_process_csv_file,
26+
_get_node_properties,
27+
_get_relationship_properties,
28+
)
1829

1930
from cosmotech.orchestrator.utils.translate import T
20-
from cosmotech.coal.cosmotech_api.twin_data_layer import (
21-
send_files_to_tdl,
22-
load_files_from_tdl,
23-
_process_csv_file,
24-
_get_node_properties,
25-
_get_relationship_properties,
31+
32+
skip_under_v5 = pytest.mark.skipif(
33+
semver_of('cosmotech_api').major >= 5, reason='not supported under version 5'
2634
)
2735

2836

37+
@skip_under_v5
2938
class TestTwinDataLayerAuth:
3039
"""Tests for authentication in the twin_data_layer module."""
3140

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_coverage.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,28 @@
1717

1818
import pytest
1919
import requests
20-
from cosmotech_api import DatasetApi, RunnerApi, DatasetTwinGraphQuery
21-
22-
from cosmotech.coal.cosmotech_api.twin_data_layer import (
23-
get_dataset_id_from_runner,
24-
send_files_to_tdl,
25-
load_files_from_tdl,
26-
_process_csv_file,
27-
_write_files,
28-
BATCH_SIZE_LIMIT,
20+
21+
from cosmotech.coal.utils.semver import semver_of
22+
from cosmotech_api import DatasetApi, RunnerApi
23+
24+
if semver_of('cosmotech_api').major < 5:
25+
from cosmotech_api import DatasetTwinGraphQuery
26+
27+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
28+
get_dataset_id_from_runner,
29+
send_files_to_tdl,
30+
load_files_from_tdl,
31+
_process_csv_file,
32+
_write_files,
33+
BATCH_SIZE_LIMIT,
34+
)
35+
36+
skip_under_v5 = pytest.mark.skipif(
37+
semver_of('cosmotech_api').major >= 5, reason='not supported under version 5'
2938
)
3039

3140

41+
@skip_under_v5
3242
class TestTwinDataLayerCoverage:
3343
"""Additional tests for the twin_data_layer module to improve coverage."""
3444

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_edge_cases.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,26 @@
1414

1515
import pytest
1616
import requests
17-
from cosmotech_api import DatasetApi, RunnerApi, DatasetTwinGraphQuery
1817

18+
from cosmotech.coal.utils.semver import semver_of
19+
from cosmotech_api import DatasetApi, RunnerApi
20+
if semver_of('cosmotech_api').major < 5:
21+
from cosmotech_api import DatasetTwinGraphQuery
22+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
23+
send_files_to_tdl,
24+
load_files_from_tdl,
25+
_process_csv_file,
26+
_get_node_properties,
27+
_get_relationship_properties,
28+
)
1929
from cosmotech.orchestrator.utils.translate import T
20-
from cosmotech.coal.cosmotech_api.twin_data_layer import (
21-
send_files_to_tdl,
22-
load_files_from_tdl,
23-
_process_csv_file,
24-
_get_node_properties,
25-
_get_relationship_properties,
30+
31+
skip_under_v5 = pytest.mark.skipif(
32+
semver_of('cosmotech_api').major >= 5, reason='not supported under version 5'
2633
)
2734

2835

36+
@skip_under_v5
2937
class TestTwinDataLayerEdgeCases:
3038
"""Tests for edge cases in the twin_data_layer module."""
3139

tests/unit/coal/test_cosmotech_api/test_dataset/test_download/test_download_twingraph.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111

1212
import pytest
1313
import cosmotech_api
14-
from cosmotech_api import DatasetApi, TwingraphApi
15-
16-
from cosmotech.coal.cosmotech_api.dataset.download.twingraph import (
17-
download_twingraph_dataset,
18-
download_legacy_twingraph_dataset,
14+
from cosmotech_api import DatasetApi
15+
from cosmotech.coal.utils.semver import semver_of
16+
if semver_of('cosmotech_api').major < 5:
17+
from cosmotech_api import TwingraphApi
18+
from cosmotech.coal.cosmotech_api.dataset.download.twingraph import (
19+
download_twingraph_dataset,
20+
download_legacy_twingraph_dataset,
21+
)
22+
23+
skip_under_v5 = pytest.mark.skipif(
24+
semver_of('cosmotech_api').major >= 5, reason='not supported under version 5'
1925
)
2026

2127

28+
@skip_under_v5
2229
class TestTwingraphFunctions:
2330
"""Tests for top-level functions in the twingraph module."""
2431

tests/unit/coal/test_cosmotech_api/test_runner/test_runner_datasets.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
# etc., to any person is prohibited unless it has been previously and
66
# specifically authorized by written means by Cosmo Tech.
77

8-
import multiprocessing
9-
import tempfile
108
from pathlib import Path
119
from unittest.mock import MagicMock, patch, call
12-
1310
import pytest
14-
from azure.identity import DefaultAzureCredential
11+
1512
from cosmotech_api import DatasetApi
1613

1714
from cosmotech.coal.cosmotech_api.runner.datasets import (
@@ -22,6 +19,7 @@
2219
download_datasets,
2320
dataset_to_file,
2421
)
22+
from cosmotech.coal.utils.semver import semver_of
2523

2624

2725
class TestDatasetsFunctions:
@@ -60,6 +58,9 @@ def test_get_dataset_ids_from_runner(self):
6058

6159
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
6260
@patch("cosmotech.coal.cosmotech_api.runner.datasets.download_adt_dataset")
61+
@pytest.mark.skipif(
62+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
63+
)
6364
def test_download_dataset_adt(self, mock_download_adt, mock_get_api_client):
6465
"""Test the download_dataset function with ADT dataset."""
6566
# Arrange
@@ -106,6 +107,9 @@ def test_download_dataset_adt(self, mock_download_adt, mock_get_api_client):
106107

107108
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
108109
@patch("cosmotech.coal.cosmotech_api.runner.datasets.download_legacy_twingraph_dataset")
110+
@pytest.mark.skipif(
111+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
112+
)
109113
def test_download_dataset_legacy_twingraph(self, mock_download_legacy, mock_get_api_client):
110114
"""Test the download_dataset function with legacy twin graph dataset."""
111115
# Arrange
@@ -153,6 +157,9 @@ def test_download_dataset_legacy_twingraph(self, mock_download_legacy, mock_get_
153157

154158
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
155159
@patch("cosmotech.coal.cosmotech_api.runner.datasets.download_file_dataset")
160+
@pytest.mark.skipif(
161+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
162+
)
156163
def test_download_dataset_storage(self, mock_download_file, mock_get_api_client):
157164
"""Test the download_dataset function with storage dataset."""
158165
# Arrange
@@ -205,6 +212,9 @@ def test_download_dataset_storage(self, mock_download_file, mock_get_api_client)
205212

206213
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
207214
@patch("cosmotech.coal.cosmotech_api.runner.datasets.download_file_dataset")
215+
@pytest.mark.skipif(
216+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
217+
)
208218
def test_download_dataset_workspace_file(self, mock_download_file, mock_get_api_client):
209219
"""Test the download_dataset function with workspace file dataset."""
210220
# Arrange
@@ -260,6 +270,9 @@ def test_download_dataset_workspace_file(self, mock_download_file, mock_get_api_
260270

261271
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
262272
@patch("cosmotech.coal.cosmotech_api.runner.datasets.download_twingraph_dataset")
273+
@pytest.mark.skipif(
274+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
275+
)
263276
def test_download_dataset_twingraph(self, mock_download_twingraph, mock_get_api_client):
264277
"""Test the download_dataset function with twin graph dataset."""
265278
# Arrange
@@ -309,6 +322,9 @@ def test_download_dataset_twingraph(self, mock_download_twingraph, mock_get_api_
309322
@patch("multiprocessing.Process")
310323
@patch("multiprocessing.Manager")
311324
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
325+
@pytest.mark.skipif(
326+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
327+
)
312328
def test_download_datasets_parallel(self, mock_get_api_client, mock_manager, mock_process, mock_download_dataset):
313329
"""Test the download_datasets_parallel function."""
314330
# Arrange
@@ -392,14 +408,12 @@ def test_download_datasets_sequential(self, mock_get_api_client, mock_download_d
392408
workspace_id=workspace_id,
393409
dataset_id="dataset-1",
394410
read_files=True,
395-
credentials=None,
396411
),
397412
call(
398413
organization_id=organization_id,
399414
workspace_id=workspace_id,
400415
dataset_id="dataset-2",
401416
read_files=True,
402-
credentials=None,
403417
),
404418
]
405419
)
@@ -436,7 +450,6 @@ def test_download_datasets_parallel_mode(self, mock_sequential, mock_parallel):
436450
workspace_id=workspace_id,
437451
dataset_ids=dataset_ids,
438452
read_files=True,
439-
credentials=None,
440453
)
441454
mock_sequential.assert_not_called()
442455
assert len(result) == 2
@@ -472,7 +485,6 @@ def test_download_datasets_sequential_mode(self, mock_sequential, mock_parallel)
472485
workspace_id=workspace_id,
473486
dataset_ids=dataset_ids,
474487
read_files=True,
475-
credentials=None,
476488
)
477489
mock_parallel.assert_not_called()
478490
assert len(result) == 2
@@ -507,7 +519,6 @@ def test_download_datasets_single_dataset(self, mock_sequential, mock_parallel):
507519
workspace_id=workspace_id,
508520
dataset_ids=dataset_ids,
509521
read_files=True,
510-
credentials=None,
511522
)
512523
mock_parallel.assert_not_called()
513524
assert len(result) == 1

tests/unit/coal/test_cosmotech_api/test_runner/test_runner_datasets_additional.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
# etc., to any person is prohibited unless it has been previously and
66
# specifically authorized by written means by Cosmo Tech.
77

8-
import multiprocessing
98
from pathlib import Path
10-
from unittest.mock import MagicMock, patch, call
9+
from unittest.mock import MagicMock, patch
1110

1211
import pytest
13-
from azure.identity import DefaultAzureCredential
1412
from cosmotech_api import DatasetApi
1513

1614
from cosmotech.coal.cosmotech_api.runner.datasets import (
@@ -19,12 +17,16 @@
1917
download_datasets,
2018
dataset_to_file,
2119
)
20+
from cosmotech.coal.utils.semver import semver_of
2221

2322

2423
class TestDatasetsAdditional:
2524
"""Additional tests for the datasets module to improve coverage."""
2625

2726
@patch("cosmotech.coal.cosmotech_api.runner.datasets.get_api_client")
27+
@pytest.mark.skipif(
28+
semver_of('cosmotech_api').major >= 5, reason='not supported in version 5'
29+
)
2830
def test_download_dataset_no_connector(self, mock_get_api_client):
2931
"""Test the download_dataset function with a dataset that has no connector."""
3032
# Arrange
@@ -189,12 +191,11 @@ def test_download_datasets_parallel_start_join(self, mock_get_api_client, mock_m
189191
mock_process.side_effect = [mock_process_instance1, mock_process_instance2]
190192

191193
# Act
192-
with patch("cosmotech.coal.cosmotech_api.runner.datasets.download_dataset") as mock_download_dataset:
193-
download_datasets_parallel(
194-
organization_id=organization_id,
195-
workspace_id=workspace_id,
196-
dataset_ids=dataset_ids,
197-
)
194+
download_datasets_parallel(
195+
organization_id=organization_id,
196+
workspace_id=workspace_id,
197+
dataset_ids=dataset_ids,
198+
)
198199

199200
# Assert
200201
# Check that start and join were called for each process

0 commit comments

Comments
 (0)