Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions src/lomap/tests/test_lomapatommapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

try:
import gufe
from gufe.tests.test_tokenization import GufeTokenizableTestsMixin

HAS_GUFE = True
except ImportError:
# Fake assign to object to avoid issues
GufeTokenizableTestsMixin = object
HAS_GUFE = False


Expand All @@ -18,43 +21,46 @@ def test_lomap_atommaper_no_gufe_error():


@pytest.mark.skipif(not HAS_GUFE, reason="requires gufe installed")
def test_to_dict_roundtrip():
ref_vals = {
"time": 19,
"threed": False,
"max3d": 999.0,
"element_change": False,
"seed": "CC",
"shift": False,
}

m = LomapAtomMapper(**ref_vals)

d = m.to_dict()

m2 = LomapAtomMapper.from_dict(d)

assert m2
assert m2.time == ref_vals["time"]
assert m2.threed == ref_vals["threed"]
assert m2.max3d == ref_vals["max3d"]
assert m2.element_change == ref_vals["element_change"]
assert m2.seed == ref_vals["seed"]
assert m2.shift == ref_vals["shift"]


@pytest.mark.skipif(not HAS_GUFE, reason="requires gufe installed")
def test_repr():
m = LomapAtomMapper()

assert repr(m) == (
class TestLomapAtomMapper(GufeTokenizableTestsMixin):
cls = LomapAtomMapper
key = None
repr = (
"<LomapAtomMapper (time=20, threed=True, max3d=1.0, "
"element_change=True, seed='None', shift=False)>"
)

m = LomapAtomMapper(time=15, seed="c1ccccc1")

assert repr(m) == (
"<LomapAtomMapper (time=15, threed=True, max3d=1.0, "
"element_change=True, seed='c1ccccc1', shift=False)>"
)
@pytest.fixture
def instance(self):
return LomapAtomMapper()

def test_to_dict_roundtrip_different(self):
ref_vals = {
"time": 19,
"threed": False,
"max3d": 999.0,
"element_change": False,
"seed": "CC",
"shift": False,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we change the default to "False", should this now be testing "True"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it's better if it's not the defaults - the roundtrip on the default settings is already taken care of in the underlying mixin. Here I'm just keeping the "old" test, hence the naming containing "different".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm probably just missing something, but I was thinking that if we want to test the non defaults here, then it should be "True"?

}

m = LomapAtomMapper(**ref_vals)

d = m.to_dict()

m2 = LomapAtomMapper.from_dict(d)

assert m2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an isinstance check be better than just the assert?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

assert m2.time == ref_vals["time"]
assert m2.threed == ref_vals["threed"]
assert m2.max3d == ref_vals["max3d"]
assert m2.element_change == ref_vals["element_change"]
assert m2.seed == ref_vals["seed"]
assert m2.shift == ref_vals["shift"]

def test_repr_different(self):
m = LomapAtomMapper(time=15, seed="c1ccccc1")

assert repr(m) == (
"<LomapAtomMapper (time=15, threed=True, max3d=1.0, "
"element_change=True, seed='c1ccccc1', shift=False)>"
)
Loading