-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix assert_str_content_equal
, add tests for testing utils
#4205
Fix assert_str_content_equal
, add tests for testing utils
#4205
Conversation
PymatgenTest
and tests to pytest
assert_str_content_equal
c7255c3
to
8a800d4
Compare
8fd92e7
to
4f42918
Compare
from pymatgen.core import Structure | ||
from pymatgen.util.typing import PathLike | ||
|
||
_MODULE_DIR: Path = Path(__file__).absolute().parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
[NEED CONFIRM] make MODULE_DIR
private, as the util.testing
directory contains nothing else other than__init__.py
, I guess it's used to define STRUCTURES_DIR
only:
pymatgen/src/pymatgen/util/testing/__init__.py
Lines 27 to 28 in 31f1e1f
MODULE_DIR = Path(__file__).absolute().parent | |
STRUCTURES_DIR = MODULE_DIR / ".." / "structures" |
assert_str_content_equal
assert_str_content_equal
, add tests for testing utils
json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) | ||
round_trip = json.loads(json_str, cls=MontyDecoder) | ||
if not issubclass(type(round_trip), type(obj)): | ||
raise TypeError(f"The reconstructed {round_trip.__class__.__name__} object is not a subclass of {obj_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More readable error message
Before: <class 'util.test_testing.TestAssertMSONable.test_not_round_trip.<locals>.NotAKpoints'> != <class 'pymatgen.io.vasp.inputs.Kpoints'>
Now: The reconstructed NotAKpoints object is not a subclass of Kpoints
6126945
to
d409b13
Compare
d409b13
to
f6beee6
Compare
Summary
assert_str_content_equal
not raisingAssertionError
util.testing
as it's intended for public usage (and quite some external code usePymatgenTest
)PymatgenTest
testing/__init__.py
totesting.py
Warning
[NEED CONFIRM] Simplify single-file module
testing/__init__.py
totesting.py
(Is this intended for some purpose?), I don't think this would be breaking (though the definition ofMODULE_DIR
would change fromutil/testing
toutil
, but no code import this AFAIK as theutil/testing
has nothing else, I believe it's intended forSTRUCTURES_DIR
and I have updated this)Fix
assert_str_content_equal
not raisingAssertionError
Current implementation would not raise
AssertionError
when two strings are not equal (it only returns a bool):pymatgen/src/pymatgen/util/testing/__init__.py
Lines 66 to 69 in 31f1e1f
And current usage of it take the pattern of
self.assert_str_content_equal
withoutassert
.Several issues found:
test_str
andtest_mul
forTestStructureGraph
ofanalysis.graphs
are failing #4206test_symmetry_ops
forTestMagneticSpaceGroup
ofsymmetry.maggroups
is failing #4207