From cb985f827c85367bdc7ae4b8cf90831c265fd8c4 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Mon, 30 Sep 2024 17:14:47 -0400 Subject: [PATCH] Added pytests for Registry and MepoComponent classes --- src/mepo/component.py | 13 ++++++++ tests/test_component.py | 71 +++++++++++++++++++++++++++++++++++++++++ tests/test_registry.py | 19 +++++++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/test_component.py create mode 100644 tests/test_registry.py diff --git a/src/mepo/component.py b/src/mepo/component.py index 749acef0..d09c63b7 100644 --- a/src/mepo/component.py +++ b/src/mepo/component.py @@ -55,6 +55,19 @@ def __repr__(self): f" ignore_submodules: {_ignore_submodules}" ) + def __eq__(self, other): + return ( + self.name == other.name + and self.local == other.local + and self.remote == other.remote + and self.version == other.version + and self.sparse == other.sparse + and self.develop == other.develop + and self.recurse_submodules == other.recurse_submodules + and self.fixture == other.fixture + and self.ignore_submodules == other.recurse_submodules + ) + def __set_original_version(self, comp_details): if self.fixture: cmd_if_branch = "git symbolic-ref HEAD" diff --git a/tests/test_component.py b/tests/test_component.py new file mode 100644 index 00000000..c5839f6a --- /dev/null +++ b/tests/test_component.py @@ -0,0 +1,71 @@ +import os + +from mepo.component import stylize_local_path +from mepo.component import MepoComponent +from mepo.registry import Registry +from mepo.utilities.version import MepoVersion + +from _pytest.assertion import truncate + +truncate.DEFAULT_MAX_LINES = 9999 +truncate.DEFAULT_MAX_CHARS = 9999 + +TEST_DIR = os.path.dirname(os.path.realpath(__file__)) + + +def get_registry(): + registry = os.path.join(TEST_DIR, "input", "components.yaml") + return Registry(registry).read_file() + + +def get_fvdycore_component(): + comp = MepoComponent() + comp.name = "fvdycore" + comp.local = "./src/Components/@FVdycoreCubed_GridComp/@fvdycore" + comp.remote = "git@github.com:GEOS-ESM/GFDL_atmos_cubed_sphere.git" + comp.version = MepoVersion(name="geos/v1.3.0", type="t", detached=True) + comp.sparse = None + comp.develop = "geos/develop" + comp.recurse_submodules = None + comp.fixture = False + comp.ignore_submodules = None + return comp + + +def get_fvdycore_serialized(): + return { + "name": "fvdycore", + "local": "./src/Components/@FVdycoreCubed_GridComp/@fvdycore", + "remote": "git@github.com:GEOS-ESM/GFDL_atmos_cubed_sphere.git", + "version": ["geos/v1.3.0", "t", True], + "sparse": None, + "develop": "geos/develop", + "recurse_submodules": None, + "fixture": False, + "ignore_submodules": None, + } + + +def test_stylize_local_path(): + local_path = "./src/Shared/@GMAO_Shared/@GEOS_Util" + output = stylize_local_path(local_path, None) + assert output == local_path + output = stylize_local_path(local_path, "prefix") + assert output == local_path + output = stylize_local_path(local_path, "naked") + assert output == "./src/Shared/@GMAO_Shared/GEOS_Util" + output = stylize_local_path(local_path, "postfix") + assert output == "./src/Shared/@GMAO_Shared/GEOS_Util@" + + +def test_MepoComponent(): + registry = get_registry() + complist = list() + for name, comp in registry.items(): + if name == "fvdycore": + fvdycore = MepoComponent().registry_to_component(name, comp, None) + # comp = MepoComponent().registry_to_component(name, comp, None) + # assert comp == get_fvdycore_component() + # complist.append(comp) + assert fvdycore == get_fvdycore_component() + assert fvdycore.serialize() == get_fvdycore_serialized() diff --git a/tests/test_registry.py b/tests/test_registry.py new file mode 100644 index 00000000..f7c47639 --- /dev/null +++ b/tests/test_registry.py @@ -0,0 +1,19 @@ +import os + +from mepo.registry import Registry + +TEST_DIR = os.path.dirname(os.path.realpath(__file__)) + + +def get_ecbuild_details(): + return { + "local": "./@cmake/@ecbuild", + "remote": "../ecbuild.git", + "tag": "geos/v1.2.0", + } + + +def test_registry(): + registry = os.path.join(TEST_DIR, "input", "components.yaml") + a = Registry(registry).read_file() + assert a["ecbuild"] == get_ecbuild_details()