Skip to content
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

Test monty fix for reverse_readline #4068

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Sep 15, 2024

Summary

  • Test monty fix for reverse readline, to close Outcar class returns empty magnetization attribute when parsing OUTCAR file on Windows operating system #4033
  • Replace reverse_readline with faster reverse_readfile
  • Fix incorrect monty imports
  • Enhance unit test for reported Outcar parser (need to test unzipped format):
    def test_init(self):
    outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz")
    expected_mag = (
    {"d": 0.0, "p": 0.003, "s": 0.002, "tot": 0.005},
    {"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
    {"d": 0.798, "p": 0.008, "s": 0.007, "tot": 0.813},
    {"d": 0.0, "p": -0.117, "s": 0.005, "tot": -0.112},
    {"d": 0.0, "p": -0.165, "s": 0.004, "tot": -0.162},
    {"d": 0.0, "p": -0.117, "s": 0.005, "tot": -0.112},
    {"d": 0.0, "p": -0.165, "s": 0.004, "tot": -0.162},
    )
    expected_chg = (
    {"p": 0.154, "s": 0.078, "d": 0.0, "tot": 0.232},
    {"p": 0.707, "s": 0.463, "d": 8.316, "tot": 9.486},
    {"p": 0.707, "s": 0.463, "d": 8.316, "tot": 9.486},
    {"p": 3.388, "s": 1.576, "d": 0.0, "tot": 4.964},
    {"p": 3.365, "s": 1.582, "d": 0.0, "tot": 4.947},
    {"p": 3.388, "s": 1.576, "d": 0.0, "tot": 4.964},
    {"p": 3.365, "s": 1.582, "d": 0.0, "tot": 4.947},
    )
    assert outcar.magnetization == approx(expected_mag, abs=1e-5), "Wrong magnetization read from Outcar"

@DanielYang59 DanielYang59 changed the title Test monty fix for reverse readline Test monty fix for reverse_readline Oct 10, 2024
@@ -831,9 +833,20 @@ def test_parse_potcar_cwd_relative(self):
assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats


class TestOutcar(PymatgenTest):
Copy link
Contributor Author

@DanielYang59 DanielYang59 Nov 8, 2024

Choose a reason for hiding this comment

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

I have to avoid inheriting from PymatgenTest as TestCase (and its subclasses) currently don't support parametrize, I believe this wouldn't affect this test as no PymatgenTest/TestCase specific method is used here.

A quick recreate:

from unittest import TestCase

import pytest


class TestDemo(TestCase):  # `class TestDemo` works just fine
    @pytest.mark.parametrize("string", ["hello", "world"])
    def test_hello(self, string):
        print(string)
        pytest.fail("should fail, test")

Would give:

====================================================== test session starts =======================================================
platform darwin -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
rootdir: /Users/yang/developer/test
plugins: anyio-4.6.2.post1
collected 1 item                                                                                                                 

test_pytest.py F                                                                                                           [100%]

============================================================ FAILURES ============================================================
______________________________________________________ TestDemo.test_hello _______________________________________________________

self = <unittest.case._Outcome object at 0x103480950>, test_case = <test_pytest.TestDemo testMethod=test_hello>, subTest = False

    @contextlib.contextmanager
    def testPartExecutor(self, test_case, subTest=False):
        old_success = self.success
        self.success = True
        try:
>           yield

/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py:58: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py:634: in run
    self._callTestMethod(testMethod)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <test_pytest.TestDemo testMethod=test_hello>
method = <bound method TestDemo.test_hello of <test_pytest.TestDemo testMethod=test_hello>>

    def _callTestMethod(self, method):
>       if method() is not None:
E       TypeError: TestDemo.test_hello() missing 1 required positional argument: 'string'

/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py:589: TypeError
==================================================== short test summary info =====================================================
FAILED test_pytest.py::TestDemo::test_hello - TypeError: TestDemo.test_hello() missing 1 required positional argument: 'string'
======================================================= 1 failed in 0.04s ========================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Outcar class returns empty magnetization attribute when parsing OUTCAR file on Windows operating system
2 participants