From 83af8c63c2f39c4fdb32d140c5641fab97212cc9 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 15 Aug 2024 00:27:41 -0400 Subject: [PATCH 1/7] workflow for testing --- .github/workflows/main.yml | 12 +-- run_tests.py | 1 + setup.py | 161 ------------------------------------- 3 files changed, 8 insertions(+), 166 deletions(-) delete mode 100755 setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3ade008..36efe71a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,8 +46,10 @@ jobs: mamba install --file requirements/test.txt pip install -e . - - name: Use Xvfb Action - uses: GabrielBB/xvfb-action@v1 - with: - run: | - bash -c "source $HOME/mambaforge/etc/profile.d/conda.sh && conda activate test_env && python -m run_tests.py" + - name: Validate diffpy.pdfgui + shell: bash -l {0} + run: | + conda activate test + coverage run -m unittest run_tests.py + coverage report -m + codecov diff --git a/run_tests.py b/run_tests.py index a2a69494..96471da4 100644 --- a/run_tests.py +++ b/run_tests.py @@ -2,4 +2,5 @@ import diffpy.pdfgui.tests +assert diffpy.pdfgui.tests.test().wasSuccessful() assert diffpy.pdfgui.tests.testdeps().wasSuccessful() diff --git a/setup.py b/setup.py deleted file mode 100755 index 1738fd08..00000000 --- a/setup.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env python - -# Installation script for diffpy.pdfgui - -"""PDFgui - graphical user interface for real space structure refinement. - -Packages: diffpy.pdfgui -Scripts: pdfgui -""" - -import os -import re -import sys - -from setuptools import find_packages, setup - -# Use this version when git data are not available, like in git zip archive. -# Update when tagging a new release. -FALLBACK_VERSION = "2.0.4" - -# determine if we run with Python 3. -PY3 = sys.version_info[0] == 3 - -# versioncfgfile holds version data for git commit hash and date. -# It must reside in the same directory as version.py. -MYDIR = os.path.dirname(os.path.abspath(__file__)) -versioncfgfile = os.path.join(MYDIR, "src/diffpy/pdfgui/version.cfg") -gitarchivecfgfile = os.path.join(MYDIR, ".gitarchive.cfg") - - -def gitinfo(): - from subprocess import PIPE, Popen - - kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True) - proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw) - desc = proc.stdout.read() - proc = Popen(["git", "log", "-1", "--format=%H %ct %ci"], **kw) - glog = proc.stdout.read() - rv = {} - rv["version"] = ".post".join(desc.strip().split("-")[:2]).lstrip("v") - rv["commit"], rv["timestamp"], rv["date"] = glog.strip().split(None, 2) - return rv - - -def getversioncfg(): - if PY3: - from configparser import RawConfigParser - else: - from ConfigParser import RawConfigParser - vd0 = dict(version=FALLBACK_VERSION, commit="", date="", timestamp=0) - # first fetch data from gitarchivecfgfile, ignore if it is unexpanded - g = vd0.copy() - cp0 = RawConfigParser(vd0) - cp0.read(gitarchivecfgfile) - if len(cp0.get("DEFAULT", "commit")) > 20: - g = cp0.defaults() - mx = re.search(r"\btag: v(\d[^,]*)", g.pop("refnames")) - if mx: - g["version"] = mx.group(1) - # then try to obtain version data from git. - gitdir = os.path.join(MYDIR, ".git") - if os.path.exists(gitdir) or "GIT_DIR" in os.environ: - try: - g = gitinfo() - except OSError: - pass - # finally, check and update the active version file - cp = RawConfigParser() - cp.read(versioncfgfile) - d = cp.defaults() - rewrite = not d or (g["commit"] and (g["version"] != d.get("version") or g["commit"] != d.get("commit"))) - if rewrite: - cp.set("DEFAULT", "version", g["version"]) - cp.set("DEFAULT", "commit", g["commit"]) - cp.set("DEFAULT", "date", g["date"]) - cp.set("DEFAULT", "timestamp", g["timestamp"]) - with open(versioncfgfile, "w") as fp: - cp.write(fp) - return cp - - -versiondata = getversioncfg() - - -def dirglob(d, *patterns): - from glob import glob - - rv = [] - for p in patterns: - rv += glob(os.path.join(d, p)) - return rv - - -with open(os.path.join(MYDIR, "README.rst")) as fp: - long_description = fp.read() - -# define distribution -setup_args = dict( - name="diffpy.pdfgui", - version="3.0.5", - packages=find_packages(os.path.join(MYDIR, "src")), - package_dir={"": "src"}, - include_package_data=True, - test_suite="diffpy.pdfgui.tests", - entry_points={ - "gui_scripts": [ - "pdfgui=diffpy.pdfgui.applications.pdfgui:main", - ], - }, - data_files=[ - ("icons", dirglob("icons", "*.png", "*.ico")), - ("doc", dirglob("doc", "*.pdf")), - ("doc/manual", dirglob("doc/manual", "*.html", "*.pdf")), - ("doc/manual/images", dirglob("doc/manual/images", "*.png")), - ("doc/tutorial", dirglob("doc/tutorial", "*")), - ], - # manual and tutorial files should not be zipped - zip_safe=False, - install_requires=[ - "six", - "diffpy.structure>=3", - "diffpy.pdffit2", - "diffpy.utils", - ], - author="Simon J.L. Billinge", - author_email="sb2896@columbia.edu", - maintainer="Pavol Juhas", - maintainer_email="pavol.juhas@gmail.com", - url="https://github.com/diffpy/diffpy.pdfgui", - description="GUI for PDF simulation and structure refinement.", - long_description=long_description, - long_description_content_type="text/x-rst", - license="BSD", - keywords="PDF structure refinement GUI", - classifiers=[ - # List of possible values at - # http://pypi.python.org/pypi?:action=list_classifiers - "Development Status :: 5 - Production/Stable", - "Environment :: MacOS X", - "Environment :: Win32 (MS Windows)", - "Environment :: X11 Applications", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Operating System :: MacOS", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.10", - "Topic :: Scientific/Engineering :: Chemistry", - "Topic :: Scientific/Engineering :: Physics", - ], -) - -if __name__ == "__main__": - setup(**setup_args) - -# End of file From 5108e9c22f5a0679c7002a6c276e6aec6620c9a0 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 15 Aug 2024 18:50:20 -0400 Subject: [PATCH 2/7] test unittest --- .github/workflows/main.yml | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36efe71a..91733948 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,28 +23,28 @@ jobs: path: . fetch-depth: 0 # avoid shallow clone with no tags - - name: Install Mamba - run: | - wget "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh" -O mambaforge.sh - bash mambaforge.sh -b -p $HOME/mambaforge - echo "$HOME/mambaforge/bin" >> $GITHUB_PATH - source $HOME/mambaforge/etc/profile.d/conda.sh - conda init bash - - - name: Create conda environment - run: | - source $HOME/mambaforge/etc/profile.d/conda.sh - conda create -n test_env python=3.12 xonsh regolith -c conda-forge -y - conda activate test_env - pip install case_insensitive_dict + - name: initialize miniconda + # this uses a marketplace action that sets up miniconda in a way that makes + # it easier to use. I tried setting it up without this and it was a pain + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: test + # environment.yml file is needed by this action. Because I don't want + # maintain this but rather maintain the requirements files it just has + # basic things in it like conda and pip + environment-file: ./environment.yml + python-version: 3 + auto-activate-base: false - - name: Install dependencies + - name: install diffpy.pdfgui requirements + shell: bash -l {0} run: | - source $HOME/mambaforge/etc/profile.d/conda.sh - conda activate test_env - mamba install --file requirements/run.txt - mamba install --file requirements/test.txt - pip install -e . + conda config --set always_yes yes --set changeps1 no + conda config --add channels conda-forge + conda activate test + conda install --file requirements/run.txt + conda install --file requirements/test.txt + pip install . - name: Validate diffpy.pdfgui shell: bash -l {0} From df85cfbddb0f7dcf1feb5c57ad7dde050aee7d78 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 15 Aug 2024 18:56:41 -0400 Subject: [PATCH 3/7] try Xvfb --- .github/workflows/main.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 91733948..57c70182 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,9 +46,18 @@ jobs: conda install --file requirements/test.txt pip install . + - name: Install Xvfb + run: sudo apt-get install -y xvfb + + - name: Start Xvfb + run: | + export DISPLAY=:99 + Xvfb :99 -screen 0 1024x768x16 & + - name: Validate diffpy.pdfgui shell: bash -l {0} run: | + export DISPLAY=:99 conda activate test coverage run -m unittest run_tests.py coverage report -m From 7bf06c4a00a7461f72d9cc3f52e05496cd732175 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 15 Aug 2024 19:42:32 -0400 Subject: [PATCH 4/7] try to remove no test ran line --- run_tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/run_tests.py b/run_tests.py index 96471da4..175a2c7b 100644 --- a/run_tests.py +++ b/run_tests.py @@ -2,5 +2,9 @@ import diffpy.pdfgui.tests -assert diffpy.pdfgui.tests.test().wasSuccessful() -assert diffpy.pdfgui.tests.testdeps().wasSuccessful() +def run_tests(): + assert diffpy.pdfgui.tests.test().wasSuccessful() + assert diffpy.pdfgui.tests.testdeps().wasSuccessful() + +if __name__ == '__main__': + run_tests() From bebdd9d40d5b74494472731663dfd1dc683c5a99 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:43:09 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit hooks --- run_tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run_tests.py b/run_tests.py index 175a2c7b..3f4c7172 100644 --- a/run_tests.py +++ b/run_tests.py @@ -2,9 +2,11 @@ import diffpy.pdfgui.tests + def run_tests(): assert diffpy.pdfgui.tests.test().wasSuccessful() assert diffpy.pdfgui.tests.testdeps().wasSuccessful() -if __name__ == '__main__': + +if __name__ == "__main__": run_tests() From c9dd3797cfbd3b371b2ff7252021b85308471bff Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 15 Aug 2024 19:57:00 -0400 Subject: [PATCH 6/7] try to remove no test ran line --- run_tests.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/run_tests.py b/run_tests.py index 3f4c7172..c33989f2 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,12 +1,18 @@ #!/usr/bin/env python +import unittest + import diffpy.pdfgui.tests -def run_tests(): - assert diffpy.pdfgui.tests.test().wasSuccessful() - assert diffpy.pdfgui.tests.testdeps().wasSuccessful() +class TestPDFGui(unittest.TestCase): + + def test_main_suite(self): + self.assertTrue(diffpy.pdfgui.tests.test().wasSuccessful()) + + def test_deps_suite(self): + self.assertTrue(diffpy.pdfgui.tests.testdeps().wasSuccessful()) if __name__ == "__main__": - run_tests() + unittest.main() From 5ab8b56866c0e5a5ab7067a46211f5029688ade2 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Fri, 16 Aug 2024 15:14:51 -0400 Subject: [PATCH 7/7] try pytest --- .github/workflows/main.yml | 2 +- run_tests.py | 18 ------------------ src/diffpy/pdfgui/tests/conftest.py | 5 +++++ ...{testaboutdialog.py => test_aboutdialog.py} | 0 ...{testcalculation.py => test_calculation.py} | 0 .../{testconstraint.py => test_constraint.py} | 0 ...tdatasetpanels.py => test_datasetpanels.py} | 0 ...eriespanel.py => test_dopingseriespanel.py} | 0 ...dplotframe.py => test_extendedplotframe.py} | 0 .../{testfitdataset.py => test_fitdataset.py} | 0 ...estfitstructure.py => test_fitstructure.py} | 0 ...trowsdialog.py => test_insertrowsdialog.py} | 0 ...{testloadproject.py => test_loadproject.py} | 0 .../{testmainframe.py => test_mainframe.py} | 0 .../{testparameter.py => test_parameter.py} | 0 ...ameterspanel.py => test_parameterspanel.py} | 0 .../{testpdfdataset.py => test_pdfdataset.py} | 0 ...tpdfguicontrol.py => test_pdfguicontrol.py} | 0 ...estpdfstructure.py => test_pdfstructure.py} | 0 ...urepanel.py => test_phaseconfigurepanel.py} | 0 ...uctureviewer.py => test_structureviewer.py} | 0 ...panel.py => test_temperatureseriespanel.py} | 0 22 files changed, 6 insertions(+), 19 deletions(-) delete mode 100644 run_tests.py rename src/diffpy/pdfgui/tests/{testaboutdialog.py => test_aboutdialog.py} (100%) rename src/diffpy/pdfgui/tests/{testcalculation.py => test_calculation.py} (100%) rename src/diffpy/pdfgui/tests/{testconstraint.py => test_constraint.py} (100%) rename src/diffpy/pdfgui/tests/{testdatasetpanels.py => test_datasetpanels.py} (100%) rename src/diffpy/pdfgui/tests/{testdopingseriespanel.py => test_dopingseriespanel.py} (100%) rename src/diffpy/pdfgui/tests/{testextendedplotframe.py => test_extendedplotframe.py} (100%) rename src/diffpy/pdfgui/tests/{testfitdataset.py => test_fitdataset.py} (100%) rename src/diffpy/pdfgui/tests/{testfitstructure.py => test_fitstructure.py} (100%) rename src/diffpy/pdfgui/tests/{testinsertrowsdialog.py => test_insertrowsdialog.py} (100%) rename src/diffpy/pdfgui/tests/{testloadproject.py => test_loadproject.py} (100%) rename src/diffpy/pdfgui/tests/{testmainframe.py => test_mainframe.py} (100%) rename src/diffpy/pdfgui/tests/{testparameter.py => test_parameter.py} (100%) rename src/diffpy/pdfgui/tests/{testparameterspanel.py => test_parameterspanel.py} (100%) rename src/diffpy/pdfgui/tests/{testpdfdataset.py => test_pdfdataset.py} (100%) rename src/diffpy/pdfgui/tests/{testpdfguicontrol.py => test_pdfguicontrol.py} (100%) rename src/diffpy/pdfgui/tests/{testpdfstructure.py => test_pdfstructure.py} (100%) rename src/diffpy/pdfgui/tests/{testphaseconfigurepanel.py => test_phaseconfigurepanel.py} (100%) rename src/diffpy/pdfgui/tests/{teststructureviewer.py => test_structureviewer.py} (100%) rename src/diffpy/pdfgui/tests/{testtemperatureseriespanel.py => test_temperatureseriespanel.py} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57c70182..c26194af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,6 +59,6 @@ jobs: run: | export DISPLAY=:99 conda activate test - coverage run -m unittest run_tests.py + coverage run -m pytest -vv -s coverage report -m codecov diff --git a/run_tests.py b/run_tests.py deleted file mode 100644 index c33989f2..00000000 --- a/run_tests.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -import unittest - -import diffpy.pdfgui.tests - - -class TestPDFGui(unittest.TestCase): - - def test_main_suite(self): - self.assertTrue(diffpy.pdfgui.tests.test().wasSuccessful()) - - def test_deps_suite(self): - self.assertTrue(diffpy.pdfgui.tests.testdeps().wasSuccessful()) - - -if __name__ == "__main__": - unittest.main() diff --git a/src/diffpy/pdfgui/tests/conftest.py b/src/diffpy/pdfgui/tests/conftest.py index e3b63139..fefe798b 100644 --- a/src/diffpy/pdfgui/tests/conftest.py +++ b/src/diffpy/pdfgui/tests/conftest.py @@ -1,9 +1,14 @@ import json +import subprocess from pathlib import Path import pytest +def pytest_collection_modifyitems(session, config, items): + subprocess.run(["python", "-m", "diffpy.pdfgui.tests.rundeps"], check=True) + + @pytest.fixture def user_filesystem(tmp_path): base_dir = Path(tmp_path) diff --git a/src/diffpy/pdfgui/tests/testaboutdialog.py b/src/diffpy/pdfgui/tests/test_aboutdialog.py similarity index 100% rename from src/diffpy/pdfgui/tests/testaboutdialog.py rename to src/diffpy/pdfgui/tests/test_aboutdialog.py diff --git a/src/diffpy/pdfgui/tests/testcalculation.py b/src/diffpy/pdfgui/tests/test_calculation.py similarity index 100% rename from src/diffpy/pdfgui/tests/testcalculation.py rename to src/diffpy/pdfgui/tests/test_calculation.py diff --git a/src/diffpy/pdfgui/tests/testconstraint.py b/src/diffpy/pdfgui/tests/test_constraint.py similarity index 100% rename from src/diffpy/pdfgui/tests/testconstraint.py rename to src/diffpy/pdfgui/tests/test_constraint.py diff --git a/src/diffpy/pdfgui/tests/testdatasetpanels.py b/src/diffpy/pdfgui/tests/test_datasetpanels.py similarity index 100% rename from src/diffpy/pdfgui/tests/testdatasetpanels.py rename to src/diffpy/pdfgui/tests/test_datasetpanels.py diff --git a/src/diffpy/pdfgui/tests/testdopingseriespanel.py b/src/diffpy/pdfgui/tests/test_dopingseriespanel.py similarity index 100% rename from src/diffpy/pdfgui/tests/testdopingseriespanel.py rename to src/diffpy/pdfgui/tests/test_dopingseriespanel.py diff --git a/src/diffpy/pdfgui/tests/testextendedplotframe.py b/src/diffpy/pdfgui/tests/test_extendedplotframe.py similarity index 100% rename from src/diffpy/pdfgui/tests/testextendedplotframe.py rename to src/diffpy/pdfgui/tests/test_extendedplotframe.py diff --git a/src/diffpy/pdfgui/tests/testfitdataset.py b/src/diffpy/pdfgui/tests/test_fitdataset.py similarity index 100% rename from src/diffpy/pdfgui/tests/testfitdataset.py rename to src/diffpy/pdfgui/tests/test_fitdataset.py diff --git a/src/diffpy/pdfgui/tests/testfitstructure.py b/src/diffpy/pdfgui/tests/test_fitstructure.py similarity index 100% rename from src/diffpy/pdfgui/tests/testfitstructure.py rename to src/diffpy/pdfgui/tests/test_fitstructure.py diff --git a/src/diffpy/pdfgui/tests/testinsertrowsdialog.py b/src/diffpy/pdfgui/tests/test_insertrowsdialog.py similarity index 100% rename from src/diffpy/pdfgui/tests/testinsertrowsdialog.py rename to src/diffpy/pdfgui/tests/test_insertrowsdialog.py diff --git a/src/diffpy/pdfgui/tests/testloadproject.py b/src/diffpy/pdfgui/tests/test_loadproject.py similarity index 100% rename from src/diffpy/pdfgui/tests/testloadproject.py rename to src/diffpy/pdfgui/tests/test_loadproject.py diff --git a/src/diffpy/pdfgui/tests/testmainframe.py b/src/diffpy/pdfgui/tests/test_mainframe.py similarity index 100% rename from src/diffpy/pdfgui/tests/testmainframe.py rename to src/diffpy/pdfgui/tests/test_mainframe.py diff --git a/src/diffpy/pdfgui/tests/testparameter.py b/src/diffpy/pdfgui/tests/test_parameter.py similarity index 100% rename from src/diffpy/pdfgui/tests/testparameter.py rename to src/diffpy/pdfgui/tests/test_parameter.py diff --git a/src/diffpy/pdfgui/tests/testparameterspanel.py b/src/diffpy/pdfgui/tests/test_parameterspanel.py similarity index 100% rename from src/diffpy/pdfgui/tests/testparameterspanel.py rename to src/diffpy/pdfgui/tests/test_parameterspanel.py diff --git a/src/diffpy/pdfgui/tests/testpdfdataset.py b/src/diffpy/pdfgui/tests/test_pdfdataset.py similarity index 100% rename from src/diffpy/pdfgui/tests/testpdfdataset.py rename to src/diffpy/pdfgui/tests/test_pdfdataset.py diff --git a/src/diffpy/pdfgui/tests/testpdfguicontrol.py b/src/diffpy/pdfgui/tests/test_pdfguicontrol.py similarity index 100% rename from src/diffpy/pdfgui/tests/testpdfguicontrol.py rename to src/diffpy/pdfgui/tests/test_pdfguicontrol.py diff --git a/src/diffpy/pdfgui/tests/testpdfstructure.py b/src/diffpy/pdfgui/tests/test_pdfstructure.py similarity index 100% rename from src/diffpy/pdfgui/tests/testpdfstructure.py rename to src/diffpy/pdfgui/tests/test_pdfstructure.py diff --git a/src/diffpy/pdfgui/tests/testphaseconfigurepanel.py b/src/diffpy/pdfgui/tests/test_phaseconfigurepanel.py similarity index 100% rename from src/diffpy/pdfgui/tests/testphaseconfigurepanel.py rename to src/diffpy/pdfgui/tests/test_phaseconfigurepanel.py diff --git a/src/diffpy/pdfgui/tests/teststructureviewer.py b/src/diffpy/pdfgui/tests/test_structureviewer.py similarity index 100% rename from src/diffpy/pdfgui/tests/teststructureviewer.py rename to src/diffpy/pdfgui/tests/test_structureviewer.py diff --git a/src/diffpy/pdfgui/tests/testtemperatureseriespanel.py b/src/diffpy/pdfgui/tests/test_temperatureseriespanel.py similarity index 100% rename from src/diffpy/pdfgui/tests/testtemperatureseriespanel.py rename to src/diffpy/pdfgui/tests/test_temperatureseriespanel.py