From 545c20d88d026910ba5a5c39667db86fb84e922d Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel) Yang" Date: Fri, 16 Aug 2024 17:34:18 +0800 Subject: [PATCH] Fix failing ruff `PT001` on master (#4003) * bump ruff version in pre-commit * fix PT001 --- .pre-commit-config.yaml | 4 ++-- tests/core/test_xcfunc.py | 5 ++--- tests/entries/test_mixing_scheme.py | 30 ++++++++++++++--------------- tests/io/aims/test_aims_parsers.py | 22 ++++++++++----------- tests/io/qchem/test_outputs.py | 2 +- tests/io/test_openff.py | 2 +- tests/test_cli.py | 2 +- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b562b202756..7596d1850a5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.7 + rev: v0.6.0 hooks: - id: ruff args: [--fix, --unsafe-fixes] @@ -65,6 +65,6 @@ repos: args: [--drop-empty-cells, --keep-output] - repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.375 + rev: v1.1.376 hooks: - id: pyright diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index 1cc64bbebc8..94627874bab 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -53,12 +53,11 @@ def test_pickle_serialize(self): # Test if object can be serialized with Pickle self.serialize_with_pickle(self.ixc_11) - @pytest.mark.skip() + @pytest.mark.skip(reason="TODO:") def test_msonable(self): # Test if object supports MSONable - # TODO self.ixc_11.x.as_dict() - self.assertMSONable(self.ixc_11) + self.assert_msonable(self.ixc_11) def test_from(self): # GGA-PBE from ixc given in abinit-libxc mode diff --git a/tests/entries/test_mixing_scheme.py b/tests/entries/test_mixing_scheme.py index f4e264fce87..457571d5a69 100644 --- a/tests/entries/test_mixing_scheme.py +++ b/tests/entries/test_mixing_scheme.py @@ -156,7 +156,7 @@ def all_entries(self): return self.gga_entries + self.scan_entries -@pytest.fixture() +@pytest.fixture def mixing_scheme_no_compat(): """Get an instance of MaterialsProjectDFTMixingScheme with no additional compatibility schemes (e.g., compat_1=None). Used by most of the tests where @@ -205,7 +205,7 @@ def mixing_scheme_no_compat(): ) -@pytest.fixture() +@pytest.fixture def ms_complete(): """Mixing state where we have R2SCAN for all GGA.""" gga_entries = [ @@ -370,7 +370,7 @@ def ms_complete(): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_scan_only(ms_complete): """Mixing state with only R2SCAN entries.""" gga_entries = [] @@ -391,7 +391,7 @@ def ms_scan_only(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_only(ms_complete): """Mixing state with only GGA entries.""" gga_entries = ms_complete.gga_entries @@ -412,7 +412,7 @@ def ms_gga_only(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_1_scan(ms_complete): """ Mixing state with all GGA entries and one R2SCAN, corresponding to the GGA @@ -434,7 +434,7 @@ def ms_gga_1_scan(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_1_scan_novel(ms_complete): """ Mixing state with all GGA entries and 1 R2SCAN, corresponding to a composition @@ -464,7 +464,7 @@ def ms_gga_1_scan_novel(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_2_scan_same(ms_complete): """ Mixing state with all GGA entries and 2 R2SCAN, corresponding to the GGA @@ -486,7 +486,7 @@ def ms_gga_2_scan_same(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_2_scan_diff_match(ms_complete): """ Mixing state with all GGA entries and 2 R2SCAN entries corresponding to @@ -510,7 +510,7 @@ def ms_gga_2_scan_diff_match(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_gga_2_scan_diff_no_match(ms_complete): """ Mixing state with all GGA entries and 2 R2SCAN, corresponding to the GGA @@ -552,7 +552,7 @@ def ms_gga_2_scan_diff_no_match(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_all_gga_scan_gs(ms_complete): """ Mixing state with all GGA entries and R2SCAN entries corresponding to all GGA @@ -576,7 +576,7 @@ def ms_all_gga_scan_gs(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_all_gga_scan_gs_plus_novel(ms_all_gga_scan_gs): """ Mixing state with all GGA entries and R2SCAN entries corresponding to all GGA @@ -617,7 +617,7 @@ def ms_all_gga_scan_gs_plus_novel(ms_all_gga_scan_gs): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_all_scan_novel(ms_complete): """ Mixing state with all GGA entries and all R2SCAN, with an additional unstable @@ -658,7 +658,7 @@ def ms_all_scan_novel(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_incomplete_gga_all_scan(ms_complete): """Mixing state with an incomplete GGA phase diagram.""" gga_entries = [entry for entry in ms_complete.gga_entries if entry.reduced_formula != "Sn"] @@ -678,7 +678,7 @@ def ms_incomplete_gga_all_scan(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_scan_chemsys_superset(ms_complete): """ Mixing state where we have R2SCAN for all GGA, and there is an additional R2SCAN @@ -709,7 +709,7 @@ def ms_scan_chemsys_superset(ms_complete): return MixingState(gga_entries, scan_entries, mixing_state) -@pytest.fixture() +@pytest.fixture def ms_complete_duplicate_structs(ms_complete): """ Mixing state where we have R2SCAN for all GGA, plus extra entries that duplicate diff --git a/tests/io/aims/test_aims_parsers.py b/tests/io/aims/test_aims_parsers.py index 1d30799122d..88378d9e824 100644 --- a/tests/io/aims/test_aims_parsers.py +++ b/tests/io/aims/test_aims_parsers.py @@ -23,7 +23,7 @@ parser_file_dir = Path(__file__).parent / "parser_checks" -@pytest.fixture() +@pytest.fixture def default_chunk(): lines = ["TEST", "A", "TEST", "| Number of atoms: 200 atoms"] return AimsOutChunk(lines) @@ -50,7 +50,7 @@ def test_search_parse_scalar(default_chunk): assert default_chunk.parse_scalar("n_electrons") is None -@pytest.fixture() +@pytest.fixture def empty_header_chunk(): return AimsOutHeaderChunk([]) @@ -89,7 +89,7 @@ def test_default_header_k_point_weights(empty_header_chunk): assert empty_header_chunk.k_point_weights is None -@pytest.fixture() +@pytest.fixture def initial_lattice(): return np.array( [ @@ -100,7 +100,7 @@ def initial_lattice(): ) -@pytest.fixture() +@pytest.fixture def header_chunk(): with gzip.open(f"{parser_file_dir}/header_chunk.out.gz", mode="rt") as hc_file: lines = hc_file.readlines() @@ -155,7 +155,7 @@ def test_header_n_k_points(header_chunk): assert header_chunk.n_k_points == 8 -@pytest.fixture() +@pytest.fixture def k_points(): return np.array( [ @@ -203,7 +203,7 @@ def test_header_header_summary(header_chunk, k_points): assert val == header_summary[key] -@pytest.fixture() +@pytest.fixture def empty_calc_chunk(header_chunk): return AimsOutCalcChunk([], header_chunk) @@ -288,7 +288,7 @@ def test_default_calc_converged(empty_calc_chunk): assert not empty_calc_chunk.converged -@pytest.fixture() +@pytest.fixture def calc_chunk(header_chunk): with gzip.open(f"{parser_file_dir}/calc_chunk.out.gz", mode="rt") as file: lines = file.readlines() @@ -298,7 +298,7 @@ def calc_chunk(header_chunk): return AimsOutCalcChunk(lines, header_chunk) -@pytest.fixture() +@pytest.fixture def numerical_stress_chunk(header_chunk): with gzip.open(f"{parser_file_dir}/numerical_stress.out.gz", mode="rt") as file: lines = file.readlines() @@ -419,7 +419,7 @@ def test_calc_hirshfeld_dipole(calc_chunk): assert calc_chunk.hirshfeld_dipole is None -@pytest.fixture() +@pytest.fixture def molecular_header_chunk(): with gzip.open(f"{parser_file_dir}/molecular_header_chunk.out.gz", mode="rt") as file: lines = file.readlines() @@ -451,7 +451,7 @@ def test_molecular_header_initial_structure(molecular_header_chunk, molecular_po ) -@pytest.fixture() +@pytest.fixture def molecular_calc_chunk(molecular_header_chunk): with gzip.open(f"{parser_file_dir}/molecular_calc_chunk.out.gz", mode="rt") as file: lines = file.readlines() @@ -461,7 +461,7 @@ def molecular_calc_chunk(molecular_header_chunk): return AimsOutCalcChunk(lines, molecular_header_chunk) -@pytest.fixture() +@pytest.fixture def molecular_positions(): return np.array([[-0.00191785, -0.00243279, 0], [0.97071531, -0.00756333, 0], [-0.25039746, 0.93789612, 0]]) diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index bd900253583..4f1b0ce308f 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -301,7 +301,7 @@ def _test_property(self, key, single_outs, multi_outs): else: assert_allclose(sub_output.data.get(key), multi_job_dict[filename][idx].get(key), atol=1e-6) - @pytest.mark.skip() # self._test_property(key, single_outs, multi_outs) fails with + @pytest.mark.skip # self._test_property(key, single_outs, multi_outs) fails with # ValueError: The truth value of an array with more than one element is ambiguous @pytest.mark.skipif(openbabel is None, reason="OpenBabel not installed.") def test_all(self): diff --git a/tests/io/test_openff.py b/tests/io/test_openff.py index 8d48f686fd9..3c2def7bf4f 100644 --- a/tests/io/test_openff.py +++ b/tests/io/test_openff.py @@ -26,7 +26,7 @@ pybel = pytest.importorskip("openbabel.pybel") -@pytest.fixture() +@pytest.fixture def mol_files(): return { "CCO_xyz": f"{TEST_DIR}/CCO.xyz", diff --git a/tests/test_cli.py b/tests/test_cli.py index e044980ae9d..83d976dbe5d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,7 +14,7 @@ from pytest import MonkeyPatch -@pytest.fixture() +@pytest.fixture def cd_tmp_path(tmp_path: Path, monkeypatch: MonkeyPatch): monkeypatch.chdir(tmp_path) return tmp_path