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

Deprecate PymatgenTest, migrate pymatgen tests to pytest from unittest #4212

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
08aebc1
revert for a separate migration PR
DanielYang59 Dec 1, 2024
21a36f5
Revert "revert for a separate migration PR"
DanielYang59 Dec 1, 2024
8bacdbc
remove hard-coded and failing test
DanielYang59 Dec 1, 2024
344a872
batch remove PymatgenTest inheritance and see what fail
DanielYang59 Dec 3, 2024
ab8bb0e
migrate alchemy and command_line
DanielYang59 Dec 4, 2024
9ed871d
deprecate pymatgen with matscitest
DanielYang59 Dec 4, 2024
2666983
migrate utils
DanielYang59 Dec 4, 2024
21123bd
migrate optimization
DanielYang59 Dec 4, 2024
614f4f7
migrate vis
DanielYang59 Dec 4, 2024
a2ea374
global replacement of setUp and TearDown, setupClass
DanielYang59 Dec 4, 2024
6f2bfe9
revert all changes to before global replace PymatgenTest
DanielYang59 Dec 4, 2024
9d33460
deprecate pymatgen with matscitest
DanielYang59 Dec 4, 2024
be187d0
global replace setUp with setup_method
DanielYang59 Dec 4, 2024
7366ec7
replace tearDown
DanielYang59 Dec 4, 2024
3239fd5
replace setUpClass(cls) with setup_class(cls)
DanielYang59 Dec 4, 2024
4429546
global remove inheritance from TestCase
DanielYang59 Dec 4, 2024
98f7fc7
global replace inheritance from PymatgenTest
DanielYang59 Dec 4, 2024
dfb616c
global replace PymatgenTest import
DanielYang59 Dec 4, 2024
9ae0deb
global replace get_structure
DanielYang59 Dec 4, 2024
42f9fb6
global replace PymatgenTest with MatSciTest
DanielYang59 Dec 4, 2024
96ccce4
fix tests
DanielYang59 Dec 4, 2024
631ef93
fix internal index and add require for pytest style
DanielYang59 Dec 4, 2024
5c89fc0
fix test
DanielYang59 Dec 4, 2024
e4ac465
remove seemingly unused conftest
DanielYang59 Dec 4, 2024
4292f38
add deprecated decorator and enhance docstring
DanielYang59 Dec 5, 2024
027f84b
inherit to reduce code duplicate
DanielYang59 Dec 5, 2024
73328d0
add some test for legacy tester
DanielYang59 Dec 5, 2024
ebd48ce
also check future warning
DanielYang59 Dec 5, 2024
f6bda1e
remove unnecessary chdir
DanielYang59 Dec 5, 2024
58dc537
prep for merge
DanielYang59 Dec 11, 2024
ec33a39
Merge branch 'master' into real-real-real-migrate-pmg-tests-to-pytest
DanielYang59 Dec 12, 2024
def9886
fix bad merge behaviour
DanielYang59 Dec 12, 2024
881e092
Merge remote-tracking branch 'upstream/master' into real-real-real-mi…
DanielYang59 Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tests/command_line/test_enumlib_caller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import unittest
from shutil import which

import numpy as np
Expand All @@ -14,12 +13,11 @@
from pymatgen.transformations.standard_transformations import SubstitutionTransformation
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest

enum_cmd = which("enum.x") or which("multienum.x")
makestr_cmd = which("makestr.x") or which("makeStr.x") or which("makeStr.py")
enumlib_present = enum_cmd and makestr_cmd
ENUM_CMD = which("enum.x") or which("multienum.x")
MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py")


@pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.")
@pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.")
class TestEnumlibAdaptor(PymatgenTest):
def test_init(self):
struct = self.get_structure("LiFePO4")
Expand Down Expand Up @@ -119,7 +117,7 @@ def test_partial_disorder(self):
for struct in structures:
assert struct.formula == "Ca12 Al8 Si4 Ge8 O48"

@unittest.skip("Fails seemingly at random.")
@pytest.mark.skip("Fails seemingly at random.")
def test_timeout(self):
struct = Structure.from_file(filename=f"{TEST_FILES_DIR}/cif/garnet.cif")
SpacegroupAnalyzer(struct, 0.1)
Expand Down
28 changes: 8 additions & 20 deletions tests/command_line/test_gulp_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import os
import sys
import unittest
from shutil import which
from unittest import TestCase

Expand All @@ -30,13 +29,15 @@

TEST_DIR = f"{TEST_FILES_DIR}/command_line/gulp"

gulp_present = which("gulp") and os.getenv("GULP_LIB") and ("win" not in sys.platform)
# disable gulp tests for now. Right now, it is compiled against libgfortran3, which is no longer supported in the new
# Ubuntu 20.04.
gulp_present = False
GULP_PRESENT = which("gulp") and os.getenv("GULP_LIB") and ("win" not in sys.platform)
# Disable GULP tests for now: it is compiled against `libgfortran3``,
# which is no longer supported in Ubuntu 20.04 and onwards.
GULP_PRESENT = False

if not GULP_PRESENT:
pytest.skip(reason="GULP not available", allow_module_level=True)


@pytest.mark.skipif(not gulp_present, reason="gulp not present.")
class TestGulpCaller:
def test_run(self):
mgo_lattice = np.eye(3) * 4.212
Expand Down Expand Up @@ -105,7 +106,6 @@ def test_decimal(self):
caller.run(buckingham_input)


@pytest.mark.skipif(not gulp_present, reason="gulp not present.")
class TestGulpIO(TestCase):
def setUp(self):
self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18")
Expand All @@ -132,15 +132,6 @@ def test_structure_lines_no_frac_coords(self):
assert "cell" not in inp_str
assert "cart" in inp_str

@unittest.skip("Not Implemented yet")
def test_specie_potential(self):
pass

@unittest.expectedFailure
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might remove this test as it is hard-coded to check the content of a non-existent file:

@unittest.expectedFailure
def test_library_line_explicit_path(self):
gin = self.gio.library_line("/Users/mbkumar/Research/Defects/GulpExe/Libraries/catlow.lib")
assert "lib" in gin

def test_library_line_explicit_path(self):
gin = self.gio.library_line("/Users/mbkumar/Research/Defects/GulpExe/Libraries/catlow.lib")
assert "lib" in gin

def test_library_line_wrong_file(self):
with pytest.raises(GulpError, match="GULP library not found"):
self.gio.library_line("temp_to_fail.lib")
Expand Down Expand Up @@ -280,12 +271,11 @@ def test_get_relaxed_structure(self):
assert struct.lattice.a == 4.212
assert struct.lattice.alpha == 90

@unittest.skip("Test later")
@pytest.mark.skip("Test later")
def test_tersoff_input(self):
self.gio.tersoff_input(self.structure)


@pytest.mark.skipif(not gulp_present, reason="gulp not present.")
class TestGlobalFunctions(TestCase):
def setUp(self):
mgo_latt = np.eye(3) * 4.212
Expand Down Expand Up @@ -337,7 +327,6 @@ def test_get_energy_relax_structure_buckingham(self):
assert site_len == len(self.mgo_uc)


@pytest.mark.skipif(not gulp_present, reason="gulp not present.")
class TestBuckinghamPotentialLewis(TestCase):
def setUp(self):
self.bpl = BuckinghamPotential("lewis")
Expand Down Expand Up @@ -365,7 +354,6 @@ def test_spring(self):
assert self.bpl.spring_dict["O"] != ""


@pytest.mark.skipif(not gulp_present, reason="gulp not present.")
class TestBuckinghamPotentialBush(TestCase):
def setUp(self):
self.bpb = BuckinghamPotential("bush")
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import json
import os
import unittest

import numpy as np
import pytest
from numpy.testing import assert_allclose
from pytest import approx

Expand Down Expand Up @@ -697,7 +697,7 @@ def test_get_d(self):
s2 = recon2.get_unreconstructed_slabs()[0]
assert get_d(s1) == approx(get_d(s2))

@unittest.skip("This test relies on neighbor orders and is hard coded. Disable temporarily")
@pytest.mark.skip("This test relies on neighbor orders and is hard coded. Disable temporarily")
def test_previous_reconstructions(self):
# Test to see if we generated all reconstruction types correctly and nothing changes

Expand Down
3 changes: 1 addition & 2 deletions tests/io/test_zeopp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import pytest
Expand Down Expand Up @@ -167,7 +166,7 @@ def test_get_voronoi_nodes(self):
assert isinstance(vor_face_center_struct, Structure)


@unittest.skip("TODO: file free_sph.cif not present")
@pytest.mark.skip("TODO: file free_sph.cif not present")
class TestGetFreeSphereParams(TestCase):
def setUp(self):
filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif"
Expand Down
5 changes: 2 additions & 3 deletions tests/io/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import hashlib
import os
import unittest
from glob import glob
from zipfile import ZipFile

Expand Down Expand Up @@ -1607,7 +1606,7 @@ def test_user_incar_settings(self):
assert not vis.incar["LASPH"], "LASPH user setting not applied"
assert vis.incar["VDW_SR"] == 1.5, "VDW_SR user setting not applied"

@unittest.skipIf(not os.path.exists(TEST_DIR), "Test files are not present.")
@pytest.mark.skipif(not os.path.exists(TEST_DIR), reason="Test files are not present.")
def test_from_prev_calc(self):
prev_run = os.path.join(TEST_DIR, "fixtures", "relaxation")

Expand All @@ -1624,7 +1623,7 @@ def test_from_prev_calc(self):
assert "VDW_A2" in vis_bj.incar
assert "VDW_S8" in vis_bj.incar

@unittest.skipIf(not os.path.exists(TEST_DIR), "Test files are not present.")
@pytest.mark.skipif(not os.path.exists(TEST_DIR), reason="Test files are not present.")
def test_override_from_prev_calc(self):
prev_run = os.path.join(TEST_DIR, "fixtures", "relaxation")

Expand Down
Loading