diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml new file mode 100644 index 00000000..3402e468 --- /dev/null +++ b/.github/workflows/tests-on-pr.yml @@ -0,0 +1,16 @@ +name: Tests on PR + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + validate: + uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0 + with: + project: diffpy.srfit + c_extension: false + headless: false diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.txt similarity index 100% rename from conda-recipe/meta.yaml rename to conda-recipe/meta.txt diff --git a/conda-recipe/run_test.py b/conda-recipe/run_test.txt similarity index 100% rename from conda-recipe/run_test.py rename to conda-recipe/run_test.txt diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000..0e279fbf --- /dev/null +++ b/environment.yml @@ -0,0 +1,6 @@ +name: diffpy.srfit +channels: + - conda-forge +dependencies: + - python=3 + - pip diff --git a/pyproject.toml b/pyproject.toml index 339a1125..22663b7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,20 +1,58 @@ +[build-system] +requires = ["setuptools>=62.0", "setuptools-git-versioning>=2.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "diffpy.srfit" +dynamic=['version', 'dependencies'] +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Topic :: Scientific/Engineering :: Physics', + 'Topic :: Scientific/Engineering :: Chemistry', +] + + +[tool.setuptools-git-versioning] +enabled = true +template = "{tag}" +dev_template = "{tag}" +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] +dependencies = {file = ["requirements/run.txt"]} + [tool.black] line-length = 115 include = '\.pyi?$' exclude = ''' /( - \.git\ + \.git + | \.hg | \.mypy_cache | \.tox | \.venv - | _build/ + | \.rst + | \.txt + | _build | buck-out | build | dist + + # The following are specific to Black, you probably don't want those. | blib2to3 - | tests/data/ - | hooks/post_gen_project.py$ - | .*\.py$ - | .*\.toml$ + | tests/data )/ ''' diff --git a/requirements/pip.txt b/requirements/pip.txt new file mode 100644 index 00000000..e69de29b diff --git a/requirements/run.txt b/requirements/run.txt new file mode 100644 index 00000000..59149ac8 --- /dev/null +++ b/requirements/run.txt @@ -0,0 +1,3 @@ +scipy +numpy +matplotlib diff --git a/requirements/test.txt b/requirements/test.txt new file mode 100644 index 00000000..a7277865 --- /dev/null +++ b/requirements/test.txt @@ -0,0 +1,6 @@ +flake8 +pytest +codecov +coverage +pytest-cov +pytest-env diff --git a/setup.py b/setup.txt similarity index 100% rename from setup.py rename to setup.txt diff --git a/src/diffpy/srfit/.DS_Store b/src/diffpy/srfit/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/src/diffpy/srfit/.DS_Store differ diff --git a/src/diffpy/srfit/tests/__init__.py b/src/diffpy/srfit/tests/__init__.py deleted file mode 100644 index 81caf417..00000000 --- a/src/diffpy/srfit/tests/__init__.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srfit 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. -# -############################################################################## - -"""Unit tests for diffpy.srfit. -""" - -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.srfit 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.srfit package. - - Returns - ------- - result : `unittest.TestResult` - """ - suite = testsuite() - runner = unittest.TextTestRunner() - result = runner.run(suite) - return result - - -# End of file diff --git a/src/diffpy/srfit/tests/debug.py b/src/diffpy/srfit/tests/debug.py deleted file mode 100644 index ec3b1a4b..00000000 --- a/src/diffpy/srfit/tests/debug.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srfit 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.srfit.tests.debug - -Exceptions raised by failed tests or other errors are not caught. -""" - - -if __name__ == "__main__": - import sys - - from diffpy.srfit.tests import testsuite - - pattern = sys.argv[1] if len(sys.argv) > 1 else "" - suite = testsuite(pattern) - suite.debug() - - -# End of file diff --git a/src/diffpy/srfit/tests/run.py b/src/diffpy/srfit/tests/run.py deleted file mode 100644 index a47c886e..00000000 --- a/src/diffpy/srfit/tests/run.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.srfit 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.srfit.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.srfit.tests import test - - # produce zero exit code for a successful test - sys.exit(not test().wasSuccessful()) - -# End of file diff --git a/src/diffpy/srfit/tests/testbuilder.py b/tests/test_builder.py similarity index 99% rename from src/diffpy/srfit/tests/testbuilder.py rename to tests/test_builder.py index b7bf6f1a..60ac3d52 100644 --- a/src/diffpy/srfit/tests/testbuilder.py +++ b/tests/test_builder.py @@ -18,10 +18,10 @@ import unittest import numpy +from utils import _makeArgs, noObserversInGlobalBuilders import diffpy.srfit.equation.builder as builder import diffpy.srfit.equation.literals as literals -from diffpy.srfit.tests.utils import _makeArgs, noObserversInGlobalBuilders class TestBuilder(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testcharacteristicfunctions.py b/tests/test_characteristicfunctions.py similarity index 98% rename from src/diffpy/srfit/tests/testcharacteristicfunctions.py rename to tests/test_characteristicfunctions.py index 7a68487b..ba9dd198 100644 --- a/src/diffpy/srfit/tests/testcharacteristicfunctions.py +++ b/tests/test_characteristicfunctions.py @@ -18,9 +18,9 @@ import unittest import numpy +from utils import _msg_nosas, has_sas from diffpy.srfit.sas.sasimport import sasimport -from diffpy.srfit.tests.utils import _msg_nosas, has_sas # Global variables to be assigned in setUp cf = None diff --git a/src/diffpy/srfit/tests/testconstraint.py b/tests/test_constraint.py similarity index 100% rename from src/diffpy/srfit/tests/testconstraint.py rename to tests/test_constraint.py diff --git a/src/diffpy/srfit/tests/testcontribution.py b/tests/test_contribution.py similarity index 99% rename from src/diffpy/srfit/tests/testcontribution.py rename to tests/test_contribution.py index e707b89a..9ca8f131 100644 --- a/src/diffpy/srfit/tests/testcontribution.py +++ b/tests/test_contribution.py @@ -18,13 +18,13 @@ import unittest from numpy import arange, array_equal, dot, sin +from utils import noObserversInGlobalBuilders from diffpy.srfit.exceptions import SrFitError from diffpy.srfit.fitbase.fitcontribution import FitContribution from diffpy.srfit.fitbase.parameter import Parameter from diffpy.srfit.fitbase.profile import Profile from diffpy.srfit.fitbase.profilegenerator import ProfileGenerator -from diffpy.srfit.tests.utils import noObserversInGlobalBuilders class TestContribution(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testdiffpyparset.py b/tests/test_diffpyparset.py similarity index 98% rename from src/diffpy/srfit/tests/testdiffpyparset.py rename to tests/test_diffpyparset.py index ca5ce791..de449837 100644 --- a/src/diffpy/srfit/tests/testdiffpyparset.py +++ b/tests/test_diffpyparset.py @@ -19,8 +19,7 @@ import unittest import numpy - -from diffpy.srfit.tests.utils import _msg_nostructure, has_structure +from utils import _msg_nostructure, has_structure # Global variables to be assigned in setUp Atom = Lattice = Structure = DiffpyStructureParSet = None diff --git a/src/diffpy/srfit/tests/testequation.py b/tests/test_equation.py similarity index 98% rename from src/diffpy/srfit/tests/testequation.py rename to tests/test_equation.py index 427d90cb..8678fe5e 100644 --- a/src/diffpy/srfit/tests/testequation.py +++ b/tests/test_equation.py @@ -17,9 +17,10 @@ import unittest +from utils import _makeArgs, noObserversInGlobalBuilders + import diffpy.srfit.equation.literals as literals from diffpy.srfit.equation import Equation -from diffpy.srfit.tests.utils import _makeArgs, noObserversInGlobalBuilders class TestEquation(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testfitrecipe.py b/tests/test_fitrecipe.py similarity index 99% rename from src/diffpy/srfit/tests/testfitrecipe.py rename to tests/test_fitrecipe.py index b3522073..87951666 100644 --- a/src/diffpy/srfit/tests/testfitrecipe.py +++ b/tests/test_fitrecipe.py @@ -18,12 +18,12 @@ import unittest from numpy import array_equal, dot, linspace, pi, sin +from utils import capturestdout from diffpy.srfit.fitbase.fitcontribution import FitContribution from diffpy.srfit.fitbase.fitrecipe import FitRecipe from diffpy.srfit.fitbase.parameter import Parameter from diffpy.srfit.fitbase.profile import Profile -from diffpy.srfit.tests.utils import capturestdout class TestFitRecipe(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testfitresults.py b/tests/test_fitresults.py similarity index 98% rename from src/diffpy/srfit/tests/testfitresults.py rename to tests/test_fitresults.py index 367b9481..928b72d1 100644 --- a/src/diffpy/srfit/tests/testfitresults.py +++ b/tests/test_fitresults.py @@ -17,9 +17,10 @@ import unittest +from utils import datafile + from diffpy.srfit.fitbase.fitrecipe import FitRecipe from diffpy.srfit.fitbase.fitresults import initializeRecipe -from diffpy.srfit.tests.utils import datafile class TestInitializeRecipe(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testliterals.py b/tests/test_literals.py similarity index 100% rename from src/diffpy/srfit/tests/testliterals.py rename to tests/test_literals.py diff --git a/src/diffpy/srfit/tests/testobjcrystparset.py b/tests/test_objcrystparset.py similarity index 99% rename from src/diffpy/srfit/tests/testobjcrystparset.py rename to tests/test_objcrystparset.py index bf5b0021..00e81700 100644 --- a/src/diffpy/srfit/tests/testobjcrystparset.py +++ b/tests/test_objcrystparset.py @@ -18,8 +18,7 @@ import unittest import numpy - -from diffpy.srfit.tests.utils import _msg_nopyobjcryst, has_pyobjcryst +from utils import _msg_nopyobjcryst, has_pyobjcryst # Global variables to be assigned in setUp ObjCrystCrystalParSet = spacegroups = None diff --git a/src/diffpy/srfit/tests/testparameter.py b/tests/test_parameter.py similarity index 100% rename from src/diffpy/srfit/tests/testparameter.py rename to tests/test_parameter.py diff --git a/src/diffpy/srfit/tests/testparameterset.py b/tests/test_parameterset.py similarity index 100% rename from src/diffpy/srfit/tests/testparameterset.py rename to tests/test_parameterset.py diff --git a/src/diffpy/srfit/tests/testpdf.py b/tests/test_pdf.py similarity index 98% rename from src/diffpy/srfit/tests/testpdf.py rename to tests/test_pdf.py index fc1c53ab..9d43ee32 100644 --- a/src/diffpy/srfit/tests/testpdf.py +++ b/tests/test_pdf.py @@ -20,16 +20,10 @@ import unittest import numpy +from utils import _msg_nosrreal, _msg_nostructure, datafile, has_srreal, has_structure from diffpy.srfit.exceptions import SrFitError from diffpy.srfit.pdf import PDFContribution, PDFGenerator, PDFParser -from diffpy.srfit.tests.utils import ( - _msg_nosrreal, - _msg_nostructure, - datafile, - has_srreal, - has_structure, -) # ---------------------------------------------------------------------------- diff --git a/src/diffpy/srfit/tests/testprofile.py b/tests/test_profile.py similarity index 99% rename from src/diffpy/srfit/tests/testprofile.py rename to tests/test_profile.py index 67917e86..74b8382c 100644 --- a/src/diffpy/srfit/tests/testprofile.py +++ b/tests/test_profile.py @@ -20,10 +20,10 @@ import unittest from numpy import allclose, arange, array, array_equal, ones_like +from utils import datafile from diffpy.srfit.exceptions import SrFitError from diffpy.srfit.fitbase.profile import Profile -from diffpy.srfit.tests.utils import datafile class TestProfile(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testprofilegenerator.py b/tests/test_profilegenerator.py similarity index 100% rename from src/diffpy/srfit/tests/testprofilegenerator.py rename to tests/test_profilegenerator.py diff --git a/src/diffpy/srfit/tests/testrecipeorganizer.py b/tests/test_recipeorganizer.py similarity index 99% rename from src/diffpy/srfit/tests/testrecipeorganizer.py rename to tests/test_recipeorganizer.py index 0616f795..a65adf7c 100644 --- a/src/diffpy/srfit/tests/testrecipeorganizer.py +++ b/tests/test_recipeorganizer.py @@ -18,6 +18,7 @@ import unittest import numpy +from utils import capturestdout from diffpy.srfit.equation.builder import EquationFactory from diffpy.srfit.fitbase.calculator import Calculator @@ -27,7 +28,6 @@ RecipeOrganizer, equationFromString, ) -from diffpy.srfit.tests.utils import capturestdout # ---------------------------------------------------------------------------- diff --git a/src/diffpy/srfit/tests/testrestraint.py b/tests/test_restraint.py similarity index 100% rename from src/diffpy/srfit/tests/testrestraint.py rename to tests/test_restraint.py diff --git a/src/diffpy/srfit/tests/testsas.py b/tests/test_sas.py similarity index 98% rename from src/diffpy/srfit/tests/testsas.py rename to tests/test_sas.py index 63f08984..fe17ca13 100644 --- a/src/diffpy/srfit/tests/testsas.py +++ b/tests/test_sas.py @@ -18,10 +18,10 @@ import unittest import numpy +from utils import _msg_nosas, datafile, has_sas from diffpy.srfit.sas import SASGenerator, SASParser, SASProfile from diffpy.srfit.sas.sasimport import sasimport -from diffpy.srfit.tests.utils import _msg_nosas, datafile, has_sas # ---------------------------------------------------------------------------- diff --git a/src/diffpy/srfit/tests/testsgconstraints.py b/tests/test_sgconstraints.py similarity index 99% rename from src/diffpy/srfit/tests/testsgconstraints.py rename to tests/test_sgconstraints.py index 60daa7d5..ea323a0f 100644 --- a/src/diffpy/srfit/tests/testsgconstraints.py +++ b/tests/test_sgconstraints.py @@ -18,8 +18,7 @@ import unittest import numpy - -from diffpy.srfit.tests.utils import ( +from utils import ( _msg_nopyobjcryst, _msg_nostructure, datafile, diff --git a/src/diffpy/srfit/tests/speedtest.py b/tests/test_speed.py similarity index 99% rename from src/diffpy/srfit/tests/speedtest.py rename to tests/test_speed.py index 407e06cb..93ef32f9 100644 --- a/src/diffpy/srfit/tests/speedtest.py +++ b/tests/test_speed.py @@ -20,10 +20,10 @@ import random import numpy +from utils import _makeArgs import diffpy.srfit.equation.literals as literals import diffpy.srfit.equation.visitors as visitors -from diffpy.srfit.tests.utils import _makeArgs x = numpy.arange(0, 20, 0.05) diff --git a/src/diffpy/srfit/tests/testtagmanager.py b/tests/test_tagmanager.py similarity index 100% rename from src/diffpy/srfit/tests/testtagmanager.py rename to tests/test_tagmanager.py diff --git a/src/diffpy/srfit/tests/testvisitors.py b/tests/test_visitors.py similarity index 99% rename from src/diffpy/srfit/tests/testvisitors.py rename to tests/test_visitors.py index 8b3da984..2a32d5e3 100644 --- a/src/diffpy/srfit/tests/testvisitors.py +++ b/tests/test_visitors.py @@ -17,9 +17,10 @@ import unittest +from utils import _makeArgs + import diffpy.srfit.equation.literals as literals import diffpy.srfit.equation.visitors as visitors -from diffpy.srfit.tests.utils import _makeArgs class TestValidator(unittest.TestCase): diff --git a/src/diffpy/srfit/tests/testweakrefcallable.py b/tests/test_weakrefcallable.py similarity index 100% rename from src/diffpy/srfit/tests/testweakrefcallable.py rename to tests/test_weakrefcallable.py diff --git a/src/diffpy/srfit/tests/testdata/LaMnO3.stru b/tests/testdata/LaMnO3.stru similarity index 100% rename from src/diffpy/srfit/tests/testdata/LaMnO3.stru rename to tests/testdata/LaMnO3.stru diff --git a/src/diffpy/srfit/tests/testdata/ni-q27r100-neutron.gr b/tests/testdata/ni-q27r100-neutron.gr similarity index 100% rename from src/diffpy/srfit/tests/testdata/ni-q27r100-neutron.gr rename to tests/testdata/ni-q27r100-neutron.gr diff --git a/src/diffpy/srfit/tests/testdata/ni.cif b/tests/testdata/ni.cif similarity index 100% rename from src/diffpy/srfit/tests/testdata/ni.cif rename to tests/testdata/ni.cif diff --git a/src/diffpy/srfit/tests/testdata/results.res b/tests/testdata/results.res similarity index 100% rename from src/diffpy/srfit/tests/testdata/results.res rename to tests/testdata/results.res diff --git a/src/diffpy/srfit/tests/testdata/sas_ascii_test_1.txt b/tests/testdata/sas_ascii_test_1.txt similarity index 100% rename from src/diffpy/srfit/tests/testdata/sas_ascii_test_1.txt rename to tests/testdata/sas_ascii_test_1.txt diff --git a/src/diffpy/srfit/tests/testdata/sas_ellipsoid_testdata.txt b/tests/testdata/sas_ellipsoid_testdata.txt similarity index 100% rename from src/diffpy/srfit/tests/testdata/sas_ellipsoid_testdata.txt rename to tests/testdata/sas_ellipsoid_testdata.txt diff --git a/src/diffpy/srfit/tests/testdata/si-q27r60-xray.gr b/tests/testdata/si-q27r60-xray.gr similarity index 100% rename from src/diffpy/srfit/tests/testdata/si-q27r60-xray.gr rename to tests/testdata/si-q27r60-xray.gr diff --git a/src/diffpy/srfit/tests/testdata/testdata.txt b/tests/testdata/testdata.txt similarity index 100% rename from src/diffpy/srfit/tests/testdata/testdata.txt rename to tests/testdata/testdata.txt diff --git a/src/diffpy/srfit/tests/utils.py b/tests/utils.py similarity index 98% rename from src/diffpy/srfit/tests/utils.py rename to tests/utils.py index 71c6b135..e2afb4be 100644 --- a/src/diffpy/srfit/tests/utils.py +++ b/tests/utils.py @@ -15,13 +15,13 @@ """Helper routines for testing.""" +import logging as logger import sys import six import diffpy.srfit.equation.literals as literals from diffpy.srfit.sas.sasimport import sasimport -from diffpy.srfit.tests import logger # Resolve availability of optional third-party packages.