From ea77121c6e202bb9ea6e6aa56b8b700ca0451e6e Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 00:06:43 -0500 Subject: [PATCH 1/7] move tests --- {src/diffpy/srreal/tests => tests}/__init__.py | 0 {src/diffpy/srreal/tests => tests}/debug.py | 0 {src/diffpy/srreal/tests => tests}/run.py | 0 {src/diffpy/srreal/tests => tests}/testatomradiitable.py | 0 {src/diffpy/srreal/tests => tests}/testattributes.py | 0 {src/diffpy/srreal/tests => tests}/testbondcalculator.py | 0 {src/diffpy/srreal/tests => tests}/testbvscalculator.py | 0 {src/diffpy/srreal/tests => tests}/testdata/C60bucky.stru | 0 {src/diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite.cif | 0 .../diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite_N.fgr | 0 .../diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite_X.fgr | 0 {src/diffpy/srreal/tests => tests}/testdata/Ni-fit.fgr | 0 {src/diffpy/srreal/tests => tests}/testdata/Ni.cif | 0 {src/diffpy/srreal/tests => tests}/testdata/Ni.stru | 0 {src/diffpy/srreal/tests => tests}/testdata/Ni_primitive.stru | 0 {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.cif | 0 {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.fgr | 0 {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.stru | 0 {src/diffpy/srreal/tests => tests}/testdata/rutile.cif | 0 {src/diffpy/srreal/tests => tests}/testdata/silicon.cif | 0 {src/diffpy/srreal/tests => tests}/testdata/sphalerite.cif | 0 {src/diffpy/srreal/tests => tests}/testdebyepdfcalculator.py | 0 {src/diffpy/srreal/tests => tests}/testoverlapcalculator.py | 0 {src/diffpy/srreal/tests => tests}/testpairquantity.py | 0 {src/diffpy/srreal/tests => tests}/testparallel.py | 0 {src/diffpy/srreal/tests => tests}/testpdfbaseline.py | 0 {src/diffpy/srreal/tests => tests}/testpdfcalcobjcryst.py | 0 {src/diffpy/srreal/tests => tests}/testpdfcalculator.py | 0 {src/diffpy/srreal/tests => tests}/testpdfenvelope.py | 0 {src/diffpy/srreal/tests => tests}/testpeakprofile.py | 0 {src/diffpy/srreal/tests => tests}/testpeakwidthmodel.py | 0 {src/diffpy/srreal/tests => tests}/testscatteringfactortable.py | 0 {src/diffpy/srreal/tests => tests}/testsfaverage.py | 0 {src/diffpy/srreal/tests => tests}/teststructureadapter.py | 0 {src/diffpy/srreal/tests => tests}/testutils.py | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename {src/diffpy/srreal/tests => tests}/__init__.py (100%) rename {src/diffpy/srreal/tests => tests}/debug.py (100%) rename {src/diffpy/srreal/tests => tests}/run.py (100%) rename {src/diffpy/srreal/tests => tests}/testatomradiitable.py (100%) rename {src/diffpy/srreal/tests => tests}/testattributes.py (100%) rename {src/diffpy/srreal/tests => tests}/testbondcalculator.py (100%) rename {src/diffpy/srreal/tests => tests}/testbvscalculator.py (100%) rename {src/diffpy/srreal/tests => tests}/testdata/C60bucky.stru (100%) rename {src/diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite_N.fgr (100%) rename {src/diffpy/srreal/tests => tests}/testdata/CdSe_cadmoselite_X.fgr (100%) rename {src/diffpy/srreal/tests => tests}/testdata/Ni-fit.fgr (100%) rename {src/diffpy/srreal/tests => tests}/testdata/Ni.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdata/Ni.stru (100%) rename {src/diffpy/srreal/tests => tests}/testdata/Ni_primitive.stru (100%) rename {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.fgr (100%) rename {src/diffpy/srreal/tests => tests}/testdata/TiO2_rutile-fit.stru (100%) rename {src/diffpy/srreal/tests => tests}/testdata/rutile.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdata/silicon.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdata/sphalerite.cif (100%) rename {src/diffpy/srreal/tests => tests}/testdebyepdfcalculator.py (100%) rename {src/diffpy/srreal/tests => tests}/testoverlapcalculator.py (100%) rename {src/diffpy/srreal/tests => tests}/testpairquantity.py (100%) rename {src/diffpy/srreal/tests => tests}/testparallel.py (100%) rename {src/diffpy/srreal/tests => tests}/testpdfbaseline.py (100%) rename {src/diffpy/srreal/tests => tests}/testpdfcalcobjcryst.py (100%) rename {src/diffpy/srreal/tests => tests}/testpdfcalculator.py (100%) rename {src/diffpy/srreal/tests => tests}/testpdfenvelope.py (100%) rename {src/diffpy/srreal/tests => tests}/testpeakprofile.py (100%) rename {src/diffpy/srreal/tests => tests}/testpeakwidthmodel.py (100%) rename {src/diffpy/srreal/tests => tests}/testscatteringfactortable.py (100%) rename {src/diffpy/srreal/tests => tests}/testsfaverage.py (100%) rename {src/diffpy/srreal/tests => tests}/teststructureadapter.py (100%) rename {src/diffpy/srreal/tests => tests}/testutils.py (100%) diff --git a/src/diffpy/srreal/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/diffpy/srreal/tests/__init__.py rename to tests/__init__.py diff --git a/src/diffpy/srreal/tests/debug.py b/tests/debug.py similarity index 100% rename from src/diffpy/srreal/tests/debug.py rename to tests/debug.py diff --git a/src/diffpy/srreal/tests/run.py b/tests/run.py similarity index 100% rename from src/diffpy/srreal/tests/run.py rename to tests/run.py diff --git a/src/diffpy/srreal/tests/testatomradiitable.py b/tests/testatomradiitable.py similarity index 100% rename from src/diffpy/srreal/tests/testatomradiitable.py rename to tests/testatomradiitable.py diff --git a/src/diffpy/srreal/tests/testattributes.py b/tests/testattributes.py similarity index 100% rename from src/diffpy/srreal/tests/testattributes.py rename to tests/testattributes.py diff --git a/src/diffpy/srreal/tests/testbondcalculator.py b/tests/testbondcalculator.py similarity index 100% rename from src/diffpy/srreal/tests/testbondcalculator.py rename to tests/testbondcalculator.py diff --git a/src/diffpy/srreal/tests/testbvscalculator.py b/tests/testbvscalculator.py similarity index 100% rename from src/diffpy/srreal/tests/testbvscalculator.py rename to tests/testbvscalculator.py diff --git a/src/diffpy/srreal/tests/testdata/C60bucky.stru b/tests/testdata/C60bucky.stru similarity index 100% rename from src/diffpy/srreal/tests/testdata/C60bucky.stru rename to tests/testdata/C60bucky.stru diff --git a/src/diffpy/srreal/tests/testdata/CdSe_cadmoselite.cif b/tests/testdata/CdSe_cadmoselite.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/CdSe_cadmoselite.cif rename to tests/testdata/CdSe_cadmoselite.cif diff --git a/src/diffpy/srreal/tests/testdata/CdSe_cadmoselite_N.fgr b/tests/testdata/CdSe_cadmoselite_N.fgr similarity index 100% rename from src/diffpy/srreal/tests/testdata/CdSe_cadmoselite_N.fgr rename to tests/testdata/CdSe_cadmoselite_N.fgr diff --git a/src/diffpy/srreal/tests/testdata/CdSe_cadmoselite_X.fgr b/tests/testdata/CdSe_cadmoselite_X.fgr similarity index 100% rename from src/diffpy/srreal/tests/testdata/CdSe_cadmoselite_X.fgr rename to tests/testdata/CdSe_cadmoselite_X.fgr diff --git a/src/diffpy/srreal/tests/testdata/Ni-fit.fgr b/tests/testdata/Ni-fit.fgr similarity index 100% rename from src/diffpy/srreal/tests/testdata/Ni-fit.fgr rename to tests/testdata/Ni-fit.fgr diff --git a/src/diffpy/srreal/tests/testdata/Ni.cif b/tests/testdata/Ni.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/Ni.cif rename to tests/testdata/Ni.cif diff --git a/src/diffpy/srreal/tests/testdata/Ni.stru b/tests/testdata/Ni.stru similarity index 100% rename from src/diffpy/srreal/tests/testdata/Ni.stru rename to tests/testdata/Ni.stru diff --git a/src/diffpy/srreal/tests/testdata/Ni_primitive.stru b/tests/testdata/Ni_primitive.stru similarity index 100% rename from src/diffpy/srreal/tests/testdata/Ni_primitive.stru rename to tests/testdata/Ni_primitive.stru diff --git a/src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.cif b/tests/testdata/TiO2_rutile-fit.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.cif rename to tests/testdata/TiO2_rutile-fit.cif diff --git a/src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.fgr b/tests/testdata/TiO2_rutile-fit.fgr similarity index 100% rename from src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.fgr rename to tests/testdata/TiO2_rutile-fit.fgr diff --git a/src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.stru b/tests/testdata/TiO2_rutile-fit.stru similarity index 100% rename from src/diffpy/srreal/tests/testdata/TiO2_rutile-fit.stru rename to tests/testdata/TiO2_rutile-fit.stru diff --git a/src/diffpy/srreal/tests/testdata/rutile.cif b/tests/testdata/rutile.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/rutile.cif rename to tests/testdata/rutile.cif diff --git a/src/diffpy/srreal/tests/testdata/silicon.cif b/tests/testdata/silicon.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/silicon.cif rename to tests/testdata/silicon.cif diff --git a/src/diffpy/srreal/tests/testdata/sphalerite.cif b/tests/testdata/sphalerite.cif similarity index 100% rename from src/diffpy/srreal/tests/testdata/sphalerite.cif rename to tests/testdata/sphalerite.cif diff --git a/src/diffpy/srreal/tests/testdebyepdfcalculator.py b/tests/testdebyepdfcalculator.py similarity index 100% rename from src/diffpy/srreal/tests/testdebyepdfcalculator.py rename to tests/testdebyepdfcalculator.py diff --git a/src/diffpy/srreal/tests/testoverlapcalculator.py b/tests/testoverlapcalculator.py similarity index 100% rename from src/diffpy/srreal/tests/testoverlapcalculator.py rename to tests/testoverlapcalculator.py diff --git a/src/diffpy/srreal/tests/testpairquantity.py b/tests/testpairquantity.py similarity index 100% rename from src/diffpy/srreal/tests/testpairquantity.py rename to tests/testpairquantity.py diff --git a/src/diffpy/srreal/tests/testparallel.py b/tests/testparallel.py similarity index 100% rename from src/diffpy/srreal/tests/testparallel.py rename to tests/testparallel.py diff --git a/src/diffpy/srreal/tests/testpdfbaseline.py b/tests/testpdfbaseline.py similarity index 100% rename from src/diffpy/srreal/tests/testpdfbaseline.py rename to tests/testpdfbaseline.py diff --git a/src/diffpy/srreal/tests/testpdfcalcobjcryst.py b/tests/testpdfcalcobjcryst.py similarity index 100% rename from src/diffpy/srreal/tests/testpdfcalcobjcryst.py rename to tests/testpdfcalcobjcryst.py diff --git a/src/diffpy/srreal/tests/testpdfcalculator.py b/tests/testpdfcalculator.py similarity index 100% rename from src/diffpy/srreal/tests/testpdfcalculator.py rename to tests/testpdfcalculator.py diff --git a/src/diffpy/srreal/tests/testpdfenvelope.py b/tests/testpdfenvelope.py similarity index 100% rename from src/diffpy/srreal/tests/testpdfenvelope.py rename to tests/testpdfenvelope.py diff --git a/src/diffpy/srreal/tests/testpeakprofile.py b/tests/testpeakprofile.py similarity index 100% rename from src/diffpy/srreal/tests/testpeakprofile.py rename to tests/testpeakprofile.py diff --git a/src/diffpy/srreal/tests/testpeakwidthmodel.py b/tests/testpeakwidthmodel.py similarity index 100% rename from src/diffpy/srreal/tests/testpeakwidthmodel.py rename to tests/testpeakwidthmodel.py diff --git a/src/diffpy/srreal/tests/testscatteringfactortable.py b/tests/testscatteringfactortable.py similarity index 100% rename from src/diffpy/srreal/tests/testscatteringfactortable.py rename to tests/testscatteringfactortable.py diff --git a/src/diffpy/srreal/tests/testsfaverage.py b/tests/testsfaverage.py similarity index 100% rename from src/diffpy/srreal/tests/testsfaverage.py rename to tests/testsfaverage.py diff --git a/src/diffpy/srreal/tests/teststructureadapter.py b/tests/teststructureadapter.py similarity index 100% rename from src/diffpy/srreal/tests/teststructureadapter.py rename to tests/teststructureadapter.py diff --git a/src/diffpy/srreal/tests/testutils.py b/tests/testutils.py similarity index 100% rename from src/diffpy/srreal/tests/testutils.py rename to tests/testutils.py From abc8a9c988d91858e38829bd12941e21680e91e8 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 00:10:24 -0500 Subject: [PATCH 2/7] remove unnecessary files, add conftest --- tests/__init__.py | 85 ------------------------------------------- tests/conftest.py | 19 ++++++++++ tests/debug.py | 33 ----------------- tests/run.py | 37 ------------------- tests/test_version.py | 10 +++++ 5 files changed, 29 insertions(+), 155 deletions(-) delete mode 100644 tests/__init__.py create mode 100644 tests/conftest.py delete mode 100644 tests/debug.py delete mode 100644 tests/run.py create mode 100644 tests/test_version.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index c4e942b5..00000000 --- a/tests/__init__.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srreal by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2012 The Trustees of Columbia University -# in the City of New York. All rights reserved. -# -# File coded by: Pavol Juhas -# -# See AUTHORS.txt for a list of people who contributed. -# See LICENSE_DANSE.txt for license information. -# -############################################################################## -"""Unit tests for diffpy.srreal.""" - -import logging -import unittest - -# create logger instance for the tests subpackage -logging.basicConfig() -logger = logging.getLogger(__name__) -del logging - - -def testsuite(pattern=""): - """Create a unit tests suite for diffpy.srreal package. - - Parameters - ---------- - pattern : str, optional - Regular expression pattern for selecting test cases. - Select all tests when empty. Ignore the pattern when - any of unit test modules fails to import. - - Returns - ------- - suite : `unittest.TestSuite` - The TestSuite object containing the matching tests. - """ - import re - from itertools import chain - from os.path import dirname - - from pkg_resources import resource_filename - - loader = unittest.defaultTestLoader - thisdir = resource_filename(__name__, "") - depth = __name__.count(".") + 1 - topdir = thisdir - for i in range(depth): - topdir = dirname(topdir) - suite_all = loader.discover(thisdir, top_level_dir=topdir) - # always filter the suite by pattern to test-cover the selection code. - suite = unittest.TestSuite() - rx = re.compile(pattern) - tsuites = list(chain.from_iterable(suite_all)) - tsok = all(isinstance(ts, unittest.TestSuite) for ts in tsuites) - if not tsok: # pragma: no cover - return suite_all - tcases = chain.from_iterable(tsuites) - for tc in tcases: - tcwords = tc.id().split(".") - shortname = ".".join(tcwords[-3:]) - if rx.search(shortname): - suite.addTest(tc) - # verify all tests are found for an empty pattern. - assert pattern or suite_all.countTestCases() == suite.countTestCases() - return suite - - -def test(): - """Execute all unit tests for the diffpy.srreal package. - - Returns - ------- - result : `unittest.TestResult` - """ - suite = testsuite() - runner = unittest.TextTestRunner() - result = runner.run(suite) - return result - - -# End of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..e3b63139 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import json +from pathlib import Path + +import pytest + + +@pytest.fixture +def user_filesystem(tmp_path): + base_dir = Path(tmp_path) + home_dir = base_dir / "home_dir" + home_dir.mkdir(parents=True, exist_ok=True) + cwd_dir = base_dir / "cwd_dir" + cwd_dir.mkdir(parents=True, exist_ok=True) + + home_config_data = {"username": "home_username", "email": "home@email.com"} + with open(home_dir / "diffpyconfig.json", "w") as f: + json.dump(home_config_data, f) + + yield tmp_path diff --git a/tests/debug.py b/tests/debug.py deleted file mode 100644 index 47197f9c..00000000 --- a/tests/debug.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srreal Complex Modeling Initiative -# (c) 2016 Brookhaven Science Associates, -# Brookhaven National Laboratory. -# All rights reserved. -# -# File coded by: Pavol Juhas -# -# See AUTHORS.txt for a list of people who contributed. -# See LICENSE.txt for license information. -# -############################################################################## -"""Convenience module for debugging the unit tests using. - -python -m diffpy.srreal.tests.debug - -Exceptions raised by failed tests or other errors are not caught. -""" - - -if __name__ == "__main__": - import sys - - from diffpy.srreal.tests import testsuite - - pattern = sys.argv[1] if len(sys.argv) > 1 else "" - suite = testsuite(pattern) - suite.debug() - - -# End of file diff --git a/tests/run.py b/tests/run.py deleted file mode 100644 index 9d107059..00000000 --- a/tests/run.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srreal by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2010 The Trustees of Columbia University -# in the City of New York. All rights reserved. -# -# File coded by: Pavol Juhas -# -# See AUTHORS.txt for a list of people who contributed. -# See LICENSE_DANSE.txt for license information. -# -############################################################################## -"""Convenience module for executing all unit tests with. - -python -m diffpy.srreal.tests.run -""" - - -if __name__ == "__main__": - import sys - - # show warnings by default - if not sys.warnoptions: - import os - import warnings - - warnings.simplefilter("default") - # also affect subprocesses - os.environ["PYTHONWARNINGS"] = "default" - from diffpy.srreal.tests import test - - # produce zero exit code for a successful test - sys.exit(not test().wasSuccessful()) - -# End of file diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 00000000..d50b30db --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,10 @@ +"""Unit tests for __version__.py.""" + +import diffpy.srreal + + +def test_package_version(): + """Ensure the package version is defined and not set to the initial + placeholder.""" + assert hasattr(diffpy.srreal, "__version__") + assert diffpy.srreal.__version__ != "0.0.0" From f01987ab40d920f060a4f76f1341899834b332cc Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 00:14:52 -0500 Subject: [PATCH 3/7] easy tests --- tests/{testattributes.py => test_attributes.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{testattributes.py => test_attributes.py} (100%) diff --git a/tests/testattributes.py b/tests/test_attributes.py similarity index 100% rename from tests/testattributes.py rename to tests/test_attributes.py From 70e88e4eb30232392242bb9ddcd83ac42dbf8ca1 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 04:29:26 -0500 Subject: [PATCH 4/7] fix pytest --- tests/conftest.py | 56 +++++++++++++++++ ...omradiitable.py => test_atomradiitable.py} | 11 ++-- ...ndcalculator.py => test_bondcalculator.py} | 14 +++-- ...bvscalculator.py => test_bvscalculator.py} | 4 +- ...lculator.py => test_debyepdfcalculator.py} | 5 +- ...alculator.py => test_overlapcalculator.py} | 14 +++-- ...stpairquantity.py => test_pairquantity.py} | 4 +- tests/{testparallel.py => test_parallel.py} | 2 +- ...testpdfbaseline.py => test_pdfbaseline.py} | 2 +- ...alcobjcryst.py => test_pdfcalcobjcryst.py} | 11 ++-- ...pdfcalculator.py => test_pdfcalculator.py} | 13 +--- ...testpdfenvelope.py => test_pdfenvelope.py} | 2 +- ...testpeakprofile.py => test_peakprofile.py} | 2 +- ...akwidthmodel.py => test_peakwidthmodel.py} | 2 +- ...table.py => test_scatteringfactortable.py} | 2 +- tests/{testsfaverage.py => test_sfaverage.py} | 12 ++-- ...ureadapter.py => test_structureadapter.py} | 27 ++++---- tests/testutils.py | 63 +++++-------------- 18 files changed, 136 insertions(+), 110 deletions(-) rename tests/{testatomradiitable.py => test_atomradiitable.py} (96%) rename tests/{testbondcalculator.py => test_bondcalculator.py} (97%) rename tests/{testbvscalculator.py => test_bvscalculator.py} (97%) rename tests/{testdebyepdfcalculator.py => test_debyepdfcalculator.py} (97%) rename tests/{testoverlapcalculator.py => test_overlapcalculator.py} (98%) rename tests/{testpairquantity.py => test_pairquantity.py} (98%) rename tests/{testparallel.py => test_parallel.py} (98%) rename tests/{testpdfbaseline.py => test_pdfbaseline.py} (99%) rename tests/{testpdfcalcobjcryst.py => test_pdfcalcobjcryst.py} (92%) rename tests/{testpdfcalculator.py => test_pdfcalculator.py} (96%) rename tests/{testpdfenvelope.py => test_pdfenvelope.py} (99%) rename tests/{testpeakprofile.py => test_peakprofile.py} (98%) rename tests/{testpeakwidthmodel.py => test_peakwidthmodel.py} (99%) rename tests/{testscatteringfactortable.py => test_scatteringfactortable.py} (99%) rename tests/{testsfaverage.py => test_sfaverage.py} (94%) rename tests/{teststructureadapter.py => test_structureadapter.py} (97%) diff --git a/tests/conftest.py b/tests/conftest.py index e3b63139..81a85fc5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,12 @@ import json +import logging from pathlib import Path import pytest +from diffpy.srreal.structureconverters import convertObjCrystCrystal +import diffpy.structure as mod_structure + @pytest.fixture def user_filesystem(tmp_path): @@ -17,3 +21,55 @@ def user_filesystem(tmp_path): json.dump(home_config_data, f) yield tmp_path + + +# Resolve availability of optional packages. + +# pyobjcryst + + +@pytest.fixture(scope="session") +def _msg_nopyobjcryst(): + return "No module named 'pyobjcryst'" + + +@pytest.fixture(scope="session") +def has_pyobjcryst(): + try: + import pyobjcryst.crystal + convertObjCrystCrystal(pyobjcryst.crystal.Crystal()) + has_pyobjcryst = True + except ImportError: + has_pyobjcryst = False + logging.warning("Cannot import pyobjcryst, pyobjcryst tests skipped.") + print("Cannot import pyobjcryst, pyobjcryst tests skipped.") + except TypeError: + has_pyobjcryst = False + logging.warning("Compiled without ObjCryst, pyobjcryst tests skipped.") + print("Compiled without ObjCryst, pyobjcryst tests skipped.") + + return has_pyobjcryst + + +# periodictable + + +@pytest.fixture(scope="session") +def _msg_noperiodictable(): + return "No module named 'periodictable'" + + +@pytest.fixture(scope="session") +def has_periodictable(): + try: + import periodictable + + has_periodictable = True + + # silence the pyflakes syntax checker + del periodictable + except ImportError: + has_periodictable = False + logging.warning("Cannot import periodictable, periodictable tests skipped.") + + return has_periodictable diff --git a/tests/testatomradiitable.py b/tests/test_atomradiitable.py similarity index 96% rename from tests/testatomradiitable.py rename to tests/test_atomradiitable.py index f5c2265e..fc4ead69 100644 --- a/tests/testatomradiitable.py +++ b/tests/test_atomradiitable.py @@ -5,15 +5,13 @@ import pickle import unittest +import pytest from diffpy.srreal.atomradiitable import AtomRadiiTable, ConstantRadiiTable, CovalentRadiiTable -from diffpy.srreal.tests.testutils import _msg_noperiodictable, has_periodictable # ---------------------------------------------------------------------------- - class TestAtomRadiiTable(unittest.TestCase): - def setUp(self): self.rtb = AtomRadiiTable() self.ctb = ConstantRadiiTable() @@ -102,10 +100,13 @@ def test_toString(self): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_periodictable, _msg_noperiodictable) class TestCovalentRadiiTable(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_periodictable, _msg_noperiodictable): + if not has_periodictable: + pytest.skip(_msg_noperiodictable) + def setUp(self): self.rtb = CovalentRadiiTable() return diff --git a/tests/testbondcalculator.py b/tests/test_bondcalculator.py similarity index 97% rename from tests/testbondcalculator.py rename to tests/test_bondcalculator.py index cbbe6090..47fcc286 100644 --- a/tests/testbondcalculator.py +++ b/tests/test_bondcalculator.py @@ -5,13 +5,12 @@ import pickle import unittest +import pytest import numpy from diffpy.srreal.bondcalculator import BondCalculator -from diffpy.srreal.tests.testutils import ( - _msg_nopyobjcryst, - has_pyobjcryst, +from testutils import ( loadDiffPyStructure, loadObjCrystCrystal, pickle_with_attr, @@ -81,7 +80,7 @@ def test_pickling(self): def test_pickling_derived_structure(self): """Check pickling of BondCalculator with DerivedStructureAdapter.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter bdc = self.bdc stru0 = DerivedStructureAdapter() @@ -248,10 +247,13 @@ def test_setTypeMask(self): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_pyobjcryst, _msg_nopyobjcryst) class TestBondCalculatorObjCryst(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + if not has_pyobjcryst: + pytest.skip(_msg_nopyobjcryst) + def setUp(self): self.bdc = BondCalculator() if not hasattr(self, "rutile"): diff --git a/tests/testbvscalculator.py b/tests/test_bvscalculator.py similarity index 97% rename from tests/testbvscalculator.py rename to tests/test_bvscalculator.py index aceac210..3e936017 100644 --- a/tests/testbvscalculator.py +++ b/tests/test_bvscalculator.py @@ -7,7 +7,7 @@ import unittest from diffpy.srreal.bvscalculator import BVSCalculator -from diffpy.srreal.tests.testutils import loadDiffPyStructure, pickle_with_attr +from testutils import loadDiffPyStructure, pickle_with_attr ############################################################################## @@ -139,7 +139,7 @@ def test_table_pickling(self): def test_pickling_derived_structure(self): """Check pickling of BVSCalculator with DerivedStructureAdapter.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter bvc = self.bvc stru0 = DerivedStructureAdapter() diff --git a/tests/testdebyepdfcalculator.py b/tests/test_debyepdfcalculator.py similarity index 97% rename from tests/testdebyepdfcalculator.py rename to tests/test_debyepdfcalculator.py index fd8c07d4..65e04a0c 100644 --- a/tests/testdebyepdfcalculator.py +++ b/tests/test_debyepdfcalculator.py @@ -9,8 +9,7 @@ import numpy from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator -from diffpy.srreal.tests.testpdfcalculator import _maxNormDiff -from diffpy.srreal.tests.testutils import loadDiffPyStructure, pickle_with_attr +from testutils import loadDiffPyStructure, pickle_with_attr, _maxNormDiff ############################################################################## @@ -189,7 +188,7 @@ def test_mask_pickling(self): def test_pickling_derived_structure(self): """Check pickling of DebyePDFCalculator with DerivedStructureAdapter.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter dpdfc = self.dpdfc stru0 = DerivedStructureAdapter() diff --git a/tests/testoverlapcalculator.py b/tests/test_overlapcalculator.py similarity index 98% rename from tests/testoverlapcalculator.py rename to tests/test_overlapcalculator.py index aabda0e6..6b410c9e 100644 --- a/tests/testoverlapcalculator.py +++ b/tests/test_overlapcalculator.py @@ -6,14 +6,13 @@ import copy import pickle import unittest +import pytest import numpy from diffpy.srreal.atomradiitable import CovalentRadiiTable from diffpy.srreal.overlapcalculator import OverlapCalculator -from diffpy.srreal.tests.testutils import ( - _msg_nopyobjcryst, - has_pyobjcryst, +from testutils import ( loadDiffPyStructure, loadObjCrystCrystal, pickle_with_attr, @@ -117,7 +116,7 @@ def test_pickling_artb(self): def test_pickling_derived_structure(self): """Check pickling of OverlapCalculator with DerivedStructureAdapter.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter olc = self.olc stru0 = DerivedStructureAdapter() @@ -331,10 +330,13 @@ def test_neighborhoods(self): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_pyobjcryst, _msg_nopyobjcryst) class TestOverlapCalculatorObjCryst(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + if not has_pyobjcryst: + pytest.skip(_msg_nopyobjcryst) + def setUp(self): self.olc = OverlapCalculator() if not hasattr(self, "rutile"): diff --git a/tests/testpairquantity.py b/tests/test_pairquantity.py similarity index 98% rename from tests/testpairquantity.py rename to tests/test_pairquantity.py index c07da95c..689883aa 100644 --- a/tests/testpairquantity.py +++ b/tests/test_pairquantity.py @@ -10,7 +10,7 @@ from diffpy.srreal.pairquantity import PairQuantity from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.srreal_ext import BasePairQuantity -from diffpy.srreal.tests.testutils import mod_structure +from testutils import mod_structure # ---------------------------------------------------------------------------- @@ -169,7 +169,7 @@ def eval_as(evtp, pq, stru): def test_pickling(self): """Check pickling and unpickling of PairQuantity.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter stru0 = DerivedStructureAdapter() self.pq.setStructure(stru0) diff --git a/tests/testparallel.py b/tests/test_parallel.py similarity index 98% rename from tests/testparallel.py rename to tests/test_parallel.py index e6ae9c12..050cd222 100644 --- a/tests/testparallel.py +++ b/tests/test_parallel.py @@ -9,7 +9,7 @@ import numpy from diffpy.srreal.parallel import createParallelCalculator -from diffpy.srreal.tests.testutils import loadDiffPyStructure +from testutils import loadDiffPyStructure ############################################################################## diff --git a/tests/testpdfbaseline.py b/tests/test_pdfbaseline.py similarity index 99% rename from tests/testpdfbaseline.py rename to tests/test_pdfbaseline.py index 152119e7..8e07d78f 100644 --- a/tests/testpdfbaseline.py +++ b/tests/test_pdfbaseline.py @@ -10,7 +10,7 @@ from diffpy.srreal.pdfbaseline import LinearBaseline, PDFBaseline, ZeroBaseline, makePDFBaseline from diffpy.srreal.pdfcalculator import PDFCalculator -from diffpy.srreal.tests.testutils import pickle_with_attr +from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/testpdfcalcobjcryst.py b/tests/test_pdfcalcobjcryst.py similarity index 92% rename from tests/testpdfcalcobjcryst.py rename to tests/test_pdfcalcobjcryst.py index 01ef21b8..980a71f0 100644 --- a/tests/testpdfcalcobjcryst.py +++ b/tests/test_pdfcalcobjcryst.py @@ -5,12 +5,12 @@ import re import unittest +import pytest import numpy from diffpy.srreal.pdfcalculator import PDFCalculator -from diffpy.srreal.tests.testpdfcalculator import _maxNormDiff -from diffpy.srreal.tests.testutils import _msg_nopyobjcryst, datafile, has_pyobjcryst, loadObjCrystCrystal +from testutils import datafile, loadObjCrystCrystal, _maxNormDiff # helper functions @@ -58,10 +58,13 @@ def _makePDFCalculator(crst, cfgdict): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_pyobjcryst, _msg_nopyobjcryst) class TestPDFCalcObjcryst(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + if not has_pyobjcryst: + pytest.skip(_msg_nopyobjcryst) + def _comparePDFs(self, nickname, pdfbasename, cifbasename): def setself(**kwtoset): for n, v in kwtoset.items(): diff --git a/tests/testpdfcalculator.py b/tests/test_pdfcalculator.py similarity index 96% rename from tests/testpdfcalculator.py rename to tests/test_pdfcalculator.py index 5b790032..a27e84d9 100644 --- a/tests/testpdfcalculator.py +++ b/tests/test_pdfcalculator.py @@ -9,20 +9,11 @@ import numpy from diffpy.srreal.pdfcalculator import PDFCalculator, fftftog, fftgtof -from diffpy.srreal.tests.testutils import datafile, loadDiffPyStructure, pickle_with_attr +from testutils import datafile, loadDiffPyStructure, pickle_with_attr, _maxNormDiff # helper functions -def _maxNormDiff(yobs, ycalc): - """Returned maximum difference normalized by RMS of the yobs.""" - yobsa = numpy.array(yobs) - obsmax = numpy.max(numpy.fabs(yobsa)) or 1 - ynmdiff = (yobsa - ycalc) / obsmax - rv = max(numpy.fabs(ynmdiff)) - return rv - - # ---------------------------------------------------------------------------- @@ -274,7 +265,7 @@ def test_mask_pickling(self): def test_pickling_derived_structure(self): """Check pickling of PDFCalculator with DerivedStructureAdapter.""" - from diffpy.srreal.tests.testutils import DerivedStructureAdapter + from testutils import DerivedStructureAdapter pdfc = self.pdfcalc stru0 = DerivedStructureAdapter() diff --git a/tests/testpdfenvelope.py b/tests/test_pdfenvelope.py similarity index 99% rename from tests/testpdfenvelope.py rename to tests/test_pdfenvelope.py index cf840554..f6493f2b 100644 --- a/tests/testpdfenvelope.py +++ b/tests/test_pdfenvelope.py @@ -17,7 +17,7 @@ StepCutEnvelope, makePDFEnvelope, ) -from diffpy.srreal.tests.testutils import pickle_with_attr +from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/testpeakprofile.py b/tests/test_peakprofile.py similarity index 98% rename from tests/testpeakprofile.py rename to tests/test_peakprofile.py index 56e3943e..8676afdb 100644 --- a/tests/testpeakprofile.py +++ b/tests/test_peakprofile.py @@ -10,7 +10,7 @@ from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.peakprofile import PeakProfile -from diffpy.srreal.tests.testutils import mod_structure, pickle_with_attr +from testutils import mod_structure, pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/testpeakwidthmodel.py b/tests/test_peakwidthmodel.py similarity index 99% rename from tests/testpeakwidthmodel.py rename to tests/test_peakwidthmodel.py index 0ba053f7..6b8e25a0 100644 --- a/tests/testpeakwidthmodel.py +++ b/tests/test_peakwidthmodel.py @@ -10,7 +10,7 @@ from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator from diffpy.srreal.peakwidthmodel import DebyeWallerPeakWidth, JeongPeakWidth, PeakWidthModel from diffpy.srreal.structureadapter import createStructureAdapter -from diffpy.srreal.tests.testutils import loadDiffPyStructure +from testutils import loadDiffPyStructure # ---------------------------------------------------------------------------- diff --git a/tests/testscatteringfactortable.py b/tests/test_scatteringfactortable.py similarity index 99% rename from tests/testscatteringfactortable.py rename to tests/test_scatteringfactortable.py index e4c95be6..48d1efe0 100644 --- a/tests/testscatteringfactortable.py +++ b/tests/test_scatteringfactortable.py @@ -16,7 +16,7 @@ SFTNeutron, SFTXray, ) -from diffpy.srreal.tests.testutils import pickle_with_attr +from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/testsfaverage.py b/tests/test_sfaverage.py similarity index 94% rename from tests/testsfaverage.py rename to tests/test_sfaverage.py index 6efaa981..78d39fd2 100644 --- a/tests/testsfaverage.py +++ b/tests/test_sfaverage.py @@ -4,14 +4,13 @@ import unittest +import pytest import numpy from diffpy.srreal.scatteringfactortable import ScatteringFactorTable from diffpy.srreal.sfaverage import SFAverage -from diffpy.srreal.tests.testutils import ( - _msg_nopyobjcryst, - has_pyobjcryst, +from testutils import ( loadDiffPyStructure, loadObjCrystCrystal, ) @@ -77,10 +76,13 @@ def test_fromComposition(self): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_pyobjcryst, _msg_nopyobjcryst) class TestSFAverageObjCryst(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + if not has_pyobjcryst: + pytest.skip(_msg_nopyobjcryst) + def setUp(self): self.sftx = ScatteringFactorTable.createByType("X") return diff --git a/tests/teststructureadapter.py b/tests/test_structureadapter.py similarity index 97% rename from tests/teststructureadapter.py rename to tests/test_structureadapter.py index 55a3604c..6cd69a36 100644 --- a/tests/teststructureadapter.py +++ b/tests/test_structureadapter.py @@ -5,10 +5,10 @@ import pickle import unittest +import pytest import numpy -import diffpy.srreal.tests.testutils as testutils from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.structureadapter import ( Atom, @@ -20,12 +20,14 @@ nometa, nosymmetry, ) -from diffpy.srreal.tests.testutils import ( - _msg_nopyobjcryst, - has_pyobjcryst, +from testutils import ( loadCrystalStructureAdapter, loadDiffPyStructure, loadObjCrystCrystal, + DerivedStructureAdapter, + DerivedAtomicStructureAdapter, + DerivedPeriodicStructureAdapter, + DerivedCrystalStructureAdapter ) # ---------------------------------------------------------------------------- @@ -110,7 +112,7 @@ def test_pickle_nonwrapped(self): class TestDerivedAdapter(unittest.TestCase): "Check functionality in a Python-derived StructureAdapter class." - DerivedCls = testutils.DerivedStructureAdapter + DerivedCls = DerivedStructureAdapter def setUp(self): self.adpt = self.DerivedCls() @@ -145,15 +147,15 @@ def test_pickling(self): class TestDerivedAtomicAdapter(TestDerivedAdapter): - DerivedCls = testutils.DerivedAtomicStructureAdapter + DerivedCls = DerivedAtomicStructureAdapter class TestDerivedPeriodicAdapter(TestDerivedAdapter): - DerivedCls = testutils.DerivedPeriodicStructureAdapter + DerivedCls = DerivedPeriodicStructureAdapter class TestDerivedCrystalAdapter(TestDerivedAdapter): - DerivedCls = testutils.DerivedCrystalStructureAdapter + DerivedCls = DerivedCrystalStructureAdapter # ---------------------------------------------------------------------------- @@ -267,10 +269,13 @@ def test_nosymmetry_pickling(self): # ---------------------------------------------------------------------------- - -@unittest.skipUnless(has_pyobjcryst, _msg_nopyobjcryst) class TestPyObjCrystAdapter(unittest.TestCase): + @pytest.fixture(autouse=True) + def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + if not has_pyobjcryst: + pytest.skip(_msg_nopyobjcryst) + def setUp(self): rutile_crystal = loadObjCrystCrystal("TiO2_rutile-fit.cif") self.rutile = createStructureAdapter(rutile_crystal) @@ -408,7 +413,7 @@ def test_getEquivalentAtoms(self): class TestDerivedStructureAdapter(IndexRangeTests, TestCase): - AdptClass = testutils.DerivedStructureAdapter + AdptClass = DerivedStructureAdapter def setUp(self): IndexRangeTests.setUp(self) diff --git a/tests/testutils.py b/tests/testutils.py index 8cbb3ecc..d68dd99c 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -14,61 +14,18 @@ PeriodicStructureAdapter, StructureAdapter, ) -from diffpy.srreal.structureconverters import convertObjCrystCrystal -from diffpy.srreal.tests import logger - -# Deprecated in 1.3 - import of old camel-case diffpy.Structure names. -# TODO drop this in version 1.4. - -try: - import diffpy.structure as mod_structure - from diffpy.structure.parsers import getParser -except ImportError as e: - try: - import diffpy.Structure as mod_structure - from diffpy.Structure.Parsers import getParser - except ImportError: - raise e - del e - -# Resolve availability of optional packages. - -# pyobjcryst - -_msg_nopyobjcryst = "No module named 'pyobjcryst'" -try: - import pyobjcryst.crystal - - convertObjCrystCrystal(pyobjcryst.crystal.Crystal()) - has_pyobjcryst = True -except ImportError: - has_pyobjcryst = False - logger.warning("Cannot import pyobjcryst, pyobjcryst tests skipped.") -except TypeError: - has_pyobjcryst = False - logger.warning("Compiled without ObjCryst, pyobjcryst tests skipped.") - -# periodictable - -_msg_noperiodictable = "No module named 'periodictable'" -try: - import periodictable - - has_periodictable = True - # silence the pyflakes syntax checker - del periodictable -except ImportError: - has_periodictable = False - logger.warning("Cannot import periodictable, periodictable tests skipped.") +import diffpy.structure as mod_structure +from diffpy.structure.parsers import getParser + # helper functions def datafile(filename): - from pkg_resources import resource_filename + from pathlib import Path - rv = resource_filename(__name__, "testdata/" + filename) - return rv + rv = Path(__file__).parent / "testdata" / filename + return str(rv) def loadObjCrystCrystal(filename): @@ -108,6 +65,14 @@ def pickle_with_attr(obj, **attr): return rv +def _maxNormDiff(yobs, ycalc): + """Returned maximum difference normalized by RMS of the yobs.""" + yobsa = numpy.array(yobs) + obsmax = numpy.max(numpy.fabs(yobsa)) or 1 + ynmdiff = (yobsa - ycalc) / obsmax + rv = max(numpy.fabs(ynmdiff)) + return rv + # helper class for testing overloading of StructureAdapter From 95f2ef125df7a69395299aa23aaafa436628a872 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 04:56:49 -0500 Subject: [PATCH 5/7] update CI --- .github/workflows/tests-on-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index f9b4d90b..dfdbc776 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -36,8 +36,8 @@ jobs: - name: Install diffpy.srreal and requirements run: | conda install --file requirements/test.txt - conda install --file requirements/conda.txt + conda install boost numpy libdiffpy setuptools diffpy.structure periodictable gsl python -m pip install . --no-deps - name: Validate diffpy.pdfgui - run: python -m diffpy.srreal.tests.run + run: pytest tests From 59f94716f04be33b01b6a6e97a681b255e6a99cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 11 Jan 2025 09:58:02 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit hooks --- tests/conftest.py | 3 ++- tests/test_atomradiitable.py | 3 +++ tests/test_bondcalculator.py | 9 +++------ tests/test_bvscalculator.py | 3 ++- tests/test_debyepdfcalculator.py | 2 +- tests/test_overlapcalculator.py | 9 +++------ tests/test_pairquantity.py | 2 +- tests/test_parallel.py | 2 +- tests/test_pdfbaseline.py | 2 +- tests/test_pdfcalcobjcryst.py | 5 +++-- tests/test_pdfcalculator.py | 2 +- tests/test_pdfenvelope.py | 2 +- tests/test_peakprofile.py | 2 +- tests/test_peakwidthmodel.py | 3 ++- tests/test_scatteringfactortable.py | 2 +- tests/test_sfaverage.py | 8 +++----- tests/test_structureadapter.py | 21 +++++++++++---------- tests/testutils.py | 4 ++-- 18 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 81a85fc5..273cc36f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,8 +4,8 @@ import pytest -from diffpy.srreal.structureconverters import convertObjCrystCrystal import diffpy.structure as mod_structure +from diffpy.srreal.structureconverters import convertObjCrystCrystal @pytest.fixture @@ -37,6 +37,7 @@ def _msg_nopyobjcryst(): def has_pyobjcryst(): try: import pyobjcryst.crystal + convertObjCrystCrystal(pyobjcryst.crystal.Crystal()) has_pyobjcryst = True except ImportError: diff --git a/tests/test_atomradiitable.py b/tests/test_atomradiitable.py index fc4ead69..158a6f4d 100644 --- a/tests/test_atomradiitable.py +++ b/tests/test_atomradiitable.py @@ -5,12 +5,14 @@ import pickle import unittest + import pytest from diffpy.srreal.atomradiitable import AtomRadiiTable, ConstantRadiiTable, CovalentRadiiTable # ---------------------------------------------------------------------------- + class TestAtomRadiiTable(unittest.TestCase): def setUp(self): self.rtb = AtomRadiiTable() @@ -100,6 +102,7 @@ def test_toString(self): # ---------------------------------------------------------------------------- + class TestCovalentRadiiTable(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/test_bondcalculator.py b/tests/test_bondcalculator.py index 47fcc286..cd69fe55 100644 --- a/tests/test_bondcalculator.py +++ b/tests/test_bondcalculator.py @@ -5,16 +5,12 @@ import pickle import unittest -import pytest import numpy +import pytest +from testutils import loadDiffPyStructure, loadObjCrystCrystal, pickle_with_attr from diffpy.srreal.bondcalculator import BondCalculator -from testutils import ( - loadDiffPyStructure, - loadObjCrystCrystal, - pickle_with_attr, -) # ---------------------------------------------------------------------------- @@ -247,6 +243,7 @@ def test_setTypeMask(self): # ---------------------------------------------------------------------------- + class TestBondCalculatorObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/test_bvscalculator.py b/tests/test_bvscalculator.py index 3e936017..c2f3838a 100644 --- a/tests/test_bvscalculator.py +++ b/tests/test_bvscalculator.py @@ -6,9 +6,10 @@ import pickle import unittest -from diffpy.srreal.bvscalculator import BVSCalculator from testutils import loadDiffPyStructure, pickle_with_attr +from diffpy.srreal.bvscalculator import BVSCalculator + ############################################################################## class TestBVSCalculator(unittest.TestCase): diff --git a/tests/test_debyepdfcalculator.py b/tests/test_debyepdfcalculator.py index 65e04a0c..693a7ab5 100644 --- a/tests/test_debyepdfcalculator.py +++ b/tests/test_debyepdfcalculator.py @@ -7,9 +7,9 @@ import unittest import numpy +from testutils import _maxNormDiff, loadDiffPyStructure, pickle_with_attr from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator -from testutils import loadDiffPyStructure, pickle_with_attr, _maxNormDiff ############################################################################## diff --git a/tests/test_overlapcalculator.py b/tests/test_overlapcalculator.py index 6b410c9e..5a7a2040 100644 --- a/tests/test_overlapcalculator.py +++ b/tests/test_overlapcalculator.py @@ -6,17 +6,13 @@ import copy import pickle import unittest -import pytest import numpy +import pytest +from testutils import loadDiffPyStructure, loadObjCrystCrystal, pickle_with_attr from diffpy.srreal.atomradiitable import CovalentRadiiTable from diffpy.srreal.overlapcalculator import OverlapCalculator -from testutils import ( - loadDiffPyStructure, - loadObjCrystCrystal, - pickle_with_attr, -) # ---------------------------------------------------------------------------- @@ -330,6 +326,7 @@ def test_neighborhoods(self): # ---------------------------------------------------------------------------- + class TestOverlapCalculatorObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/test_pairquantity.py b/tests/test_pairquantity.py index 689883aa..01e3bd94 100644 --- a/tests/test_pairquantity.py +++ b/tests/test_pairquantity.py @@ -6,11 +6,11 @@ import unittest import numpy +from testutils import mod_structure from diffpy.srreal.pairquantity import PairQuantity from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.srreal_ext import BasePairQuantity -from testutils import mod_structure # ---------------------------------------------------------------------------- diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 050cd222..3bc524c6 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -7,9 +7,9 @@ import unittest import numpy +from testutils import loadDiffPyStructure from diffpy.srreal.parallel import createParallelCalculator -from testutils import loadDiffPyStructure ############################################################################## diff --git a/tests/test_pdfbaseline.py b/tests/test_pdfbaseline.py index 8e07d78f..20535ce5 100644 --- a/tests/test_pdfbaseline.py +++ b/tests/test_pdfbaseline.py @@ -7,10 +7,10 @@ import unittest import numpy +from testutils import pickle_with_attr from diffpy.srreal.pdfbaseline import LinearBaseline, PDFBaseline, ZeroBaseline, makePDFBaseline from diffpy.srreal.pdfcalculator import PDFCalculator -from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/test_pdfcalcobjcryst.py b/tests/test_pdfcalcobjcryst.py index 980a71f0..3fd4d4ca 100644 --- a/tests/test_pdfcalcobjcryst.py +++ b/tests/test_pdfcalcobjcryst.py @@ -5,12 +5,12 @@ import re import unittest -import pytest import numpy +import pytest +from testutils import _maxNormDiff, datafile, loadObjCrystCrystal from diffpy.srreal.pdfcalculator import PDFCalculator -from testutils import datafile, loadObjCrystCrystal, _maxNormDiff # helper functions @@ -58,6 +58,7 @@ def _makePDFCalculator(crst, cfgdict): # ---------------------------------------------------------------------------- + class TestPDFCalcObjcryst(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/test_pdfcalculator.py b/tests/test_pdfcalculator.py index a27e84d9..ef45a6ba 100644 --- a/tests/test_pdfcalculator.py +++ b/tests/test_pdfcalculator.py @@ -7,9 +7,9 @@ import unittest import numpy +from testutils import _maxNormDiff, datafile, loadDiffPyStructure, pickle_with_attr from diffpy.srreal.pdfcalculator import PDFCalculator, fftftog, fftgtof -from testutils import datafile, loadDiffPyStructure, pickle_with_attr, _maxNormDiff # helper functions diff --git a/tests/test_pdfenvelope.py b/tests/test_pdfenvelope.py index f6493f2b..7ea75f4c 100644 --- a/tests/test_pdfenvelope.py +++ b/tests/test_pdfenvelope.py @@ -7,6 +7,7 @@ import unittest import numpy +from testutils import pickle_with_attr from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator from diffpy.srreal.pdfenvelope import ( @@ -17,7 +18,6 @@ StepCutEnvelope, makePDFEnvelope, ) -from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/test_peakprofile.py b/tests/test_peakprofile.py index 8676afdb..9b739c19 100644 --- a/tests/test_peakprofile.py +++ b/tests/test_peakprofile.py @@ -7,10 +7,10 @@ import unittest import numpy +from testutils import mod_structure, pickle_with_attr from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.peakprofile import PeakProfile -from testutils import mod_structure, pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/test_peakwidthmodel.py b/tests/test_peakwidthmodel.py index 6b8e25a0..6c83cd15 100644 --- a/tests/test_peakwidthmodel.py +++ b/tests/test_peakwidthmodel.py @@ -7,10 +7,11 @@ import pickle import unittest +from testutils import loadDiffPyStructure + from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator from diffpy.srreal.peakwidthmodel import DebyeWallerPeakWidth, JeongPeakWidth, PeakWidthModel from diffpy.srreal.structureadapter import createStructureAdapter -from testutils import loadDiffPyStructure # ---------------------------------------------------------------------------- diff --git a/tests/test_scatteringfactortable.py b/tests/test_scatteringfactortable.py index 48d1efe0..3d327ae8 100644 --- a/tests/test_scatteringfactortable.py +++ b/tests/test_scatteringfactortable.py @@ -7,6 +7,7 @@ import unittest import numpy +from testutils import pickle_with_attr from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator from diffpy.srreal.scatteringfactortable import ( @@ -16,7 +17,6 @@ SFTNeutron, SFTXray, ) -from testutils import pickle_with_attr # ---------------------------------------------------------------------------- diff --git a/tests/test_sfaverage.py b/tests/test_sfaverage.py index 78d39fd2..87dd9a15 100644 --- a/tests/test_sfaverage.py +++ b/tests/test_sfaverage.py @@ -4,16 +4,13 @@ import unittest -import pytest import numpy +import pytest +from testutils import loadDiffPyStructure, loadObjCrystCrystal from diffpy.srreal.scatteringfactortable import ScatteringFactorTable from diffpy.srreal.sfaverage import SFAverage -from testutils import ( - loadDiffPyStructure, - loadObjCrystCrystal, -) # ---------------------------------------------------------------------------- @@ -76,6 +73,7 @@ def test_fromComposition(self): # ---------------------------------------------------------------------------- + class TestSFAverageObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/test_structureadapter.py b/tests/test_structureadapter.py index 6cd69a36..697c355c 100644 --- a/tests/test_structureadapter.py +++ b/tests/test_structureadapter.py @@ -5,9 +5,18 @@ import pickle import unittest -import pytest import numpy +import pytest +from testutils import ( + DerivedAtomicStructureAdapter, + DerivedCrystalStructureAdapter, + DerivedPeriodicStructureAdapter, + DerivedStructureAdapter, + loadCrystalStructureAdapter, + loadDiffPyStructure, + loadObjCrystCrystal, +) from diffpy.srreal.pdfcalculator import PDFCalculator from diffpy.srreal.structureadapter import ( @@ -20,15 +29,6 @@ nometa, nosymmetry, ) -from testutils import ( - loadCrystalStructureAdapter, - loadDiffPyStructure, - loadObjCrystCrystal, - DerivedStructureAdapter, - DerivedAtomicStructureAdapter, - DerivedPeriodicStructureAdapter, - DerivedCrystalStructureAdapter -) # ---------------------------------------------------------------------------- @@ -269,6 +269,7 @@ def test_nosymmetry_pickling(self): # ---------------------------------------------------------------------------- + class TestPyObjCrystAdapter(unittest.TestCase): @pytest.fixture(autouse=True) diff --git a/tests/testutils.py b/tests/testutils.py index d68dd99c..5f594af7 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -8,16 +8,15 @@ import numpy +import diffpy.structure as mod_structure from diffpy.srreal.structureadapter import ( AtomicStructureAdapter, CrystalStructureAdapter, PeriodicStructureAdapter, StructureAdapter, ) -import diffpy.structure as mod_structure from diffpy.structure.parsers import getParser - # helper functions @@ -73,6 +72,7 @@ def _maxNormDiff(yobs, ycalc): rv = max(numpy.fabs(ynmdiff)) return rv + # helper class for testing overloading of StructureAdapter From 0ce4864698f77bb77fa563e33c48dcfaa4bb5464 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sat, 11 Jan 2025 05:00:17 -0500 Subject: [PATCH 7/7] pcmt --- tests/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 273cc36f..ac3c2227 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ import pytest -import diffpy.structure as mod_structure from diffpy.srreal.structureconverters import convertObjCrystCrystal