Skip to content

Commit

Permalink
Added pytests for Registry and MepoComponent classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed Sep 30, 2024
1 parent b75c5a6 commit cb985f8
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mepo/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
71 changes: 71 additions & 0 deletions tests/test_component.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]: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": "[email protected]: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()
19 changes: 19 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit cb985f8

Please sign in to comment.