Skip to content

Commit 84262d4

Browse files
authored
Merge pull request #58 from Cosmo-Tech/LAL/dataset_api_v5-PROD-14582
Lal/dataset api v5 prod 14582
2 parents 0a7d423 + 5a95b46 commit 84262d4

23 files changed

+212
-479
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e ".[test]"
25+
pip install -e ".[past]"
26+
27+
- name: Run tests with coverage
28+
run: |
29+
pytest tests/unit/coal/ --cov=cosmotech.coal --cov-report=term

cosmotech/coal/cosmotech_api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
)
1818

1919
from cosmotech.coal.utils.semver import semver_of
20-
csm_version = semver_of('cosmotech_api')
20+
21+
csm_version = semver_of("cosmotech_api")
2122
if csm_version.major < 5:
2223
# Re-export functions from the twin_data_layer module
2324
from cosmotech.coal.cosmotech_api.twin_data_layer import (

cosmotech/coal/cosmotech_api/dataset/download/file.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ def process_xls(target_file) -> Dict[str, Any]:
5252
content[sheet_name].append(new_row)
5353
row_count += 1
5454

55-
LOGGER.debug(
56-
T("coal.services.dataset.sheet_processed").format(sheet_name=sheet_name, rows=row_count)
57-
)
55+
LOGGER.debug(T("coal.services.dataset.sheet_processed").format(sheet_name=sheet_name, rows=row_count))
5856
return content
5957

6058

@@ -87,9 +85,7 @@ def process_csv(target_file) -> Dict[str, Any]:
8785
content[current_filename].append(new_row)
8886
row_count += 1
8987

90-
LOGGER.debug(
91-
T("coal.services.dataset.csv_processed").format(file_name=current_filename, rows=row_count)
92-
)
88+
LOGGER.debug(T("coal.services.dataset.csv_processed").format(file_name=current_filename, rows=row_count))
9389
return content
9490

9591

@@ -107,9 +103,7 @@ def process_json(target_file) -> Dict[str, Any]:
107103
else:
108104
item_count = 1
109105

110-
LOGGER.debug(
111-
T("coal.services.dataset.json_processed").format(file_name=current_filename, items=item_count)
112-
)
106+
LOGGER.debug(T("coal.services.dataset.json_processed").format(file_name=current_filename, items=item_count))
113107
return content
114108

115109

@@ -118,12 +112,10 @@ def process_txt(target_file) -> Dict[str, Any]:
118112
LOGGER.debug(T("coal.services.dataset.processing_text").format(file_name=target_file))
119113
with open(target_file, "r") as _file:
120114
current_filename = os.path.basename(target_file)
121-
content[current_filename] = "".join(line for line in _file)
115+
content[current_filename] = _file.read()
122116

123117
line_count = content[current_filename].count("\n") + 1
124-
LOGGER.debug(
125-
T("coal.services.dataset.text_processed").format(file_name=current_filename, lines=line_count)
126-
)
118+
LOGGER.debug(T("coal.services.dataset.text_processed").format(file_name=current_filename, lines=line_count))
127119
return content
128120

129121

@@ -140,6 +132,7 @@ def timed_read_file(file_name, file):
140132
else:
141133
content.update(process_txt(file))
142134
return content
135+
143136
return timed_read_file(file_name, file)
144137

145138

cosmotech/coal/cosmotech_api/dataset/download/twingraph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def download_twingraph_dataset(
6262
# Query edges
6363
edges_start = time.time()
6464
LOGGER.debug(T("coal.services.dataset.twingraph_querying_edges").format(dataset_id=dataset_id))
65-
edges_query = cosmotech_api.DatasetTwinGraphQuery(query="MATCH(n)-[r]->(m) RETURN n as src, r as rel, m as dest")
65+
edges_query = cosmotech_api.DatasetTwinGraphQuery(
66+
query="MATCH(n)-[r]->(m) RETURN n as src, r as rel, m as dest"
67+
)
6668

6769
edges = dataset_api.twingraph_query(
6870
organization_id=organization_id,

cosmotech/coal/cosmotech_api/runner/datasets.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def download_dataset(
5757
read_files: bool = True,
5858
) -> Dict[str, Any]:
5959
"""
60-
retro-compatibility to cosmo-api v4
60+
retro-compatibility to cosmo-api v4
6161
"""
6262
from cosmotech.coal.utils.semver import semver_of
6363

@@ -90,9 +90,9 @@ def download_dataset_v5(
9090
# Get dataset information
9191
with get_api_client()[0] as api_client:
9292
dataset_api_instance = DatasetApi(api_client)
93-
dataset = dataset_api_instance.get_dataset(organization_id=organization_id,
94-
workspace_id=workspace_id,
95-
dataset_id=dataset_id)
93+
dataset = dataset_api_instance.get_dataset(
94+
organization_id=organization_id, workspace_id=workspace_id, dataset_id=dataset_id
95+
)
9696

9797
content = dict()
9898
tmp_dataset_dir = tempfile.mkdtemp()
@@ -223,9 +223,7 @@ def download_dataset_v4(
223223
}
224224

225225

226-
def download_dataset_process(
227-
_dataset_id, organization_id, workspace_id, read_files, _return_dict, _error_dict
228-
):
226+
def download_dataset_process(_dataset_id, organization_id, workspace_id, read_files, _return_dict, _error_dict):
229227
"""
230228
Process function for downloading a dataset in a separate process.
231229

cosmotech/coal/utils/api.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

cosmotech/coal/utils/decorator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ def wrapper(*args, **kwargs):
1919
else:
2020
LOGGER.info(msg)
2121
return r
22+
2223
return wrapper
24+
2325
return decorator

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_run_template.py

Lines changed: 3 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,10 @@
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(semver_of("cosmotech_api").major >= 5, reason="not supported in version 5")
2223
class TestRunTemplateFunctions:
2324
"""Tests for top-level functions in the run_template module."""
2425

@@ -66,7 +67,6 @@ def test_load_run_template_handlers_success(self):
6667
patch("cosmotech.coal.cosmotech_api.run_template.WorkspaceApi", return_value=mock_workspace_api),
6768
patch("cosmotech.coal.cosmotech_api.run_template.SolutionApi", return_value=mock_solution_api),
6869
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,
7070
patch("cosmotech.coal.cosmotech_api.run_template.pathlib.Path") as mock_path_class,
7171
):
7272
mock_path_class.return_value = mock_path

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +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,
32-
)
17+
18+
from cosmotech.coal.utils.semver import semver_of
19+
from cosmotech_api import DatasetApi, RunnerApi
20+
21+
if semver_of("cosmotech_api").major < 5:
22+
from cosmotech_api import DatasetTwinGraphQuery
23+
24+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
25+
get_dataset_id_from_runner,
26+
send_files_to_tdl,
27+
load_files_from_tdl,
28+
CSVSourceFile,
29+
_process_csv_file,
30+
_get_node_properties,
31+
_get_relationship_properties,
32+
_execute_queries,
33+
_write_files,
34+
ID_COLUMN,
35+
SOURCE_COLUMN,
36+
TARGET_COLUMN,
37+
)
38+
39+
pytestmark = pytest.mark.skipif(semver_of("cosmotech_api").major >= 5, reason="not supported under version 5")
3340

3441

3542
class TestCSVSourceFile:

tests/unit/coal/test_cosmotech_api/test_cosmotech_api_twin_data_layer_auth.py

Lines changed: 16 additions & 8 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
17+
18+
from cosmotech.coal.utils.semver import semver_of
19+
from cosmotech_api import DatasetApi, RunnerApi
20+
21+
if semver_of("cosmotech_api").major < 5:
22+
from cosmotech_api import DatasetTwinGraphQuery
23+
from cosmotech.coal.cosmotech_api.twin_data_layer import (
24+
send_files_to_tdl,
25+
load_files_from_tdl,
26+
_process_csv_file,
27+
_get_node_properties,
28+
_get_relationship_properties,
29+
)
1830

1931
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,
26-
)
32+
33+
skip_under_v5 = pytest.mark.skipif(semver_of("cosmotech_api").major >= 5, reason="not supported under version 5")
2734

2835

36+
@skip_under_v5
2937
class TestTwinDataLayerAuth:
3038
"""Tests for authentication in the twin_data_layer module."""
3139

0 commit comments

Comments
 (0)