Skip to content

Commit

Permalink
Move tests to their own folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Aug 2, 2023
1 parent 7c1d780 commit 77f89df
Show file tree
Hide file tree
Showing 266 changed files with 59 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
# pytest --store-durations --durations-path test_files/.pytest-split-durations
# and commit the results (requires pip install pytest-split)
run: |
pytest --cov=pymatgen --splits 10 --group ${{ matrix.split }} --durations-path test_files/.pytest-split-durations
pytest --cov=pymatgen --splits 10 --group ${{ matrix.split }} --durations-path test_files/.pytest-split-durations tests
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions pymatgen/analysis/chemenv/utils/tests/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions pymatgen/io/exciting/tests/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions pymatgen/io/qchem/tests/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions pymatgen/io/xtb/tests/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ isort.split-on-trailing-comma = false

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"*/tests/*" = ["D"]
"tests/**" = ["D"]
"tasks.py" = ["D"]
"pymatgen/analysis/*" = ["D"]
"pymatgen/vis/*" = ["D"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Tests"""
"""Tests."""

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package."""
1 change: 1 addition & 0 deletions tests/analysis/chemenv/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package."""
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
TODO: Modify module doc.
"""
"""TODO: Modify module doc."""


from __future__ import annotations
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Unit tests for TEM calculator.
"""
"""Unit tests for TEM calculator."""

from __future__ import annotations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class XRDCalculatorTest(PymatgenTest):
def test_type_wavelength(self):
"""Test TypeError is raised if wavelength is unaccepted type"""
"""Test TypeError is raised if wavelength is unaccepted type."""
wavelength = [1.78, 2.78] # just a list
with pytest.raises(TypeError) as exc:
XRDCalculator(wavelength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ def test_energy_density(self):


class DiffFitTest(PymatgenTest):
"""
Tests various functions related to diff fitting
"""
"""Tests various functions related to diff fitting."""

def setUp(self):
with open(os.path.join(PymatgenTest.TEST_FILES_DIR, "test_toec_data.json")) as f:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SubstitutionProbabilityTest(unittest.TestCase):
def test_full_lambda_table(self):
"""
This test tests specific values in the data folder. If the
json is updated, these tests will have to be as well
json is updated, these tests will have to be as well.
"""
sp = SubstitutionProbability(alpha=-5.0)
sp1 = Species("Fe", 4)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_init(self):
assert len(e_min.best_m_list) == 6, "Returned wrong number of permutations"

def test_site(self):
"""Test that uses an uncharged structure"""
"""Test that uses an uncharged structure."""
filepath = os.path.join(PymatgenTest.TEST_FILES_DIR, "POSCAR")
p = Poscar.from_file(filepath, check_for_POTCAR=False)
original_s = p.structure
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@

class ValenceIonicRadiusEvaluatorTest(PymatgenTest):
def setUp(self):
"""
Setup MgO rocksalt structure for testing Vacancy
"""
"""Setup MgO rocksalt structure for testing Vacancy."""
mgo_latt = [[4.212, 0, 0], [0, 4.212, 0], [0, 0, 4.212]]
mgo_specie = ["Mg"] * 4 + ["O"] * 4
mgo_frac_cord = [
Expand Down Expand Up @@ -204,7 +202,7 @@ def test_all_at_once(self):
self.assert_all_close(all_weights, by_one_weights)

def test_Cs2O(self):
"""A problematic structure in the Materials Project"""
"""A problematic structure in the Materials Project."""
strc = Structure(
[
[4.358219, 0.192833, 6.406960],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@


class PathFinderTest(unittest.TestCase):
"""
Uses Li migration in LiFePO4
"""
"""Uses Li migration in LiFePO4."""

def test_image_num(self):
os.path.dirname(os.path.abspath(__file__))
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Test for the piezo tensor class
"""
"""Test for the piezo tensor class."""
from __future__ import annotations

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Test for the piezo tensor class
"""
"""Test for the piezo tensor class."""

from __future__ import annotations

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_fit(self):
1) Ensure match
2) Ensure match after translation and rotations
3) Ensure no-match after large site translation
4) Ensure match after site shuffling
4) Ensure match after site shuffling.
"""
sm = StructureMatcher()

Expand Down Expand Up @@ -299,14 +299,14 @@ def test_fit(self):
assert sm_coarse.fit(s2, s1, symmetric=True) is False

def test_oxi(self):
"""Test oxidation state removal matching"""
"""Test oxidation state removal matching."""
sm = StructureMatcher()
assert not sm.fit(self.oxi_structs[0], self.oxi_structs[1])
sm = StructureMatcher(comparator=ElementComparator())
assert sm.fit(self.oxi_structs[0], self.oxi_structs[1])

def test_primitive(self):
"""Test primitive cell reduction"""
"""Test primitive cell reduction."""
sm = StructureMatcher(primitive_cell=True)
self.struct_list[1].make_supercell([[2, 0, 0], [0, 3, 0], [0, 0, 1]])
assert sm.fit(self.struct_list[0], self.struct_list[1])
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_mix(self):
assert len(g) == 1

def test_left_handed_lattice(self):
"""Ensure Left handed lattices are accepted"""
"""Ensure Left handed lattices are accepted."""
sm = StructureMatcher()
struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Li3GaPCO7.json"))
assert sm.fit(struct, struct)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_get_plotly(self):
def symm_check(self, ucell, wulff_vertices):
"""
# Checks if the point group of the Wulff shape matches
# the point group of its conventional unit cell
# the point group of its conventional unit cell.
Args:
ucell (str): Unit cell that the Wulff shape is based on.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@


def abiref_file(filename):
"""Return absolute path to filename in ~pymatgen/test_files/abinit"""
"""Return absolute path to filename in ~pymatgen/test_files/abinit."""
return os.path.join(_test_dir, filename)


def abiref_files(*filenames):
"""Return list of absolute paths to filenames in ~pymatgen/test_files/abinit"""
"""Return list of absolute paths to filenames in ~pymatgen/test_files/abinit."""
return [os.path.join(_test_dir, f) for f in filenames]


Expand Down Expand Up @@ -125,7 +125,7 @@ def test_api(self):
self.serialize_with_pickle(inp, test_eq=False)

def test_input_errors(self):
"""Testing typical BasicAbinitInput Error"""
"""Testing typical BasicAbinitInput Error."""
si_structure = Structure.from_file(abiref_file("si.cif"))

# Ambiguous list of pseudos.
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_api(self):

class ShiftModeTest(PymatgenTest):
def test_shiftmode(self):
"""Testing shiftmode"""
"""Testing shiftmode."""
gamma = ShiftMode.GammaCentered
assert ShiftMode.from_object("G") == gamma
assert ShiftMode.from_object(gamma) == gamma
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setUp(self):
setattr(self, attr_name, pseudo)

def test_nc_pseudos(self):
"""Test norm-conserving pseudopotentials"""
"""Test norm-conserving pseudopotentials."""
for symbol, pseudos in self.nc_pseudos.items():
for pseudo in pseudos:
assert repr(pseudo)
Expand Down Expand Up @@ -129,9 +129,7 @@ def test_pawxml_pseudos(self):
assert o.paw_radius == approx(1.4146523028)

def test_oncvpsp_pseudo_sr(self):
"""
Test the ONCVPSP Ge pseudo (scalar relativistic version).
"""
"""Test the ONCVPSP Ge pseudo (scalar relativistic version)."""
ger = Pseudo.from_file(ref_file("ge.oncvpsp"))
assert repr(ger)
assert str(ger)
Expand All @@ -153,9 +151,7 @@ def test_oncvpsp_pseudo_sr(self):
self.assert_msonable(ger)

def test_oncvpsp_pseudo_fr(self):
"""
Test the ONCVPSP Pb pseudo (relativistic version with SO).
"""
"""Test the ONCVPSP Pb pseudo (relativistic version with SO)."""
pb = Pseudo.from_file(ref_file("Pb-d-3_r.psp8"))
repr(pb)
str(pb)
Expand All @@ -176,7 +172,7 @@ def test_oncvpsp_pseudo_fr(self):

class PseudoTableTest(PymatgenTest):
def test_methods(self):
"""Test PseudoTable methods"""
"""Test PseudoTable methods."""
table = PseudoTable(ref_files("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi"))
assert str(table)
assert len(table) == 3
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.out = Cp2kOutput(Path.joinpath(self.TEST_FILES_DIR, "cp2k.out"), auto_load=True)

def test_files(self):
"""Can find files successfully"""
"""Can find files successfully."""
self.out.parse_files()
assert len(self.out.filenames["PDOS"]) == 1
assert len(self.out.filenames["PDOS"]) == 1
Expand All @@ -24,7 +24,7 @@ def test_files(self):
assert len(self.out.filenames["g_tensor"]) == 1

def test_run_info(self):
"""Can extract run info from out file"""
"""Can extract run info from out file."""
assert self.out.spin_polarized
assert self.out.completed
assert self.out.num_warnings == [[2]]
Expand All @@ -33,19 +33,19 @@ def test_run_info(self):
assert self.out.run_type.upper() == "ENERGY_FORCE"

def energy_force(self):
"""Can get energy and forces"""
"""Can get energy and forces."""
assert self.out.final_energy == -197.40000341992783
self.assert_all_close(
self.out.data["forces"][0], [[-0.00000001, -0.00000001, -0.00000001], [0.00000002, 0.00000002, 0.00000002]]
)

def test_band(self):
"""Can parse bandstructure files"""
"""Can parse bandstructure files."""
assert self.out.band_structure
assert self.out.band_structure.get_band_gap().get("energy") == 0.27940141999999923

def test_dos(self):
"""Can parse dos files"""
"""Can parse dos files."""
assert self.out.data["pdos"]["Si_1"]["s"]["efermi"] == approx(-6.7370756409404455)
assert self.out.data["tdos"].energies[0] == approx(-6.781065751604123)

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tests/io/exciting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for exciting."""
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_absorbing_atom(self):
def test_single_absorbing_atom(self):
"""
When there is only one absorbing atom in the structure, it should not appear
in the pot_dict to avoid an error
in the pot_dict to avoid an error.
"""
# one Zn+2, 9 triflate, plus water
xyz = os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_radial_shell.xyz")
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_init(self):
def test_single_absorbing_atom(self):
"""
When there is only one absorbing atom in the structure, it should not appear
in the pot_dict to avoid an error
in the pot_dict to avoid an error.
"""
# one Zn+2, 9 triflate, plus water
xyz = os.path.join(PymatgenTest.TEST_FILES_DIR, "feff_radial_shell.xyz")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/io/qchem/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""This package implements modules test the input and output modules for QChem."""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,15 @@
class TestQCOutput(PymatgenTest):
@staticmethod
def generate_single_job_dict():
"""
Used to generate test dictionary for single jobs.
"""
"""Used to generate test dictionary for single jobs."""
single_job_dict = {}
for file in single_job_out_names:
single_job_dict[file] = QCOutput(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", file)).data
dumpfn(single_job_dict, "single_job.json")

@staticmethod
def generate_multi_job_dict():
"""
Used to generate test dictionary for multiple jobs.
"""
"""Used to generate test dictionary for multiple jobs."""
multi_job_dict = {}
for file in multi_job_out_names:
outputs = QCOutput.multiple_outputs_from_file(
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ def test_pcm_write(self):
os.remove("mol.qin")

def test_isosvp_write(self):
"""
Also tests overwrite_inputs with a RHOISO value
"""
"""Also tests overwrite_inputs with a RHOISO value."""
test_molecule = QCInput.from_file(os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule
dict_set = QChemDictSet(
molecule=test_molecule,
Expand Down Expand Up @@ -298,9 +296,7 @@ def test_smd_write(self):
os.remove("mol.qin")

def test_cmirs_write(self):
"""
Also tests overwrite_inputs with a RHOISO value
"""
"""Also tests overwrite_inputs with a RHOISO value."""
test_molecule = QCInput.from_file(os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule
dict_set = QChemDictSet(
molecule=test_molecule,
Expand Down Expand Up @@ -392,9 +388,7 @@ def test_custom_smd_write(self):
os.remove("solvent_data")

def test_solvation_warnings(self):
"""
Tests warnings / errors resulting from nonsensical overwrite_inputs
"""
"""Tests warnings / errors resulting from nonsensical overwrite_inputs."""
test_molecule = QCInput.from_file(os.path.join(test_dir, "new_qchem_files/pcm.qin")).molecule
with pytest.raises(RuntimeError, match="CMIRS is only parameterized"):
QChemDictSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@


class UtilTest(PymatgenTest):
"""
test utils
"""
"""test utils."""

def test_lower_and_check_unique(self):
d = {"sVp": {"RHOISO": 0.0009}, "jobType": "SP"}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 77f89df

Please sign in to comment.