From c44895208c1a7ab0611d26f8f83ae4280ab528cb Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:54:39 -0400 Subject: [PATCH 01/10] Remove test testutils func --- src/diffpy/structure/tests/testutils.py | 25 ------------------- .../structure/tests => tests}/__init__.py | 0 .../structure/tests => tests}/conftest.py | 0 .../diffpy/structure/tests => tests}/debug.py | 0 {src/diffpy/structure/tests => tests}/run.py | 0 .../structure/tests => tests}/test_atom.py | 0 .../structure/tests => tests}/test_lattice.py | 0 .../tests => tests}/test_loadstructure.py | 0 .../tests => tests}/test_oldimports.py | 0 .../structure/tests => tests}/test_p_cif.py | 0 .../tests => tests}/test_p_discus.py | 0 .../tests => tests}/test_p_pdffit.py | 0 .../structure/tests => tests}/test_parsers.py | 0 .../tests => tests}/test_spacegroups.py | 0 .../tests => tests}/test_structure.py | 0 .../tests => tests}/test_supercell.py | 0 .../tests => tests}/test_symmetryutilities.py | 0 .../testdata/BubbleRaftShort.xcfg | 0 .../tests => tests}/testdata/CdSe_bulk.stru | 0 .../tests => tests}/testdata/LiCl-bad.cif | 0 .../tests => tests}/testdata/Ni-bad.stru | 0 .../tests => tests}/testdata/Ni-discus.stru | 0 .../tests => tests}/testdata/Ni.stru | 0 .../tests => tests}/testdata/Ni_prim123.stru | 0 .../tests => tests}/testdata/Ni_ref.cif | 0 .../tests => tests}/testdata/PbTe.cif | 0 .../tests => tests}/testdata/TeI-unkocc.cif | 0 .../tests => tests}/testdata/TeI.cif | 0 .../testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr | 0 .../tests => tests}/testdata/arginine.pdb | 0 .../testdata/badspacegroup.cif | 0 .../tests => tests}/testdata/bucky-bad1.xyz | 0 .../tests => tests}/testdata/bucky-bad2.xyz | 0 .../testdata/bucky-plain-bad.xyz | 0 .../tests => tests}/testdata/bucky-plain.xyz | 0 .../tests => tests}/testdata/bucky-raw.xyz | 0 .../tests => tests}/testdata/bucky.xyz | 0 .../testdata/curlybrackets.cif | 0 .../tests => tests}/testdata/customsg.cif | 0 .../tests => tests}/testdata/graphite.cif | 0 .../testdata/hexagon-raw-bad.xyz | 0 .../tests => tests}/testdata/hexagon-raw.xy | 0 .../tests => tests}/testdata/hexagon-raw.xyz | 0 .../tests => tests}/testdata/nosites.cif | 0 44 files changed, 25 deletions(-) delete mode 100644 src/diffpy/structure/tests/testutils.py rename {src/diffpy/structure/tests => tests}/__init__.py (100%) rename {src/diffpy/structure/tests => tests}/conftest.py (100%) rename {src/diffpy/structure/tests => tests}/debug.py (100%) rename {src/diffpy/structure/tests => tests}/run.py (100%) rename {src/diffpy/structure/tests => tests}/test_atom.py (100%) rename {src/diffpy/structure/tests => tests}/test_lattice.py (100%) rename {src/diffpy/structure/tests => tests}/test_loadstructure.py (100%) rename {src/diffpy/structure/tests => tests}/test_oldimports.py (100%) rename {src/diffpy/structure/tests => tests}/test_p_cif.py (100%) rename {src/diffpy/structure/tests => tests}/test_p_discus.py (100%) rename {src/diffpy/structure/tests => tests}/test_p_pdffit.py (100%) rename {src/diffpy/structure/tests => tests}/test_parsers.py (100%) rename {src/diffpy/structure/tests => tests}/test_spacegroups.py (100%) rename {src/diffpy/structure/tests => tests}/test_structure.py (100%) rename {src/diffpy/structure/tests => tests}/test_supercell.py (100%) rename {src/diffpy/structure/tests => tests}/test_symmetryutilities.py (100%) rename {src/diffpy/structure/tests => tests}/testdata/BubbleRaftShort.xcfg (100%) rename {src/diffpy/structure/tests => tests}/testdata/CdSe_bulk.stru (100%) rename {src/diffpy/structure/tests => tests}/testdata/LiCl-bad.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/Ni-bad.stru (100%) rename {src/diffpy/structure/tests => tests}/testdata/Ni-discus.stru (100%) rename {src/diffpy/structure/tests => tests}/testdata/Ni.stru (100%) rename {src/diffpy/structure/tests => tests}/testdata/Ni_prim123.stru (100%) rename {src/diffpy/structure/tests => tests}/testdata/Ni_ref.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/PbTe.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/TeI-unkocc.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/TeI.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr (100%) rename {src/diffpy/structure/tests => tests}/testdata/arginine.pdb (100%) rename {src/diffpy/structure/tests => tests}/testdata/badspacegroup.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky-bad1.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky-bad2.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky-plain-bad.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky-plain.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky-raw.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/bucky.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/curlybrackets.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/customsg.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/graphite.cif (100%) rename {src/diffpy/structure/tests => tests}/testdata/hexagon-raw-bad.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/hexagon-raw.xy (100%) rename {src/diffpy/structure/tests => tests}/testdata/hexagon-raw.xyz (100%) rename {src/diffpy/structure/tests => tests}/testdata/nosites.cif (100%) diff --git a/src/diffpy/structure/tests/testutils.py b/src/diffpy/structure/tests/testutils.py deleted file mode 100644 index 461f020d..00000000 --- a/src/diffpy/structure/tests/testutils.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.structure by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2010 Trustees of the 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. -# -############################################################################## - -"""Helper routines for running other unit tests. -""" - -# helper functions - -from importlib import resources - - -def datafile(filename): - return str(resources.files(__package__).joinpath("testdata/" + filename)) diff --git a/src/diffpy/structure/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/diffpy/structure/tests/__init__.py rename to tests/__init__.py diff --git a/src/diffpy/structure/tests/conftest.py b/tests/conftest.py similarity index 100% rename from src/diffpy/structure/tests/conftest.py rename to tests/conftest.py diff --git a/src/diffpy/structure/tests/debug.py b/tests/debug.py similarity index 100% rename from src/diffpy/structure/tests/debug.py rename to tests/debug.py diff --git a/src/diffpy/structure/tests/run.py b/tests/run.py similarity index 100% rename from src/diffpy/structure/tests/run.py rename to tests/run.py diff --git a/src/diffpy/structure/tests/test_atom.py b/tests/test_atom.py similarity index 100% rename from src/diffpy/structure/tests/test_atom.py rename to tests/test_atom.py diff --git a/src/diffpy/structure/tests/test_lattice.py b/tests/test_lattice.py similarity index 100% rename from src/diffpy/structure/tests/test_lattice.py rename to tests/test_lattice.py diff --git a/src/diffpy/structure/tests/test_loadstructure.py b/tests/test_loadstructure.py similarity index 100% rename from src/diffpy/structure/tests/test_loadstructure.py rename to tests/test_loadstructure.py diff --git a/src/diffpy/structure/tests/test_oldimports.py b/tests/test_oldimports.py similarity index 100% rename from src/diffpy/structure/tests/test_oldimports.py rename to tests/test_oldimports.py diff --git a/src/diffpy/structure/tests/test_p_cif.py b/tests/test_p_cif.py similarity index 100% rename from src/diffpy/structure/tests/test_p_cif.py rename to tests/test_p_cif.py diff --git a/src/diffpy/structure/tests/test_p_discus.py b/tests/test_p_discus.py similarity index 100% rename from src/diffpy/structure/tests/test_p_discus.py rename to tests/test_p_discus.py diff --git a/src/diffpy/structure/tests/test_p_pdffit.py b/tests/test_p_pdffit.py similarity index 100% rename from src/diffpy/structure/tests/test_p_pdffit.py rename to tests/test_p_pdffit.py diff --git a/src/diffpy/structure/tests/test_parsers.py b/tests/test_parsers.py similarity index 100% rename from src/diffpy/structure/tests/test_parsers.py rename to tests/test_parsers.py diff --git a/src/diffpy/structure/tests/test_spacegroups.py b/tests/test_spacegroups.py similarity index 100% rename from src/diffpy/structure/tests/test_spacegroups.py rename to tests/test_spacegroups.py diff --git a/src/diffpy/structure/tests/test_structure.py b/tests/test_structure.py similarity index 100% rename from src/diffpy/structure/tests/test_structure.py rename to tests/test_structure.py diff --git a/src/diffpy/structure/tests/test_supercell.py b/tests/test_supercell.py similarity index 100% rename from src/diffpy/structure/tests/test_supercell.py rename to tests/test_supercell.py diff --git a/src/diffpy/structure/tests/test_symmetryutilities.py b/tests/test_symmetryutilities.py similarity index 100% rename from src/diffpy/structure/tests/test_symmetryutilities.py rename to tests/test_symmetryutilities.py diff --git a/src/diffpy/structure/tests/testdata/BubbleRaftShort.xcfg b/tests/testdata/BubbleRaftShort.xcfg similarity index 100% rename from src/diffpy/structure/tests/testdata/BubbleRaftShort.xcfg rename to tests/testdata/BubbleRaftShort.xcfg diff --git a/src/diffpy/structure/tests/testdata/CdSe_bulk.stru b/tests/testdata/CdSe_bulk.stru similarity index 100% rename from src/diffpy/structure/tests/testdata/CdSe_bulk.stru rename to tests/testdata/CdSe_bulk.stru diff --git a/src/diffpy/structure/tests/testdata/LiCl-bad.cif b/tests/testdata/LiCl-bad.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/LiCl-bad.cif rename to tests/testdata/LiCl-bad.cif diff --git a/src/diffpy/structure/tests/testdata/Ni-bad.stru b/tests/testdata/Ni-bad.stru similarity index 100% rename from src/diffpy/structure/tests/testdata/Ni-bad.stru rename to tests/testdata/Ni-bad.stru diff --git a/src/diffpy/structure/tests/testdata/Ni-discus.stru b/tests/testdata/Ni-discus.stru similarity index 100% rename from src/diffpy/structure/tests/testdata/Ni-discus.stru rename to tests/testdata/Ni-discus.stru diff --git a/src/diffpy/structure/tests/testdata/Ni.stru b/tests/testdata/Ni.stru similarity index 100% rename from src/diffpy/structure/tests/testdata/Ni.stru rename to tests/testdata/Ni.stru diff --git a/src/diffpy/structure/tests/testdata/Ni_prim123.stru b/tests/testdata/Ni_prim123.stru similarity index 100% rename from src/diffpy/structure/tests/testdata/Ni_prim123.stru rename to tests/testdata/Ni_prim123.stru diff --git a/src/diffpy/structure/tests/testdata/Ni_ref.cif b/tests/testdata/Ni_ref.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/Ni_ref.cif rename to tests/testdata/Ni_ref.cif diff --git a/src/diffpy/structure/tests/testdata/PbTe.cif b/tests/testdata/PbTe.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/PbTe.cif rename to tests/testdata/PbTe.cif diff --git a/src/diffpy/structure/tests/testdata/TeI-unkocc.cif b/tests/testdata/TeI-unkocc.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/TeI-unkocc.cif rename to tests/testdata/TeI-unkocc.cif diff --git a/src/diffpy/structure/tests/testdata/TeI.cif b/tests/testdata/TeI.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/TeI.cif rename to tests/testdata/TeI.cif diff --git a/src/diffpy/structure/tests/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr b/tests/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr similarity index 100% rename from src/diffpy/structure/tests/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr rename to tests/testdata/ZnSb_RT_Q28X_VM_20_fxiso.rstr diff --git a/src/diffpy/structure/tests/testdata/arginine.pdb b/tests/testdata/arginine.pdb similarity index 100% rename from src/diffpy/structure/tests/testdata/arginine.pdb rename to tests/testdata/arginine.pdb diff --git a/src/diffpy/structure/tests/testdata/badspacegroup.cif b/tests/testdata/badspacegroup.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/badspacegroup.cif rename to tests/testdata/badspacegroup.cif diff --git a/src/diffpy/structure/tests/testdata/bucky-bad1.xyz b/tests/testdata/bucky-bad1.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky-bad1.xyz rename to tests/testdata/bucky-bad1.xyz diff --git a/src/diffpy/structure/tests/testdata/bucky-bad2.xyz b/tests/testdata/bucky-bad2.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky-bad2.xyz rename to tests/testdata/bucky-bad2.xyz diff --git a/src/diffpy/structure/tests/testdata/bucky-plain-bad.xyz b/tests/testdata/bucky-plain-bad.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky-plain-bad.xyz rename to tests/testdata/bucky-plain-bad.xyz diff --git a/src/diffpy/structure/tests/testdata/bucky-plain.xyz b/tests/testdata/bucky-plain.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky-plain.xyz rename to tests/testdata/bucky-plain.xyz diff --git a/src/diffpy/structure/tests/testdata/bucky-raw.xyz b/tests/testdata/bucky-raw.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky-raw.xyz rename to tests/testdata/bucky-raw.xyz diff --git a/src/diffpy/structure/tests/testdata/bucky.xyz b/tests/testdata/bucky.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/bucky.xyz rename to tests/testdata/bucky.xyz diff --git a/src/diffpy/structure/tests/testdata/curlybrackets.cif b/tests/testdata/curlybrackets.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/curlybrackets.cif rename to tests/testdata/curlybrackets.cif diff --git a/src/diffpy/structure/tests/testdata/customsg.cif b/tests/testdata/customsg.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/customsg.cif rename to tests/testdata/customsg.cif diff --git a/src/diffpy/structure/tests/testdata/graphite.cif b/tests/testdata/graphite.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/graphite.cif rename to tests/testdata/graphite.cif diff --git a/src/diffpy/structure/tests/testdata/hexagon-raw-bad.xyz b/tests/testdata/hexagon-raw-bad.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/hexagon-raw-bad.xyz rename to tests/testdata/hexagon-raw-bad.xyz diff --git a/src/diffpy/structure/tests/testdata/hexagon-raw.xy b/tests/testdata/hexagon-raw.xy similarity index 100% rename from src/diffpy/structure/tests/testdata/hexagon-raw.xy rename to tests/testdata/hexagon-raw.xy diff --git a/src/diffpy/structure/tests/testdata/hexagon-raw.xyz b/tests/testdata/hexagon-raw.xyz similarity index 100% rename from src/diffpy/structure/tests/testdata/hexagon-raw.xyz rename to tests/testdata/hexagon-raw.xyz diff --git a/src/diffpy/structure/tests/testdata/nosites.cif b/tests/testdata/nosites.cif similarity index 100% rename from src/diffpy/structure/tests/testdata/nosites.cif rename to tests/testdata/nosites.cif From 1e0dca9234a865e97bd972faa6a6799beb8a1b6f Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:55:08 -0400 Subject: [PATCH 02/10] Remove exclude for diffpy.structrue.tests in pyproject --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0b37965c..66fb7f89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ dirty_template = "{tag}" [tool.setuptools.packages.find] where = ["src"] # list of folders that contain the packages (["."] by default) include = ["*"] # package names should match these glob patterns (["*"] by default) -exclude = ["diffpy.structure.tests*"] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) [tool.setuptools.dynamic] From cf8597b7c4f5c1fe99c00f7d1fd5581c4e1260cd Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:55:35 -0400 Subject: [PATCH 03/10] Remove unittest funcs --- tests/debug.py | 35 ----------------------------------- tests/run.py | 36 ------------------------------------ 2 files changed, 71 deletions(-) delete mode 100644 tests/debug.py delete mode 100644 tests/run.py diff --git a/tests/debug.py b/tests/debug.py deleted file mode 100644 index 36d78c9e..00000000 --- a/tests/debug.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# (c) 2024 The Trustees of Columbia University in the City of New York. -# All rights reserved. -# -# File coded by: Billinge Group members and community contributors. -# -# See GitHub contributions for a more detailed list of contributors. -# https://github.com/diffpy/diffpy.structure/graphs/contributors -# -# See LICENSE.rst for license information. -# -############################################################################## - -""" -Convenience module for debugging the unit tests using - -python -m diffpy.structure.tests.debug - -Exceptions raised by failed tests or other errors are not caught. -""" - - -if __name__ == "__main__": - import sys - - from diffpy.structure.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 4b9b58ee..00000000 --- a/tests/run.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.structure by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2010 Trustees of the 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.structure.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.structure.tests import test - - # produce zero exit code for a successful test - sys.exit(not test().wasSuccessful()) From 40a42f54355e1e192a3bb10afc0047bd1e49b0b6 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:55:53 -0400 Subject: [PATCH 04/10] Include datafile util func in conftest --- tests/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index e3b63139..ff8aad16 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import json +from importlib import resources from pathlib import Path import pytest @@ -17,3 +18,17 @@ def user_filesystem(tmp_path): json.dump(home_config_data, f) yield tmp_path + + +def get_datafile(filename): + return str(resources.files(__package__).joinpath("testdata/" + filename)) + + +@pytest.fixture +def datafile(): + """Fixture to dynamically load any test file.""" + + def _load(filename): + return get_datafile(filename) + + return _load From 9f5525e9c751a65ad05d3ef7e8534e5c26e7501f Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:56:11 -0400 Subject: [PATCH 05/10] Apply pytest fixtures in unnitest classes --- tests/test_loadstructure.py | 18 +++--- tests/test_p_cif.py | 30 +++++----- tests/test_p_discus.py | 21 ++++--- tests/test_p_pdffit.py | 32 ++++++----- tests/test_parsers.py | 48 ++++++++++------ tests/test_structure.py | 106 +++++++++++++++++------------------- tests/test_supercell.py | 11 ++-- 7 files changed, 148 insertions(+), 118 deletions(-) diff --git a/tests/test_loadstructure.py b/tests/test_loadstructure.py index 92bd4c7f..4f099c7d 100644 --- a/tests/test_loadstructure.py +++ b/tests/test_loadstructure.py @@ -5,17 +5,21 @@ import unittest +import pytest + from diffpy.structure import PDFFitStructure, Structure, loadStructure from diffpy.structure.structureerrors import StructureFormatError -from diffpy.structure.tests.testutils import datafile ############################################################################## class TestLoadStructure(unittest.TestCase): + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile def test_xcfg(self): """check loading of atomeye xcfg format""" - f = datafile("BubbleRaftShort.xcfg") + f = self.datafile("BubbleRaftShort.xcfg") stru = loadStructure(f) self.assertTrue(type(stru) is Structure) self.assertRaises(StructureFormatError, loadStructure, f, "xyz") @@ -23,14 +27,14 @@ def test_xcfg(self): def test_discus(self): """check loading of discus file format""" - f = datafile("Ni-discus.stru") + f = self.datafile("Ni-discus.stru") stru = loadStructure(f) self.assertTrue(type(stru) is PDFFitStructure) return def test_cif(self): """check loading of CIF file format""" - f = datafile("PbTe.cif") + f = self.datafile("PbTe.cif") stru = loadStructure(f) self.assertTrue(isinstance(stru, Structure)) self.assertFalse(isinstance(stru, PDFFitStructure)) @@ -38,20 +42,20 @@ def test_cif(self): def test_badfile(self): """check loading of CIF file format""" - f = datafile("Ni-bad.stru") + f = self.datafile("Ni-bad.stru") self.assertRaises(StructureFormatError, loadStructure, f) return def test_goodkwarg(self): """check loading of CIF file and passing of parser keyword argument.""" - f = datafile("graphite.cif") + f = self.datafile("graphite.cif") stru = loadStructure(f, eps=1e-10) self.assertEqual(8, len(stru)) return def test_badkwarg(self): """check loading of xyz file format with invalid keyword argument""" - f = datafile("bucky.xyz") + f = self.datafile("bucky.xyz") self.assertRaises(TypeError, loadStructure, f, eps=1e-10) return diff --git a/tests/test_p_cif.py b/tests/test_p_cif.py index edd611f6..62bb25db 100644 --- a/tests/test_p_cif.py +++ b/tests/test_p_cif.py @@ -19,12 +19,12 @@ import unittest import numpy +import pytest from diffpy.structure import Structure from diffpy.structure.parsers import getParser from diffpy.structure.parsers.p_cif import P_cif, getSymOp, leading_float from diffpy.structure.structureerrors import StructureFormatError -from diffpy.structure.tests.testutils import datafile # ---------------------------------------------------------------------------- @@ -65,14 +65,16 @@ def test_getSymOp(self): class TestP_cif(unittest.TestCase): - - pbteciffile = datafile("PbTe.cif") - badciffile = datafile("LiCl-bad.cif") - graphiteciffile = datafile("graphite.cif") - cdsebulkpdffitfile = datafile("CdSe_bulk.stru") - teiciffile = datafile("TeI.cif") - refciffile = datafile("Ni_ref.cif") - places = 6 + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + self.pbteciffile = datafile("PbTe.cif") + self.badciffile = datafile("LiCl-bad.cif") + self.graphiteciffile = datafile("graphite.cif") + self.cdsebulkpdffitfile = datafile("CdSe_bulk.stru") + self.teiciffile = datafile("TeI.cif") + self.refciffile = datafile("Ni_ref.cif") + self.places = 6 def setUp(self): self.ptest = P_cif() @@ -240,7 +242,7 @@ def test_eps(self): def test_unknown_occupancy(self): "test CIF file with unknown occupancy data" - stru = self.ptest.parseFile(datafile("TeI-unkocc.cif")) + stru = self.ptest.parseFile(self.datafile("TeI-unkocc.cif")) self.assertTrue(numpy.array_equal(16 * [1], stru.occupancy)) return @@ -268,7 +270,7 @@ def test_unknown_spacegroup_number(self): def test_nosites_cif(self): """Test reading of CIF file with no valid sites.""" ptest = self.ptest - stru = ptest.parseFile(datafile("nosites.cif")) + stru = ptest.parseFile(self.datafile("nosites.cif")) self.assertEqual(0, len(stru)) self.assertEqual(10.413, stru.lattice.a) self.assertEqual(10.413, stru.lattice.b) @@ -278,14 +280,14 @@ def test_nosites_cif(self): def test_badspacegroup_cif(self): """Test reading of CIF file with unrecognized space group.""" ptest = self.ptest - filename = datafile("badspacegroup.cif") + filename = self.datafile("badspacegroup.cif") self.assertRaises(StructureFormatError, ptest.parseFile, filename) return def test_custom_spacegroup_cif(self): """Test parsing of nonstandard symops-defined space group.""" pfile = self.pfile - filename = datafile("customsg.cif") + filename = self.datafile("customsg.cif") pfile.parseFile(filename) sg = pfile.spacegroup self.assertEqual("CIF data", sg.short_name) @@ -363,7 +365,7 @@ def test_unknown_aniso(self): def test_curly_brace(self): "verify loading of a CIF file with unquoted curly brace" ptest = self.ptest - stru = ptest.parseFile(datafile("curlybrackets.cif")) + stru = ptest.parseFile(self.datafile("curlybrackets.cif")) self.assertEqual(20, len(stru)) return diff --git a/tests/test_p_discus.py b/tests/test_p_discus.py index 43c44ea5..8959718e 100644 --- a/tests/test_p_discus.py +++ b/tests/test_p_discus.py @@ -19,9 +19,10 @@ import re import unittest +import pytest + from diffpy.structure import Structure from diffpy.structure.parsers import StructureFormatError -from diffpy.structure.tests.testutils import datafile # ---------------------------------------------------------------------------- @@ -29,6 +30,10 @@ class TestP_discus(unittest.TestCase): """test Parser for PDFFit file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "discus" @@ -37,7 +42,7 @@ def setUp(self): def test_read_discus_Ni(self): """check reading of Ni structure in discus format""" stru = self.stru - stru.read(datafile("Ni-discus.stru"), self.format) + stru.read(self.datafile("Ni-discus.stru"), self.format) f_title = "structure Ni FCC" self.assertEqual(f_title, stru.title) self.assertEqual("Fm-3m", stru.pdffit["spcgr"]) @@ -75,7 +80,7 @@ def test_except_other_formats(self): "hexagon-raw.xyz", ] for ft in badfiles: - ff = datafile(ft) + ff = self.datafile(ft) self.assertRaises(StructureFormatError, self.stru.read, ff, format=self.format) return @@ -83,7 +88,7 @@ def test_ignored_lines(self): """check skipping of ignored lines in the header""" r1 = "ignored record 1\n" r2 = "ignored record 2\n" - with open(datafile("Ni-discus.stru")) as fp: + with open(self.datafile("Ni-discus.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(2, r1) ni_lines.insert(4, r2) @@ -98,7 +103,7 @@ def test_ignored_lines(self): def test_spdiameter_parsing(self): """check parsing of spdiameter record from a file.""" stru = self.stru - stru.read(datafile("Ni-discus.stru"), self.format) + stru.read(self.datafile("Ni-discus.stru"), self.format) self.assertEqual(0, stru.pdffit["spdiameter"]) snoshape = stru.writeStr(format=self.format) self.assertTrue(not re.search("(?m)^shape", snoshape)) @@ -109,7 +114,7 @@ def test_spdiameter_parsing(self): stru13 = Structure() stru13.readStr(s13) self.assertEqual(13, stru13.pdffit["spdiameter"]) - with open(datafile("Ni.stru")) as fp: + with open(self.datafile("Ni.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(3, "shape invalid, 7\n") sbad = "".join(ni_lines) @@ -119,7 +124,7 @@ def test_spdiameter_parsing(self): def test_stepcut_parsing(self): """check parsing of stepcut record from a file.""" stru = self.stru - stru.read(datafile("Ni-discus.stru"), self.format) + stru.read(self.datafile("Ni-discus.stru"), self.format) self.assertEqual(0, stru.pdffit["stepcut"]) snoshape = stru.writeStr(format=self.format) self.assertTrue(not re.search("(?m)^shape", snoshape)) @@ -130,7 +135,7 @@ def test_stepcut_parsing(self): stru13 = Structure() stru13.readStr(s13) self.assertEqual(13, stru13.pdffit["stepcut"]) - with open(datafile("Ni.stru")) as fp: + with open(self.datafile("Ni.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(3, "shape invalid, 7\n") sbad = "".join(ni_lines) diff --git a/tests/test_p_pdffit.py b/tests/test_p_pdffit.py index 586ca413..f993cb4b 100644 --- a/tests/test_p_pdffit.py +++ b/tests/test_p_pdffit.py @@ -20,10 +20,10 @@ import unittest import numpy +import pytest from diffpy.structure import Structure from diffpy.structure.structureerrors import StructureFormatError -from diffpy.structure.tests.testutils import datafile # ---------------------------------------------------------------------------- @@ -31,6 +31,10 @@ class TestP_pdffit(unittest.TestCase): """test Parser for PDFFit file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "pdffit" @@ -39,7 +43,7 @@ def setUp(self): def test_read_pdffit_ZnSb(self): """check reading of ZnSb pdffit structure file""" stru = self.stru - stru.read(datafile("ZnSb_RT_Q28X_VM_20_fxiso.rstr"), self.format) + stru.read(self.datafile("ZnSb_RT_Q28X_VM_20_fxiso.rstr"), self.format) f_title = "Cell structure file of Zn4Sb3 #167 interstitial" self.assertEqual(stru.title, f_title) self.assertAlmostEqual(stru.pdffit["scale"], 0.826145) @@ -84,7 +88,7 @@ def test_read_pdffit_ZnSb(self): def test_read_pdffit_Ni(self): """check reading of Ni pdffit structure file""" stru = self.stru - stru.read(datafile("Ni.stru"), self.format) + stru.read(self.datafile("Ni.stru"), self.format) f_title = "structure Ni FCC" self.assertEqual(stru.title, f_title) self.assertEqual(stru.pdffit["spcgr"], "Fm-3m") @@ -117,7 +121,7 @@ def test_read_pdffit_Ni(self): def test_read_pdffit_Ni_prim123(self): """check reading of Ni_prim supercell 1x2x3""" stru = self.stru - stru.read(datafile("Ni_prim123.stru"), self.format) + stru.read(self.datafile("Ni_prim123.stru"), self.format) s_lat = [ stru.lattice.a, stru.lattice.b, @@ -148,15 +152,15 @@ def test_read_pdffit_Ni_prim123(self): def test_read_pdffit_bad(self): """check exceptions when reading invalid pdffit file""" stru = self.stru - self.assertRaises(StructureFormatError, stru.read, datafile("Ni-bad.stru"), self.format) - self.assertRaises(StructureFormatError, stru.read, datafile("bucky.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("Ni-bad.stru"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("bucky.xyz"), self.format) return def test_writeStr_pdffit(self): """check writing of normal xyz file""" stru = self.stru - stru.read(datafile("Ni.stru"), self.format) - with open(datafile("Ni.stru")) as fp: + stru.read(self.datafile("Ni.stru"), self.format) + with open(self.datafile("Ni.stru")) as fp: f_s = fp.read() f_s = re.sub("[ \t]+", " ", f_s) f_s = re.sub("[ \t]+\n", "\n", f_s) @@ -167,7 +171,7 @@ def test_writeStr_pdffit(self): def test_huge_occupancy(self): """check structure with huge occupancy can be read.""" - self.stru.read(datafile("Ni.stru"), self.format) + self.stru.read(self.datafile("Ni.stru"), self.format) self.stru[0].occupancy = 16e16 s_s = self.stru.writeStr(self.format) stru1 = Structure() @@ -179,7 +183,7 @@ def test_ignored_lines(self): """check skipping of ignored lines in the header""" r1 = "ignored record 1" r2 = "ignored record 2" - with open(datafile("Ni.stru")) as fp: + with open(self.datafile("Ni.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(2, r1 + "\n") ni_lines.insert(4, r2 + "\n") @@ -194,7 +198,7 @@ def test_ignored_lines(self): def test_spdiameter_parsing(self): """check parsing of spdiameter record from a file.""" stru = self.stru - stru.read(datafile("Ni.stru"), self.format) + stru.read(self.datafile("Ni.stru"), self.format) self.assertEqual(0, stru.pdffit["spdiameter"]) snoshape = stru.writeStr(format=self.format) self.assertTrue(not re.search("(?m)^shape", snoshape)) @@ -205,7 +209,7 @@ def test_spdiameter_parsing(self): stru13 = Structure() stru13.readStr(s13) self.assertEqual(13, stru13.pdffit["spdiameter"]) - with open(datafile("Ni.stru")) as fp: + with open(self.datafile("Ni.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(3, "shape invalid, 7\n") sbad = "".join(ni_lines) @@ -215,7 +219,7 @@ def test_spdiameter_parsing(self): def test_stepcut_parsing(self): """check parsing of stepcut record from a file.""" stru = self.stru - stru.read(datafile("Ni.stru"), self.format) + stru.read(self.datafile("Ni.stru"), self.format) self.assertEqual(0, stru.pdffit["stepcut"]) snoshape = stru.writeStr(format=self.format) self.assertTrue(not re.search("(?m)^shape", snoshape)) @@ -226,7 +230,7 @@ def test_stepcut_parsing(self): stru13 = Structure() stru13.readStr(s13) self.assertEqual(13, stru13.pdffit["stepcut"]) - with open(datafile("Ni.stru")) as fp: + with open(self.datafile("Ni.stru")) as fp: ni_lines = fp.readlines() ni_lines.insert(3, "shape invalid, 7\n") sbad = "".join(ni_lines) diff --git a/tests/test_parsers.py b/tests/test_parsers.py index 91f0e085..a3f7f3c1 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -22,10 +22,10 @@ import unittest import numpy +import pytest from diffpy.structure import Atom, Lattice, Structure from diffpy.structure.structureerrors import StructureFormatError -from diffpy.structure.tests.testutils import datafile # ---------------------------------------------------------------------------- @@ -33,6 +33,10 @@ class TestP_xyz(unittest.TestCase): """test Parser for xyz file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "xyz" @@ -52,7 +56,7 @@ def mktmpfile(self): def test_read_xyz(self): """check reading of normal xyz file""" stru = self.stru - stru.read(datafile("bucky.xyz"), self.format) + stru.read(self.datafile("bucky.xyz"), self.format) s_els = [a.element for a in stru] self.assertEqual(stru.title, "bucky-ball") self.assertEqual(s_els, 60 * ["C"]) @@ -61,10 +65,10 @@ def test_read_xyz(self): def test_read_xyz_bad(self): """check exceptions when reading invalid xyz file""" stru = self.stru - self.assertRaises(StructureFormatError, stru.read, datafile("bucky-bad1.xyz"), self.format) - self.assertRaises(StructureFormatError, stru.read, datafile("bucky-bad2.xyz"), self.format) - self.assertRaises(StructureFormatError, stru.read, datafile("bucky-plain.xyz"), self.format) - self.assertRaises(StructureFormatError, stru.read, datafile("hexagon-raw.xy"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("bucky-bad1.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("bucky-bad2.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("bucky-plain.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("hexagon-raw.xy"), self.format) return def test_writeStr_xyz(self): @@ -103,6 +107,10 @@ def test_write_xyz(self): class TestP_rawxyz(unittest.TestCase): """test Parser for rawxyz file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "rawxyz" @@ -111,7 +119,7 @@ def setUp(self): def test_read_plainxyz(self): """check reading of a plain xyz file""" stru = self.stru - stru.read(datafile("bucky-plain.xyz"), self.format) + stru.read(self.datafile("bucky-plain.xyz"), self.format) s_els = [a.element for a in stru] self.assertEqual(stru.title, "bucky-plain") self.assertEqual(s_els, 60 * ["C"]) @@ -120,17 +128,17 @@ def test_read_plainxyz(self): def test_read_plainxyz_bad(self): """check exceptions when reading invalid plain xyz file""" stru = self.stru - self.assertRaises(StructureFormatError, stru.read, datafile("bucky-plain-bad.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("bucky-plain-bad.xyz"), self.format) return def test_read_rawxyz(self): """check reading of raw xyz file""" stru = self.stru - stru.read(datafile("bucky-raw.xyz"), self.format) + stru.read(self.datafile("bucky-raw.xyz"), self.format) s_els = [a.element for a in stru] self.assertEqual(stru.title, "bucky-raw") self.assertEqual(s_els, 60 * [""]) - stru.read(datafile("hexagon-raw.xyz"), self.format) + stru.read(self.datafile("hexagon-raw.xyz"), self.format) zs = [a.xyz[-1] for a in stru] self.assertEqual(zs, 6 * [0.0]) return @@ -138,8 +146,8 @@ def test_read_rawxyz(self): def test_read_rawxyz_bad(self): """check exceptions when reading unsupported xy file""" stru = self.stru - self.assertRaises(StructureFormatError, stru.read, datafile("hexagon-raw-bad.xyz"), self.format) - self.assertRaises(StructureFormatError, stru.read, datafile("hexagon-raw.xy"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("hexagon-raw-bad.xyz"), self.format) + self.assertRaises(StructureFormatError, stru.read, self.datafile("hexagon-raw.xy"), self.format) return def test_writeStr_rawxyz(self): @@ -168,6 +176,10 @@ def test_writeStr_rawxyz(self): class TestP_pdb(unittest.TestCase): """test Parser for PDB file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "pdb" @@ -176,7 +188,7 @@ def setUp(self): def test_read_pdb_arginine(self): """check reading of arginine PDB file""" stru = self.stru - stru.read(datafile("arginine.pdb"), self.format) + stru.read(self.datafile("arginine.pdb"), self.format) f_els = [ "N", "C", @@ -224,7 +236,7 @@ def test_read_pdb_arginine(self): def test_rwStr_pdb_CdSe(self): """check conversion to PDB file format""" stru = self.stru - stru.read(datafile("CdSe_bulk.stru"), "pdffit") + stru.read(self.datafile("CdSe_bulk.stru"), "pdffit") s = stru.writeStr(self.format) # all lines should be 80 characters long linelens = [len(line) for line in s.split("\n") if line != ""] @@ -265,6 +277,10 @@ def test_rwStr_pdb_CdSe(self): class TestP_xcfg(unittest.TestCase): """test Parser for XCFG file format""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile + def setUp(self): self.stru = Structure() self.format = "xcfg" @@ -273,7 +289,7 @@ def setUp(self): def test_read_xcfg(self): """check reading of BubbleRaft XCFG file""" stru = self.stru - stru.read(datafile("BubbleRaftShort.xcfg"), self.format) + stru.read(self.datafile("BubbleRaftShort.xcfg"), self.format) f_els = 500 * ["Ar"] s_els = [a.element for a in stru] self.assertEqual(s_els, f_els) @@ -293,7 +309,7 @@ def test_read_xcfg(self): def test_rwStr_xcfg_CdSe(self): """check conversion to XCFG file format""" stru = self.stru - stru.read(datafile("CdSe_bulk.stru"), "pdffit") + stru.read(self.datafile("CdSe_bulk.stru"), "pdffit") s = stru.writeStr(self.format) stru = Structure() stru.readStr(s, self.format) diff --git a/tests/test_structure.py b/tests/test_structure.py index 37f89a59..e9016e3f 100644 --- a/tests/test_structure.py +++ b/tests/test_structure.py @@ -22,14 +22,9 @@ import unittest import numpy +import pytest from diffpy.structure import Atom, Lattice, Structure -from diffpy.structure.tests.testutils import datafile - -# useful variables -cdsefile = datafile("CdSe_bulk.stru") -teifile = datafile("TeI.cif") -pbtefile = datafile("PbTe.cif") # ---------------------------------------------------------------------------- @@ -37,16 +32,24 @@ class TestStructure(unittest.TestCase): """test methods of Structure class""" + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.cdsefile = datafile("CdSe_bulk.stru") + self.teifile = datafile("TeI.cif") + self.pbtefile = datafile("PbTe.cif") + _loaded_structures = {} def setUp(self): self.stru = Structure([Atom("C", [0, 0, 0]), Atom("C", [1, 1, 1])], lattice=Lattice(1, 1, 1, 90, 90, 120)) + # useful variables + if not self._loaded_structures: self._loaded_structures.update( [ - ("cdse", Structure(filename=cdsefile)), - ("tei", Structure(filename=teifile)), - ("pbte", Structure(filename=pbtefile)), + ("cdse", Structure(filename=self.cdsefile)), + ("tei", Structure(filename=self.teifile)), + ("pbte", Structure(filename=self.pbtefile)), ] ) self.__dict__.update(self._loaded_structures) @@ -56,9 +59,9 @@ def setUp(self): def test___init__(self): """check Structure.__init__()""" atoms = [Atom("C", [0, 0, 0]), Atom("C", [0.5, 0.5, 0.5])] - self.assertRaises(ValueError, Structure, atoms, filename=teifile) - self.assertRaises(ValueError, Structure, lattice=Lattice(), filename=teifile) - self.assertRaises(ValueError, Structure, title="test", filename=teifile) + self.assertRaises(ValueError, Structure, atoms, filename=self.teifile) + self.assertRaises(ValueError, Structure, lattice=Lattice(), filename=self.teifile) + self.assertRaises(ValueError, Structure, title="test", filename=self.teifile) stru1 = Structure(title="my title") self.assertEqual("my title", stru1.title) stru2a = Structure(atoms) @@ -95,7 +98,7 @@ def __copy__(self): def test___copy__(self): """check Structure.__copy__()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) cdse_str = cdse.writeStr("pdffit") cdse2 = copy.copy(cdse) self.assertEqual(cdse_str, cdse2.writeStr("pdffit")) @@ -104,20 +107,17 @@ def test___copy__(self): self.assertFalse(sameatoms) return - # def test___str__(self): - # """check Structure.__str__() - # """ - # return - # - # def test_addNewAtom(self): - # """check Structure.addNewAtom() - # """ - # return - # - # def test_getLastAtom(self): - # """check Structure.getLastAtom() - # """ - # return + def test___str__(self): + """check Structure.__str__()""" + return + + def test_addNewAtom(self): + """check Structure.addNewAtom()""" + return + + def test_getLastAtom(self): + """check Structure.getLastAtom()""" + return def test_assignUniqueLabels(self): """check Structure.assignUniqueLabels()""" @@ -141,7 +141,7 @@ def test_distance(self): def test_angle(self): """check Structure.angle()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) cdse.assignUniqueLabels() self.assertEqual(109, round(cdse.angle(0, 2, 1))) self.assertEqual(109, round(cdse.angle("Cd1", "Se1", "Cd2"))) @@ -157,25 +157,21 @@ def test_placeInLattice(self): a1 = stru[1] self.assertTrue(numpy.allclose(a1.xyz, [2.0, 0.0, 2.0])) - # def test_read(self): - # """check Structure.read() - # """ - # return - # - # def test_readStr(self): - # """check Structure.readStr() - # """ - # return - # - # def test_write(self): - # """check Structure.write() - # """ - # return - # - # def test_writeStr(self): - # """check Structure.writeStr() - # """ - # return + def test_read(self): + """check Structure.read()""" + return + + def test_readStr(self): + """check Structure.readStr()""" + return + + def test_write(self): + """check Structure.write()""" + return + + def test_writeStr(self): + """check Structure.writeStr()""" + return def test_aslist(self): """check Structure.tolist()""" @@ -215,7 +211,7 @@ def test_insert(self): def test_extend(self): """check Structure.extend()""" stru = self.stru - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) lst = stru.tolist() stru.extend(cdse) self.assertEqual(6, len(stru)) @@ -289,7 +285,7 @@ def test___setitem__slice(self): def test___add__(self): """check Structure.__add__()""" stru = self.stru - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) total = stru + cdse self.assertEqual(6, len(total)) ta0 = total[0] @@ -307,7 +303,7 @@ def test___iadd__(self): stru = self.stru lat0 = stru.lattice lst = stru.tolist() - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) stru += cdse self.assertEqual(6, len(stru)) self.assertEqual(lst, stru[:2].tolist()) @@ -321,7 +317,7 @@ def test___iadd__(self): def test___sub__(self): """check Structure.__sub__()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) cadmiums = cdse - cdse[2:] self.assertEqual(2, len(cadmiums)) self.assertEqual("Cd", cadmiums[0].element) @@ -334,7 +330,7 @@ def test___sub__(self): def test___isub__(self): """check Structure.__isub__()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) lat = cdse.lattice lst = cdse.tolist() cdse -= cdse[2:] @@ -348,7 +344,7 @@ def test___isub__(self): def test___mul__(self): """check Structure.__mul__()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) self.assertEqual(12, len(set(3 * cdse))) self.assertEqual(12, len(set(cdse * 3))) cdsex3 = 3 * cdse @@ -361,7 +357,7 @@ def test___mul__(self): def test___imul__(self): """check Structure.__imul__()""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) lat = cdse.lattice els = cdse.element xyz = cdse.xyz @@ -466,7 +462,7 @@ def test_z(self): def test_label(self): """check Structure.label""" - cdse = Structure(filename=cdsefile) + cdse = Structure(filename=self.cdsefile) self.assertEqual(4 * [""], cdse.label.tolist()) cdse.assignUniqueLabels() self.assertEqual("Cd1 Cd2 Se1 Se2".split(), cdse.label.tolist()) diff --git a/tests/test_supercell.py b/tests/test_supercell.py index 2ca5d72e..0e840dfa 100644 --- a/tests/test_supercell.py +++ b/tests/test_supercell.py @@ -16,17 +16,20 @@ """Unit tests for supercell.py """ - import unittest +import pytest + from diffpy.structure import Structure from diffpy.structure.expansion import supercell -from diffpy.structure.tests.testutils import datafile # ---------------------------------------------------------------------------- class TestSuperCell(unittest.TestCase): + @pytest.fixture(autouse=True) + def prepare_fixture(self, datafile): + self.datafile = datafile stru_cdse = None stru_ni = None @@ -34,10 +37,10 @@ class TestSuperCell(unittest.TestCase): def setUp(self): # load test structures once if TestSuperCell.stru_cdse is None: - cdsefile = datafile("CdSe_bulk.stru") + cdsefile = self.datafile("CdSe_bulk.stru") TestSuperCell.stru_cdse = Structure(filename=cdsefile) if TestSuperCell.stru_ni is None: - nifile = datafile("Ni.stru") + nifile = self.datafile("Ni.stru") TestSuperCell.stru_ni = Structure(filename=nifile) # bring them to the instance self.stru_cdse = TestSuperCell.stru_cdse From 05e106c3a83632f4ee7ce667657d5e2ab6fad98d Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 15:58:34 -0400 Subject: [PATCH 06/10] Add commented tests back --- tests/test_structure.py | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_structure.py b/tests/test_structure.py index e9016e3f..9c1a6308 100644 --- a/tests/test_structure.py +++ b/tests/test_structure.py @@ -107,17 +107,17 @@ def test___copy__(self): self.assertFalse(sameatoms) return - def test___str__(self): - """check Structure.__str__()""" - return + # def test___str__(self): + # """check Structure.__str__()""" + # return - def test_addNewAtom(self): - """check Structure.addNewAtom()""" - return + # def test_addNewAtom(self): + # """check Structure.addNewAtom()""" + # return - def test_getLastAtom(self): - """check Structure.getLastAtom()""" - return + # def test_getLastAtom(self): + # """check Structure.getLastAtom()""" + # return def test_assignUniqueLabels(self): """check Structure.assignUniqueLabels()""" @@ -157,21 +157,21 @@ def test_placeInLattice(self): a1 = stru[1] self.assertTrue(numpy.allclose(a1.xyz, [2.0, 0.0, 2.0])) - def test_read(self): - """check Structure.read()""" - return + # def test_read(self): + # """check Structure.read()""" + # return - def test_readStr(self): - """check Structure.readStr()""" - return + # def test_readStr(self): + # """check Structure.readStr()""" + # return - def test_write(self): - """check Structure.write()""" - return + # def test_write(self): + # """check Structure.write()""" + # return - def test_writeStr(self): - """check Structure.writeStr()""" - return + # def test_writeStr(self): + # """check Structure.writeStr()""" + # return def test_aslist(self): """check Structure.tolist()""" From c80ecc55c15b187e4821f2f42e4fda6eb8005633 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Mon, 9 Sep 2024 16:08:59 -0400 Subject: [PATCH 07/10] Create folder.rst --- news/folder.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/folder.rst diff --git a/news/folder.rst b/news/folder.rst new file mode 100644 index 00000000..63f83284 --- /dev/null +++ b/news/folder.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* tests folder at the root of the repo + +**Security:** + +* From 2f8aace4eba92918cd6e39d4499501e62080dd13 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Thu, 12 Sep 2024 23:06:23 -0400 Subject: [PATCH 08/10] Delete tests/__init__.py --- tests/__init__.py | 77 ----------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 98485bde..00000000 --- a/tests/__init__.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.structure by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2010 Trustees of the 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.structure. -""" - -import unittest - - -def testsuite(pattern=""): - """Create a unit tests suite for diffpy.structure 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 importlib import resources - from itertools import chain - from os.path import dirname - - loader = unittest.defaultTestLoader - thisdir = str(resources.files(__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.structure package. - - Returns - ------- - result : `unittest.TestResult` - """ - suite = testsuite() - runner = unittest.TextTestRunner() - result = runner.run(suite) - return result From e4cf9f38197585a081f3277b50ac843148a607cb Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 13 Sep 2024 08:33:28 -0400 Subject: [PATCH 09/10] Fix contest not to use __init__.py content --- tests/conftest.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ff8aad16..5471acc1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import json -from importlib import resources from pathlib import Path import pytest @@ -20,15 +19,11 @@ def user_filesystem(tmp_path): yield tmp_path -def get_datafile(filename): - return str(resources.files(__package__).joinpath("testdata/" + filename)) - - @pytest.fixture def datafile(): """Fixture to dynamically load any test file.""" def _load(filename): - return get_datafile(filename) + return "tests/testdata/" + filename return _load From 8cfba3883b171ed661f0d79ca04b2dc91402407a Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 13 Sep 2024 20:09:52 -0400 Subject: [PATCH 10/10] Leave exclude tag but empty --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 66fb7f89..e50524b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ dirty_template = "{tag}" [tool.setuptools.packages.find] where = ["src"] # list of folders that contain the packages (["."] by default) include = ["*"] # package names should match these glob patterns (["*"] by default) +exclude = [] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) [tool.setuptools.dynamic]