diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index de811ba..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -diffpy.structure/_version.py export-subst diff --git a/.github/workflows/check-news-item.yml b/.github/workflows/check-news-item.yml new file mode 100644 index 0000000..1301ca8 --- /dev/null +++ b/.github/workflows/check-news-item.yml @@ -0,0 +1,12 @@ +name: Check for News + +on: + pull_request_target: + branches: + - main + +jobs: + build: + uses: Billingegroup/release-scripts/.github/workflows/_check-news-item.yml@v0 + with: + project: diffpy.structure diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100644 index fd96a71..0000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Gather coverage report and upload to codecov - -on: - push: - branches: - - main - release: - types: - - prereleased - - published - workflow_dispatch: - -defaults: - run: - shell: bash -l {0} - -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - name: Check out diffpy.structure - uses: actions/checkout@v4 - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: test - auto-update-conda: true - environment-file: environment.yml - auto-activate-base: false - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install diffpy.structure and requirements - run: | - conda install --file requirements/run.txt - conda install --file requirements/test.txt - python -m pip install -r requirements/pip.txt - python -m pip install . --no-deps - - - name: Validate diffpy.structure - run: | - coverage run -m pytest -vv -s - coverage report -m - codecov - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index df2b392..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build and Deploy Documentation - -on: - release: - types: - - published - workflow_dispatch: - -defaults: - run: - shell: bash -l {0} - -jobs: - docs: - runs-on: ubuntu-latest - steps: - - name: Check out diffpy.structure - uses: actions/checkout@v4 - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: build - auto-update-conda: true - environment-file: environment.yml - auto-activate-base: false - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install diffpy.structure and build requirements - run: | - conda install --file requirements/build.txt - conda install --file requirements/run.txt - conda install --file requirements/docs.txt - python -m pip install -r requirements/pip.txt - python -m pip install . --no-deps - - - name: build documents - run: make -C doc html - - - name: Deploy - uses: peaceiris/actions-gh-pages@v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./doc/build/html diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 33ece6c..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Test - -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - -defaults: - run: - shell: bash -l {0} - -jobs: - validate: - runs-on: ubuntu-latest - steps: - - name: Check out diffpy.structure - uses: actions/checkout@v4 - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: test - auto-update-conda: true - environment-file: environment.yml - auto-activate-base: false - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install diffpy.structure and requirements - run: | - conda install --file requirements/run.txt - conda install --file requirements/test.txt - python -m pip install -r requirements/pip.txt - python -m pip install . --no-deps - - - name: Validate diffpy.structure - run: python -m pytest diff --git a/.github/workflows/matrix-and-codecov-on-merge-to-main.yml b/.github/workflows/matrix-and-codecov-on-merge-to-main.yml new file mode 100644 index 0000000..c1905e0 --- /dev/null +++ b/.github/workflows/matrix-and-codecov-on-merge-to-main.yml @@ -0,0 +1,21 @@ +name: CI + +on: + push: + branches: + - main + release: + types: + - prereleased + - published + workflow_dispatch: null + +jobs: + coverage: + uses: Billingegroup/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0 + with: + project: diffpy.structure + c_extension: false + headless: false + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/publish-docs-on-release.yml b/.github/workflows/publish-docs-on-release.yml new file mode 100644 index 0000000..1c5981d --- /dev/null +++ b/.github/workflows/publish-docs-on-release.yml @@ -0,0 +1,14 @@ +name: Build and Deploy Docs + +on: + release: + types: + - published + workflow_dispatch: + +jobs: + docs: + uses: Billingegroup/release-scripts/.github/workflows/_publish-docs-on-release.yml@v0 + with: + project: diffpy.structure + c_extension: false diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml new file mode 100644 index 0000000..614b16f --- /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.structure + c_extension: false + headless: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c458806..3070e19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,10 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - exclude: '\.(rst|txt)$' + - id: check-case-conflict + - id: check-merge-conflict + - id: check-toml + - id: check-added-large-files - repo: https://github.com/psf/black rev: 24.4.2 hooks: diff --git a/AUTHORS.rst b/AUTHORS.rst index 9f6a419..1abf16b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,6 +1,7 @@ Authors ======= +Billinge Group and community contributors, Pavol Juhas, Christopher L. Farrow, Xiaohao Yang, diff --git a/LICENSE.rst b/LICENSE.rst index f1fe010..2e8d4ba 100644 --- a/LICENSE.rst +++ b/LICENSE.rst @@ -15,7 +15,7 @@ Copyright (c) 2014, Australian Synchrotron Research Program Inc., ("ASRP") Copyright (c) 2014-2019, Brookhaven Science Associates, Brookhaven National Laboratory -Copyright (c) 2024, The Trustees of Columbia University in the City of New York. +Copyright (c) 2024, The Trustees of Columbia University in the City of New York. All rights reserved. The "DiffPy-CMI" is distributed subject to the following license conditions: diff --git a/LICENSE_DANSE.rst b/LICENSE_DANSE.rst index c05648e..d56af61 100644 --- a/LICENSE_DANSE.rst +++ b/LICENSE_DANSE.rst @@ -9,13 +9,13 @@ Copyright 2006-2007, Board of Trustees of Michigan State University, Copyright 2008-2012, The Trustees of Columbia University in the City of New York. (Copyright holder indicated in each source file). -Copyright (c) 2024, The Trustees of Columbia University in the City of New York. +Copyright (c) 2024, The Trustees of Columbia University in the City of New York. All rights reserved. For more information please visit the project web-page: http://www.diffpy.org/ - + or email Prof. Simon Billinge at sb2896@columbia.edu Redistribution and use in source and binary forms, with or without diff --git a/LICENSE_pymmlib.rst b/LICENSE_pymmlib.rst index e0b82c9..ef484f5 100644 --- a/LICENSE_pymmlib.rst +++ b/LICENSE_pymmlib.rst @@ -1,5 +1,5 @@ .. code-block:: text - + The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. diff --git a/README.rst b/README.rst index 5dd3a22..076bc7e 100644 --- a/README.rst +++ b/README.rst @@ -15,8 +15,8 @@ .. |Black| image:: https://img.shields.io/badge/code_style-black-black :target: https://github.com/psf/black -.. |CI| image:: https://github.com/diffpy/diffpy.structure/actions/workflows/main.yml/badge.svg - :target: https://github.com/diffpy/diffpy.structure/actions/workflows/main.yml +.. |CI| image:: https://github.com/diffpy/diffpy.structure/actions/workflows/matrix-and-codecov-on-merge-to-main.yml/badge.svg + :target: https://github.com/diffpy/diffpy.structure/actions/workflows/matrix-and-codecov-on-merge-to-main.yml .. |Codecov| image:: https://codecov.io/gh/diffpy/diffpy.structure/branch/main/graph/badge.svg :target: https://codecov.io/gh/diffpy/diffpy.structure @@ -47,6 +47,7 @@ of symmetry constraints for atom positions and displacement parameters. diffpy.structure includes definitions of all space groups in over 500 symmetry settings. + For more information about the diffpy.structure library, please consult our `online documentation `_. Citation @@ -86,11 +87,7 @@ Then, to fully install ``diffpy.structure`` in our active environment, run :: Another option is to use ``pip`` to download and install the latest release from `Python Package Index `_. -To install using ``pip`` into your ``diffpy.structure_env`` environment, we will also have to install dependencies :: - - pip install -r https://raw.githubusercontent.com/diffpy/diffpy.structure/main/requirements/run.txt - -and then install the package :: +To install using ``pip`` into your ``diffpy.structure_env`` environment, type :: pip install diffpy.structure @@ -105,7 +102,7 @@ Support and Contribute `Diffpy user group `_ is the discussion forum for general questions and discussions about the use of diffpy.structure. Please join the diffpy.structure users community by joining the Google group. The diffpy.structure project welcomes your expertise and enthusiasm! -If you see a bug or want to request a feature, please `report it as an issue `_ and/or `submit a fix as a PR `_. You can also post it to the `Diffpy user group `_. +If you see a bug or want to request a feature, please `report it as an issue `_ and/or `submit a fix as a PR `_. You can also post it to the `Diffpy user group `_. Feel free to fork the project and contribute. To install diffpy.structure in a development mode, with its sources being directly used by Python diff --git a/devutils/makesdist b/devutils/makesdist deleted file mode 100755 index dccfaa9..0000000 --- a/devutils/makesdist +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python - -"""Create source distribution tar.gz archive, where each file belongs -to a root user and modification time is set to the git commit time. -""" - -import glob -import gzip -import os -import subprocess -import sys -import tarfile - -from setup import FALLBACK_VERSION, versiondata - -BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) -sys.path.insert(0, BASEDIR) - -timestamp = versiondata.getint("DEFAULT", "timestamp") - -vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0" -emsg = "Invalid FALLBACK_VERSION. Expected %r got %r." -assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION) - - -def inform(s): - sys.stdout.write(s) - sys.stdout.flush() - return - - -inform('Run "setup.py sdist --formats=tar" ') -cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split() -ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w")) -if ec: - sys.exit(ec) -inform("[done]\n") - -tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime) - -tfin = tarfile.open(tarname) -fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0) -tfout = tarfile.open(fileobj=fpout, mode="w") - - -def fixtarinfo(tinfo): - tinfo.uid = tinfo.gid = 0 - tinfo.uname = tinfo.gname = "root" - tinfo.mtime = timestamp - tinfo.mode &= ~0o022 - return tinfo - - -inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),))) -for ti in tfin: - tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti)) - -tfin.close() -os.remove(tarname) -inform("[done]\n") diff --git a/doc/source/conf.py b/doc/source/conf.py index d3af3e3..f7b1c77 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -18,8 +18,6 @@ from importlib.metadata import version from pathlib import Path -autodoc_mock_imports = ["importlib.metadata"] - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use Path().resolve() to make it absolute, like shown here. @@ -48,8 +46,6 @@ "m2r", ] -autodoc_member_order = "groupwise" - # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -120,12 +116,6 @@ # Display all warnings for missing links. nitpicky = True -nitpick_ignore = [ - ("py:class", "array_like"), - ("py:class", "Parser"), - ("py:class", "CifFile"), -] - # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -297,7 +287,3 @@ # Example configuration for intersphinx: refer to the Python standard library. # intersphinx_mapping = {'http://docs.python.org/': None} -intersphinx_mapping = { - "python": ("https://docs.python.org/3", None), - "numpy": ("https://numpy.org/doc/stable/", None), -} diff --git a/doc/source/license.rst b/doc/source/license.rst index cfab61c..33a363a 100644 --- a/doc/source/license.rst +++ b/doc/source/license.rst @@ -7,33 +7,142 @@ License OPEN SOURCE LICENSE AGREEMENT ============================= -BSD 3-Clause License - -Copyright (c) 2024, The Trustees of Columbia University in -the City of New York. -All Rights Reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Copyright (c) 1989, 1991 Free Software Foundation, Inc. + +Copyright (c) 2006, The Regents of the University of California through Lawrence Berkeley National Laboratory + +Copyright (c) 2006-2007, Board of Trustees of Michigan State University + +Copyright (c) 2008-2012, The Trustees of Columbia University in the City of New York + +Copyright (c) 2009-2011, University of Tennessee + +Copyright (c) 2014, Australian Synchrotron Research Program Inc., ("ASRP") + +Copyright (c) 2014-2019, Brookhaven Science Associates, Brookhaven National Laboratory + +Copyright (c) 2024, The Trustees of Columbia University in the City of New York. +All rights reserved. + +The "DiffPy-CMI" is distributed subject to the following license conditions: + +.. code-block:: text + + SOFTWARE LICENSE AGREEMENT + + Software: DiffPy-CMI + + + (1) The "Software", below, refers to the aforementioned DiffPy-CMI (in either + source code, or binary form and accompanying documentation). + + Part of the software was derived from the DANSE, ObjCryst++ (with permission), + PyCifRW, Python periodictable, CCTBX, and SasView open source projects, of + which the original Copyrights are contained in each individual file. + + Each licensee is addressed as "you" or "Licensee." + + + (2) The copyright holders shown above and their third-party Licensors hereby + grant licensee a royalty-free nonexclusive license, subject to the limitations + stated herein and U.S. Government license rights. + + + (3) You may modify and make a copy or copies of the software for use within + your organization, if you meet the following conditions: + + (a) Copies in source code must include the copyright notice and this + software license agreement. + + (b) Copies in binary form must include the copyright notice and this + Software License Agreement in the documentation and/or other materials + provided with the copy. + + + (4) You may modify a copy or copies of the Software or any portion of it, thus + forming a work based on the Software, and distribute copies of such work + outside your organization, if you meet all of the following conditions: + + (a) Copies in source code must include the copyright notice and this + Software License Agreement; + + (b) Copies in binary form must include the copyright notice and this + Software License Agreement in the documentation and/or other materials + provided with the copy; + + (c) Modified copies and works based on the Software must carry prominent + notices stating that you changed specified portions of the Software. + + (d) Neither the name of Brookhaven Science Associates or Brookhaven + National Laboratory nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + written permission. + + + (5) Portions of the Software resulted from work developed under a U.S. + Government contract and are subject to the following license: + The Government is granted for itself and others acting on its behalf a + paid-up, nonexclusive, irrevocable worldwide license in this computer software + to reproduce, prepare derivative works, and perform publicly and display + publicly. + + + (6) WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT + WARRANTY OF ANY KIND. THE COPYRIGHT HOLDERS, THEIR THIRD PARTY + LICENSORS, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND + THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR IMPLIED, INCLUDING + BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL + LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF + THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF THE SOFTWARE WOULD NOT INFRINGE + PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION + UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL BE CORRECTED. + + + (7) LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDERS, THEIR + THIRD PARTY LICENSORS, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF + ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, INCIDENTAL, + CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF ANY KIND OR NATURE, INCLUDING + BUT NOT LIMITED TO LOSS OF PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, + WHETHER SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING + NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS + BEEN WARNED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGES. + + +Brookhaven National Laboratory Notice +===================================== + +Acknowledgment of sponsorship +----------------------------- + +This software was produced by the Brookhaven National Laboratory, under +Contract DE-AC02-98CH10886 with the Department of Energy. + + +Government disclaimer of liability +---------------------------------- + +Neither the United States nor the United States Department of Energy, nor +any of their employees, makes any warranty, express or implied, or assumes +any legal liability or responsibility for the accuracy, completeness, or +usefulness of any data, apparatus, product, or process disclosed, or +represents that its use would not infringe privately owned rights. + + +Brookhaven disclaimer of liability +---------------------------------- + +Brookhaven National Laboratory makes no representations or warranties, +express or implied, nor assumes any liability for the use of this software. + + +Maintenance of notice +--------------------- + +In the interest of clarity regarding the origin and status of this +software, Brookhaven National Laboratory requests that any recipient of it +maintain this notice affixed to any distribution by the recipient that +contains a copy or derivative of this software. + +END OF LICENSE diff --git a/news/recut.rst b/news/recut.rst new file mode 100644 index 0000000..973fc92 --- /dev/null +++ b/news/recut.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Recookiecut package to the group standard + +**Security:** + +* diff --git a/requirements/build.txt b/requirements/build.txt index f72d870..e69de29 100644 --- a/requirements/build.txt +++ b/requirements/build.txt @@ -1,2 +0,0 @@ -python -setuptools diff --git a/requirements/run.txt b/requirements/run.txt index 5413a93..0fdcecb 100644 --- a/requirements/run.txt +++ b/requirements/run.txt @@ -1,2 +1,2 @@ -numpy -pycifrw +numpy +pycifrw diff --git a/requirements/test.txt b/requirements/test.txt index 6f9ccf8..a727786 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -2,4 +2,5 @@ flake8 pytest codecov coverage +pytest-cov pytest-env diff --git a/src/diffpy/Structure.py b/src/diffpy/Structure.py deleted file mode 100644 index 1f65df4..0000000 --- a/src/diffpy/Structure.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.structure Complex Modeling Initiative -# (c) 2017 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. -# -############################################################################## - -"""Support import of old camel-case module names with `DeprecationWarning`. - -The imported camel-case modules are aliases for the current module -instances. Their `__name__` attributes are thus all in lower-case. - -Warning -------- -This module is deprecated and will be removed in the future. -""" - - -import sys - -# install legacy import hooks -import diffpy.structure._legacy_importer - -# replace this module with the new one -sys.modules["diffpy.Structure"] = diffpy.structure - -# End of file diff --git a/tests/test_oldimports.py b/tests/test_oldimports.py deleted file mode 100644 index 9c6ff11..0000000 --- a/tests/test_oldimports.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -############################################################################## -# -# diffpy.structure Complex Modeling Initiative -# (c) 2017 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. -# -############################################################################## - -""" -Unit tests for imports of old camel-case names. -""" - - -import importlib -import sys -import unittest -import warnings - -import diffpy - -# ---------------------------------------------------------------------------- - - -class TestOldImports(unittest.TestCase): - - @classmethod - def setUpClass(cls): - "Uncache any already-imported old modules." - for modname in tuple(sys.modules): - if modname.startswith("diffpy.Structure"): - del sys.modules[modname] # pragma: no cover - return - - def test_00TopImport(self): - """check import of diffpy.Structure""" - with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=DeprecationWarning) - import diffpy.Structure as m0 - self.assertIs(diffpy.structure, m0) - # second import should raise no warning - with warnings.catch_warnings(): - warnings.simplefilter("error") - import diffpy.Structure as m1 - self.assertIs(diffpy.structure, m1) - return - - def test_O1SubmoduleImport(self): - """check import of diffpy.Structure submodules.""" - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", category=DeprecationWarning) - import diffpy.Structure.SymmetryUtilities as symutil - - self.assertIs(DeprecationWarning, w[0].category) - self.assertIs(diffpy.structure.symmetryutilities, symutil) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", category=DeprecationWarning) - import diffpy.Structure.Parsers.P_cif as pcif - - self.assertIs(DeprecationWarning, w[0].category) - self.assertIs(diffpy.structure.parsers.p_cif, pcif) - self.assertRaises(ImportError, importlib.import_module, "diffpy.Structure.SSpaceGroups") - return - - -# End of class TestOldImports - -# ---------------------------------------------------------------------------- - -if __name__ == "__main__": - unittest.main()