Skip to content

Commit

Permalink
chore(test): add pytest entrypoint (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Feb 23, 2024
1 parent 4ae8469 commit e31da78
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/unittests/cli/test_cli_with_mock.py
Expand Up @@ -269,3 +269,7 @@ def test_rosetta(upload_rosetta: Mock) -> None:
args = "rosetta".split()
entry_point.run(args)
upload_rosetta.assert_called_once_with()


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/commands/excel2json/test_project.py
@@ -1,6 +1,8 @@
import json
import unittest

import pytest

from dsp_tools.commands.excel2json.project import _create_project_json, _validate_folder_structure_get_filenames

# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest)
Expand All @@ -14,3 +16,7 @@ def test_excel_to_json_project(self) -> None:
with open("testdata/excel2json/excel2json-expected-output.json", encoding="utf-8") as f:
output_expected = json.load(f)
self.assertDictEqual(project, output_expected)


if __name__ == "__main__":
pytest.main([__file__])
5 changes: 5 additions & 0 deletions test/unittests/commands/excel2xml/test_excel2xml_cli.py
@@ -1,6 +1,7 @@
import unittest
from pathlib import Path

import pytest
import regex

from dsp_tools.commands.excel2xml import excel2xml_cli
Expand Down Expand Up @@ -85,3 +86,7 @@ def test_excel2xml_cli(self) -> None:
for file, _regex in error_cases:
with self.assertRaisesRegex(BaseError, _regex, msg=f"Failed with file '{file}'"):
excel2xml_cli.excel2xml(file, "1234", "excel2xml-invalid")


if __name__ == "__main__":
pytest.main([__file__])
@@ -1,3 +1,4 @@
import pytest
from lxml import etree

from dsp_tools.commands.ingest_xmlupload.apply_ingest_id import replace_filepath_with_sipi_id
Expand Down Expand Up @@ -57,3 +58,7 @@ def test_missing_paths(self) -> None:
assert res_bitstream.text == "images/Fluffy.jpg"
assert res_bitstream.attrib["permissions"] == "prop-default"
assert res_bitstream.tag == "bitstream"


if __name__ == "__main__":
pytest.main([__file__])
@@ -1,6 +1,7 @@
from pathlib import Path

import pandas as pd
import pytest
from pandas.testing import assert_frame_equal

from dsp_tools.commands.ingest_xmlupload.user_information import IngestInformation
Expand Down Expand Up @@ -102,3 +103,7 @@ def test_no_id_to_df() -> None:

def test_no_id_to_df_not_enough() -> None:
assert not IngestInformation([], [("ID_no_up0", "fileno_up0.jpg")])._unused_mediafiles_to_df()


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/commands/xmlupload/connection_mock.py
@@ -1,6 +1,8 @@
from dataclasses import dataclass
from typing import Any

import pytest

# ruff: noqa: ARG002 (unused-method-argument)


Expand Down Expand Up @@ -47,3 +49,7 @@ def login(self, email: str, password: str) -> None:

def logout(self) -> None:
raise AssertionError("logout not implemented in mock")


if __name__ == "__main__":
pytest.main([__file__])
Expand Up @@ -293,3 +293,7 @@ def test_get_all_classes_and_properties_from_data() -> None:
assert res_properties.keys() == expected_properties.keys()
for k, v in res_properties.items():
assert unordered(v) == expected_properties[k]


if __name__ == "__main__":
pytest.main([__file__])
4 changes: 4 additions & 0 deletions test/unittests/commands/xmlupload/test_iri_resolver.py
Expand Up @@ -32,3 +32,7 @@ def test_update_previous_value(resolver: IriResolver) -> None:
assert resolver.get("a") == "http://example.com/iri#a"
resolver.update("a", "http://example.com/iri#aaa")
assert resolver.get("a") == "http://example.com/iri#aaa"


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/commands/xmlupload/test_list_client_live.py
Expand Up @@ -2,6 +2,8 @@
from test.unittests.commands.xmlupload.connection_mock import ConnectionMockBase
from typing import Any

import pytest

from dsp_tools.commands.xmlupload.list_client import (
List,
ListClientLive,
Expand Down Expand Up @@ -240,3 +242,7 @@ def test_get_list_iris_from_server() -> None:
result = _get_list_iris_from_server(con, "")
expected = ["http://www.example.org/lists#a", "http://www.example.org/lists#b"]
assert result == expected


if __name__ == "__main__":
pytest.main([__file__])
5 changes: 5 additions & 0 deletions test/unittests/commands/xmlupload/test_ontology_client.py
Expand Up @@ -2,6 +2,7 @@
from test.unittests.commands.xmlupload.connection_mock import ConnectionMockBase
from typing import Any

import pytest
from pytest_unordered import unordered

from dsp_tools.commands.xmlupload.ontology_client import (
Expand Down Expand Up @@ -79,3 +80,7 @@ def test_get_knora_api_from_server() -> None:
onto_client = OntologyClientLive(con, "", "")
res_graph = onto_client.get_knora_api_ontology_from_server()
assert unordered(res_graph) == [{"resource_class": ["Information"]}, {"property": ["Information"]}]


if __name__ == "__main__":
pytest.main([__file__])
@@ -1,4 +1,5 @@
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal

from dsp_tools.commands.xmlupload.models.ontology_problem_models import InvalidOntologyElementsInData
Expand Down Expand Up @@ -86,3 +87,7 @@ def test_get_problems_as_df() -> None:
)
res_df = onto._get_problems_as_df()
assert_frame_equal(res_df, expected_df)


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/commands/xmlupload/test_project_client_live.py
Expand Up @@ -2,6 +2,8 @@
from test.unittests.commands.xmlupload.connection_mock import ConnectionMockBase
from typing import Any

import pytest

from dsp_tools.commands.xmlupload.project_client import ProjectClientLive


Expand Down Expand Up @@ -45,3 +47,7 @@ def test_get_ontology_name_dict(self) -> None:
"a.2": "http://www.example.org/ontologies/a.2/v2",
}
assert ontology_name_dict == expected


if __name__ == "__main__":
pytest.main([__file__])
@@ -1,3 +1,4 @@
import pytest
from lxml import etree

from dsp_tools.commands.xmlupload.read_validate_xml_file import (
Expand Down Expand Up @@ -96,3 +97,7 @@ def test_check_if_salsah_targets_exist_invalid() -> None:
"Resource 'resource2', property 'text2' has an invalid link target 'IRI:resource4:IRI'",
]
assert errors_returned == errors_expected


if __name__ == "__main__":
pytest.main([__file__])
Expand Up @@ -390,3 +390,7 @@ def test_to_boolean() -> None:
_to_boolean("foo")
with pytest.raises(BaseError):
_to_boolean(2)


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/commands/xmlupload/test_upload_config.py
@@ -1,3 +1,5 @@
import pytest

from dsp_tools.commands.xmlupload.upload_config import UploadConfig, _transform_server_url_to_foldername


Expand Down Expand Up @@ -54,3 +56,7 @@ def test_save_location() -> None:
except OSError:
# there was already stuff in the folder before this test: do nothing
pass


if __name__ == "__main__":
pytest.main([__file__])
4 changes: 4 additions & 0 deletions test/unittests/utils/test_date_util.py
Expand Up @@ -266,3 +266,7 @@ def test_do_not_allow_different_date_formats(self) -> None:
date_string = "01.01.2020"
with pytest.raises(BaseError):
_parse_single_date(date_string, Era.CE)


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/utils/test_iri_util.py
@@ -1,3 +1,5 @@
import pytest

from dsp_tools.utils.iri_util import is_resource_iri


Expand All @@ -12,3 +14,7 @@ def test_is_not_resource_iri() -> None:
assert not is_resource_iri("https://knora.org/0000/PKzNC8MFQT6NAwR3OaQEKw")
assert not is_resource_iri("https://rdfh.ch/0000/PKzNC8MFQT6NAwR3OaQ")
assert not is_resource_iri("www.rdfh.ch/0000/PKzNC8MFQT6NAwR3OaQEKw")


if __name__ == "__main__":
pytest.main([__file__])
6 changes: 6 additions & 0 deletions test/unittests/utils/test_json_ld_util.py
@@ -1,3 +1,5 @@
import pytest

from dsp_tools.utils.json_ld_util import get_default_json_ld_context, get_json_ld_context_for_project


Expand Down Expand Up @@ -46,3 +48,7 @@ def test_get_json_ld_context_for_project_with_multiple_ontologies() -> None:
"testonto2": "http://www.knora.org/ontology/testonto2#",
}
assert context == expected


if __name__ == "__main__":
pytest.main([__file__])
4 changes: 4 additions & 0 deletions test/unittests/utils/test_xml_validation_low_level.py
Expand Up @@ -371,3 +371,7 @@ def test_check_if_only_one_encoding_is_used_in_xml_problem() -> None:
assert res.resource_id == "resC"
assert res.property_name == ":hasSimpleText"
assert res.encoding == {"xml", "utf8"}


if __name__ == "__main__":
pytest.main([__file__])

0 comments on commit e31da78

Please sign in to comment.