-
Notifications
You must be signed in to change notification settings - Fork 876
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
Merged
shyuep
merged 19 commits into
materialsproject:master
from
DanielYang59:migrate-to-pytest
Dec 11, 2024
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
962a938
clean up comment and docstring
DanielYang59 10da590
change reference to stable doc instead of latest
DanielYang59 ce750fa
fix assert_str_content_equal and add test
DanielYang59 22cc72e
clean up assert_str_content_equal usage
DanielYang59 f472e7f
make error msg more detailed
DanielYang59 78a4ede
don't force positional as err msg contains expected and actual tag
DanielYang59 1b21599
fix quote
DanielYang59 6a32f6d
make assert_msonable staticmethod
DanielYang59 ac56aad
sort methods alphabetically
DanielYang59 f611c16
add list of methods
DanielYang59 24ee9a5
comment out test_symmetry_ops
DanielYang59 8a800d4
skip failing tests
DanielYang59 4f42918
only comment out assert to reduce change
DanielYang59 11b061d
simplify single file module
DanielYang59 e8a52a8
make module dir private
DanielYang59 0af7f38
remove test for module dir
DanielYang59 c32852e
add test for non existent structure
DanielYang59 47b26fe
add more tests
DanielYang59 f6beee6
more human readable err msg and test
DanielYang59 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
from pymatgen.core import Structure | ||
from pymatgen.util.testing import ( | ||
FAKE_POTCAR_DIR, | ||
MODULE_DIR, | ||
STRUCTURES_DIR, | ||
TEST_FILES_DIR, | ||
VASP_IN_DIR, | ||
VASP_OUT_DIR, | ||
PymatgenTest, | ||
) | ||
|
||
|
||
def test_paths(): | ||
"""Test paths provided in testing util.""" | ||
assert MODULE_DIR.is_dir() | ||
|
||
assert STRUCTURES_DIR.is_dir() | ||
assert [f for f in os.listdir(STRUCTURES_DIR) if f.endswith(".json")] | ||
|
||
assert TEST_FILES_DIR.is_dir() | ||
assert os.path.isdir(VASP_IN_DIR) | ||
assert os.path.isdir(VASP_OUT_DIR) | ||
|
||
assert os.path.isdir(FAKE_POTCAR_DIR) | ||
assert any(f.startswith("POTCAR") for _root, _dir, files in os.walk(FAKE_POTCAR_DIR) for f in files) | ||
|
||
|
||
class TestPymatgenTest: | ||
def test_tmp_dir(self): | ||
pass | ||
|
||
def test_assert_msonable(self): | ||
pass | ||
|
||
def test_assert_str_content_equal(self): | ||
# Cases where strings are equal | ||
PymatgenTest.assert_str_content_equal("hello world", "hello world") | ||
PymatgenTest.assert_str_content_equal(" hello world ", "hello world") | ||
PymatgenTest.assert_str_content_equal("\nhello\tworld\n", "hello world") | ||
|
||
# Test whitespace handling | ||
PymatgenTest.assert_str_content_equal("", "") | ||
PymatgenTest.assert_str_content_equal(" ", "") | ||
PymatgenTest.assert_str_content_equal("hello\n", "hello") | ||
PymatgenTest.assert_str_content_equal("hello\r\n", "hello") | ||
PymatgenTest.assert_str_content_equal("hello\t", "hello") | ||
|
||
# Cases where strings are not equal | ||
with pytest.raises(AssertionError, match="Strings are not equal"): | ||
PymatgenTest.assert_str_content_equal("hello world", "hello_world") | ||
|
||
with pytest.raises(AssertionError, match="Strings are not equal"): | ||
PymatgenTest.assert_str_content_equal("hello", "hello world") | ||
|
||
def test_get_structure(self): | ||
structure = PymatgenTest.get_structure("LiFePO4") | ||
assert isinstance(structure, Structure) | ||
|
||
# TODO: need to check non-existent structure exception | ||
|
||
def test_serialize_with_pickle(self): | ||
pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theutil.testing
directory contains nothing else other than__init__.py
, I guess it's used to defineSTRUCTURES_DIR
only:pymatgen/src/pymatgen/util/testing/__init__.py
Lines 27 to 28 in 31f1e1f