Skip to content

Commit

Permalink
[NEAT-219] Moved legacy tests πŸ‘΄ (#428)
Browse files Browse the repository at this point in the history
* refactor: moved all tests into legacy

* refactor: Moved ExcelImporter rules to the correct place
  • Loading branch information
doctrino committed May 4, 2024
1 parent 3cac7ab commit dddd414
Show file tree
Hide file tree
Showing 42 changed files with 796 additions and 830 deletions.
79 changes: 0 additions & 79 deletions tests/tests_unit/rules/importer/test_excel2rules.py

This file was deleted.

24 changes: 16 additions & 8 deletions tests/tests_unit/rules/test_importers/test_excel_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
from cognite.neat.rules import issues as validation
from cognite.neat.rules.importers import ExcelImporter
from cognite.neat.rules.issues import IssueList
from cognite.neat.rules.models.rules import DMSRules, InformationRules
from cognite.neat.rules.models.rules import DMSRules, DomainRules, InformationRules
from tests.config import DOC_RULES
from tests.tests_unit.rules.test_importers.constants import EXCEL_IMPORTER_DATA


def valid_dms_rules_filepaths():
yield pytest.param(DOC_RULES / "cdf-dms-architect-alice.xlsx", DMSRules, id="Alice rules")
yield pytest.param(DOC_RULES / "information-analytics-olav.xlsx", InformationRules, id="Olav user rules")


def invalid_rules_filepaths():
yield pytest.param(
DOC_RULES / "not-existing.xlsx",
Expand Down Expand Up @@ -89,8 +84,21 @@ def invalid_rules_filepaths():


class TestExcelImporter:
@pytest.mark.parametrize("filepath, rule_type", valid_dms_rules_filepaths())
def test_import_valid_rules(self, filepath: Path, rule_type: DMSRules | InformationRules):
@pytest.mark.parametrize(
"filepath, rule_type",
[
pytest.param(DOC_RULES / "cdf-dms-architect-alice.xlsx", DMSRules, id="Alice rules"),
pytest.param(DOC_RULES / "information-analytics-olav.xlsx", InformationRules, id="Olav user rules"),
pytest.param(DOC_RULES / "expert-wind-energy-jon.xlsx", DomainRules, id="expert-wind-energy-jon"),
pytest.param(DOC_RULES / "expert-grid-emma.xlsx", DomainRules, id="expert-grid-emma"),
pytest.param(
DOC_RULES / "information-architect-david.xlsx", InformationRules, id="information-architect-david"
),
],
)
def test_import_valid_rules(
self, filepath: Path, rule_type: type[DMSRules] | type[InformationRules] | type[DomainRules]
):
importer = ExcelImporter(filepath)
rules = importer.to_rules(errors="raise")
assert isinstance(rules, rule_type)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import re
import sys

from cognite import neat
from tests.config import PYPROJECT_TOML, ROOT

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib


def _extract_version_from_file(filename, search_pattern, error_message):
changelog = (ROOT / filename).read_text()
if not (changelog_version_result := re.search(search_pattern, changelog)):
raise ValueError(error_message)
return changelog_version_result.groups()[0]


def test_consistent_version_variables():
pyproject = tomllib.loads(PYPROJECT_TOML.read_text())
pyproject_toml = pyproject["tool"]["poetry"]["version"]

changelog_version = _extract_version_from_file(
"./docs/CHANGELOG.md",
r"\[(\d+\.\d+\.\d+)\]",
"Failed to obtain changelog version",
)
docker_version = _extract_version_from_file(
"Makefile",
r'version="(\d+\.\d+\.\d+)"',
"Failed to obtain docker version",
)
assert neat.__version__ == changelog_version == pyproject_toml == docker_version, "Inconsistent version variables"


def test_no_spaces_in_sub_folders() -> None:
name_by_location = {path: path.name for path in (ROOT / "cognite").rglob("*") if path.is_dir() and " " in path.name}

assert not name_by_location, f"Subfolders with spaces found: {name_by_location}"
import re
import sys

from cognite import neat
from tests.config import PYPROJECT_TOML, ROOT

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib


def _extract_version_from_file(filename, search_pattern, error_message):
changelog = (ROOT / filename).read_text()
if not (changelog_version_result := re.search(search_pattern, changelog)):
raise ValueError(error_message)
return changelog_version_result.groups()[0]


def test_consistent_version_variables():
pyproject = tomllib.loads(PYPROJECT_TOML.read_text())
pyproject_toml = pyproject["tool"]["poetry"]["version"]

changelog_version = _extract_version_from_file(
"./docs/CHANGELOG.md",
r"\[(\d+\.\d+\.\d+)\]",
"Failed to obtain changelog version",
)
docker_version = _extract_version_from_file(
"Makefile",
r'version="(\d+\.\d+\.\d+)"',
"Failed to obtain docker version",
)
assert neat.__version__ == changelog_version == pyproject_toml == docker_version, "Inconsistent version variables"


def test_no_spaces_in_sub_folders() -> None:
name_by_location = {path: path.name for path in (ROOT / "cognite").rglob("*") if path.is_dir() and " " in path.name}

assert not name_by_location, f"Subfolders with spaces found: {name_by_location}"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from cognite.neat.legacy.graph import extractors as graph_extractor
from cognite.neat.legacy.graph.extractors._graph_capturing_sheet import rules2graph_capturing_sheet
from cognite.neat.legacy.rules.importers import ExcelImporter
from tests import config


def test_graph_capturing_sheet(tmp_path, simple_rules):
extractor = graph_extractor.GraphCapturingSheet(
simple_rules, config.GRAPH_CAPTURING_SHEET, store_graph_capturing_sheet=True
)
_ = extractor.extract()
graph_capturing_sheet = extractor.sheet
tmp_sheet = tmp_path / "temp_graph_capturing.xlsx"

rules2graph_capturing_sheet(simple_rules, tmp_sheet, add_drop_down_list=True, auto_identifier_type="uuid")
resulting_sheet = ExcelImporter(tmp_sheet).to_tables()
assert resulting_sheet.keys() == graph_capturing_sheet.keys()
for sheet_name in resulting_sheet.keys():
assert list(resulting_sheet[sheet_name].columns) == list(graph_capturing_sheet[sheet_name].columns)
from cognite.neat.legacy.graph import extractors as graph_extractor
from cognite.neat.legacy.graph.extractors._graph_capturing_sheet import rules2graph_capturing_sheet
from cognite.neat.legacy.rules.importers import ExcelImporter
from tests import config


def test_graph_capturing_sheet(tmp_path, simple_rules):
extractor = graph_extractor.GraphCapturingSheet(
simple_rules, config.GRAPH_CAPTURING_SHEET, store_graph_capturing_sheet=True
)
_ = extractor.extract()
graph_capturing_sheet = extractor.sheet
tmp_sheet = tmp_path / "temp_graph_capturing.xlsx"

rules2graph_capturing_sheet(simple_rules, tmp_sheet, add_drop_down_list=True, auto_identifier_type="uuid")
resulting_sheet = ExcelImporter(tmp_sheet).to_tables()
assert resulting_sheet.keys() == graph_capturing_sheet.keys()
for sheet_name in resulting_sheet.keys():
assert list(resulting_sheet[sheet_name].columns) == list(graph_capturing_sheet[sheet_name].columns)
Loading

0 comments on commit dddd414

Please sign in to comment.