diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a71feeb010..52dd9092f45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,6 +86,9 @@ jobs: uv pip install --editable '.[${{ matrix.config.extras }}]' --resolution=${{ matrix.config.resolution }} + # TODO: test monty fix for reverse readline + uv pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending + - name: Install optional Ubuntu dependencies if: matrix.config.os == 'ubuntu-latest' run: | diff --git a/dev_scripts/potcar_scrambler.py b/dev_scripts/potcar_scrambler.py index f7115f1996a..a9f7d15a5d6 100644 --- a/dev_scripts/potcar_scrambler.py +++ b/dev_scripts/potcar_scrambler.py @@ -7,8 +7,8 @@ from typing import TYPE_CHECKING import numpy as np +from monty.io import zopen from monty.os.path import zpath -from monty.serialization import zopen from pymatgen.core import SETTINGS from pymatgen.io.vasp import Potcar, PotcarSingle diff --git a/src/pymatgen/io/adf.py b/src/pymatgen/io/adf.py index f5fbf52d9a2..1510ae0b135 100644 --- a/src/pymatgen/io/adf.py +++ b/src/pymatgen/io/adf.py @@ -6,10 +6,9 @@ import re from typing import TYPE_CHECKING -from monty.io import reverse_readline +from monty.io import reverse_readfile from monty.itertools import chunks from monty.json import MSONable -from monty.serialization import zopen from pymatgen.core.structure import Molecule @@ -645,16 +644,15 @@ def _parse_logfile(self, logfile): # The last non-empty line of the logfile must match the end pattern. # Otherwise the job has some internal failure. The TAPE13 part of the # ADF manual has a detailed explanation. - with zopen(logfile, mode="rt") as file: - for line in reverse_readline(file): - if line == "": - continue - if end_patt.search(line) is None: - self.is_internal_crash = True - self.error = "Internal crash. TAPE13 is generated!" - self.is_failed = True - return - break + for line in reverse_readfile(logfile): + if line.strip() == "": + continue + if end_patt.search(line) is None: + self.is_internal_crash = True + self.error = "Internal crash. TAPE13 is generated!" + self.is_failed = True + return + break with open(logfile) as file: for line in file: diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 1c840dcfa2b..ea732f06926 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -4,7 +4,8 @@ import numpy as np import pytest -from monty.serialization import MontyDecoder, loadfn +from monty.json import MontyDecoder +from monty.serialization import loadfn from numpy.testing import assert_allclose from pytest import approx diff --git a/tests/io/test_core.py b/tests/io/test_core.py index bd4ad9ea7fa..5500b8c8a83 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING import pytest -from monty.serialization import MontyDecoder +from monty.json import MontyDecoder from pymatgen.core.structure import Structure from pymatgen.io.cif import CifParser, CifWriter diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index 46eb0fa60e7..a0d9eb50e41 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -12,6 +12,8 @@ import numpy as np import pytest from monty.io import zopen +from monty.shutil import decompress_file +from monty.tempfile import ScratchDir from numpy.testing import assert_allclose from pytest import approx @@ -832,9 +834,20 @@ def test_parse_potcar_cwd_relative(self): assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats -class TestOutcar(PymatgenTest): - def test_init(self): - outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz") +class TestOutcar: + @pytest.mark.parametrize("compressed", [True, False]) + def test_init(self, compressed: bool): + """Test from both compressed and uncompressed versions, + as there was a bug in monty causing different behaviours. + """ + with ScratchDir("."): + if compressed: + copyfile(f"{VASP_OUT_DIR}/OUTCAR.gz", "./OUTCAR.gz") + decompress_file("./OUTCAR.gz") + outcar = Outcar("./OUTCAR") + else: + 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},