From 861803c877683ca0afd752fd5fb1ee1d76869899 Mon Sep 17 00:00:00 2001 From: swryan Date: Tue, 12 Mar 2024 13:38:17 -0400 Subject: [PATCH 1/3] change build system to hatch; add test workflow --- .github/workflows/test_workflow.yml | 148 ++++++++++++++++++ pyproject.toml | 38 +++++ setup.cfg | 2 - setup.py | 42 ----- testflo/tests/__init__.py | 0 .../{test => tests}/test_nested_fixtures.py | 10 +- testflo/{test => tests}/test_testflo.py | 12 +- 7 files changed, 197 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/test_workflow.yml create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py create mode 100644 testflo/tests/__init__.py rename testflo/{test => tests}/test_nested_fixtures.py (81%) rename testflo/{test => tests}/test_testflo.py (89%) diff --git a/.github/workflows/test_workflow.yml b/.github/workflows/test_workflow.yml new file mode 100644 index 0000000..515c147 --- /dev/null +++ b/.github/workflows/test_workflow.yml @@ -0,0 +1,148 @@ +name: Test testflo + +on: + # Trigger on push or pull request events for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allow running the workflow manually from the Actions tab + workflow_dispatch: + inputs: + debug_enabled: + type: boolean + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' + required: false + default: false + +permissions: {} + +jobs: + + tests: + + timeout-minutes: 120 + + strategy: + fail-fast: false + matrix: + include: + # test on Ubuntu + - NAME: Ubuntu Baseline + OS: ubuntu-latest + PY: '3.11' + + # test on MacOS + - NAME: MacOS Baseline + OS: macos-latest + PY: '3.11' + + runs-on: ${{ matrix.OS }} + + name: ${{ matrix.NAME }} + + defaults: + run: + shell: bash -l {0} + + steps: + + - name: Checkout code + uses: actions/checkout@v3 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.PY }} + + - name: Install testflo + run: | + python -m pip install --upgrade pip + python -m pip install . + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + # + # To access the terminal through the web-interface: + # 1. Click on the web-browser link printed out in this action from the github + # workflow terminal + # 2. Press cntrl + c in the new tab that opens up to reveal the terminal + # 3. To activate the conda environment run: + # $ source $CONDA/etc/profile.d/conda.sh + # $ conda activate test + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} + + - name: Run tests + run: | + cd $HOME + + testflo testflo.tests || RC=$? + + if [[ $RC -ne 1 ]]; then + echo "Expected some tests to fail." + exit 1 + fi + + if [[ ! -n `grep "Ran 26 tests" testflo_report.out` ]]; then + echo "Expected 26 tests." + exit 7 + fi + + if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then + echo "Expected 7 tests to pass." + exit 7 + fi + + if [[ ! -n `grep "Failed: 8" testflo_report.out` ]]; then + echo "Expected 8 tests to fail." + exit 8 + fi + + if [[ ! -n `grep "Skipped: 11" testflo_report.out` ]]; then + echo "Expected 11 tests to be skipped." + exit 11 + fi + + - name: Run tests in serial + run: | + cd $HOME + + testflo -n 1 testflo.tests || RC=$? + + if [[ $RC -ne 1 ]]; then + echo "Expected some tests to fail." + exit 1 + fi + + if [[ ! -n `grep "Ran 26 tests using 1 processes" testflo_report.out` ]]; then + echo "Expected 26 tests on one process." + exit 7 + fi + + if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then + echo "Expected 7 tests to pass." + exit 7 + fi + + if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then + echo "Expected 7 tests to pass." + exit 7 + fi + + if [[ ! -n `grep "Failed: 8" testflo_report.out` ]]; then + echo "Expected 8 tests to fail." + exit 8 + fi + + if [[ ! -n `grep "Skipped: 11" testflo_report.out` ]]; then + echo "Expected 11 tests to be skipped." + exit 11 + fi + + - name: Notify slack of failure + uses: act10ns/slack@v2.0.0 + with: + webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + status: ${{ job.status }} + if: failure() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c2e52e3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "testflo" +dynamic = ["version"] +description = "A simple flow-based testing framework" +readme = "README.md" +license = "Apache-2.0" +classifiers = [ + "Development Status :: 4 - Beta", + "License :: OSI Approved :: Apache Software License", + "Natural Language :: English", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython", +] +dependencies = [ + "setuptools", + "coverage>=6.0", +] + +[project.scripts] +testflo = "testflo.main:main" + +[tool.hatch.version] +path = "testflo/__init__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/testflo", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b88034e..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -description-file = README.md diff --git a/setup.py b/setup.py deleted file mode 100644 index 1dd7409..0000000 --- a/setup.py +++ /dev/null @@ -1,42 +0,0 @@ -from setuptools import setup - -import re - -from pathlib import Path - -__version__ = re.findall( - r"""__version__ = ["']+([0-9\.\-dev]*)["']+""", - open('testflo/__init__.py').read(), -)[0] - -with open(Path(__file__).parent / "README.md", encoding="utf-8") as f: - long_description = f.read() - -setup(name='testflo', - version=__version__, - description="A simple flow-based testing framework", - long_description=long_description, - long_description_content_type='text/markdown', - classifiers=[ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: Apache Software License', - 'Natural Language :: English', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: POSIX :: Linux', - 'Operating System :: Microsoft :: Windows', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: Implementation :: CPython', - ], - license='Apache 2.0', - install_requires=[ - 'coverage>=6.0' - ], - packages=['testflo'], - entry_points=""" - [console_scripts] - testflo=testflo.main:main - """ - ) diff --git a/testflo/tests/__init__.py b/testflo/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/testflo/test/test_nested_fixtures.py b/testflo/tests/test_nested_fixtures.py similarity index 81% rename from testflo/test/test_nested_fixtures.py rename to testflo/tests/test_nested_fixtures.py index 2049e1d..c82ae58 100644 --- a/testflo/test/test_nested_fixtures.py +++ b/testflo/tests/test_nested_fixtures.py @@ -45,19 +45,19 @@ def test_tcase_grouped_unexpected_success(self): @unittest.skip("skipping 2") def test_tcase_grouped_skip(self): - pass + self.fail("This test should have been skipped.") @unittest.skip("skipping a whole testcase...") class SkippedTestCase2(unittest.TestCase): def test_1(self): - pass + self.fail("This test should have been skipped.") def test_2(self): - pass + self.fail("This test should have been skipped.") def test_3(self): - pass + self.fail("This test should have been skipped.") def test_4(self): - pass + self.fail("This test should have been skipped.") diff --git a/testflo/test/test_testflo.py b/testflo/tests/test_testflo.py similarity index 89% rename from testflo/test/test_testflo.py rename to testflo/tests/test_testflo.py index 4b343d0..9d2841d 100644 --- a/testflo/test/test_testflo.py +++ b/testflo/tests/test_testflo.py @@ -12,7 +12,7 @@ def test_env_var(self): self.assertNotEqual(testflo_running, False) def test_fail(self): - self.fail("failure 1") + self.fail("This test should fail") @unittest.expectedFailure def test_expected_fail_good(self): @@ -24,7 +24,7 @@ def test_unexpected_success(self): @unittest.skip("skipping 1") def test_skip(self): - pass + self.fail("This test should have been skipped.") class TestfloTestCaseWFixture(unittest.TestCase): @@ -60,16 +60,16 @@ def test_tcase_grouped_skip(self): @unittest.skip("skipping a whole testcase...") class SkippedTestCase(unittest.TestCase): def test_1(self): - pass + self.fail("This test should have been skipped.") def test_2(self): - pass + self.fail("This test should have been skipped.") def test_3(self): - pass + self.fail("This test should have been skipped.") def test_4(self): - pass + self.fail("This test should have been skipped.") class TestSubTests(unittest.TestCase): From 78814923b956d1210587b3571545bbc8851ba31f Mon Sep 17 00:00:00 2001 From: swryan Date: Tue, 12 Mar 2024 13:53:32 -0400 Subject: [PATCH 2/3] cleanup --- .github/workflows/test_workflow.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_workflow.yml b/.github/workflows/test_workflow.yml index 515c147..fc6b84c 100644 --- a/.github/workflows/test_workflow.yml +++ b/.github/workflows/test_workflow.yml @@ -86,7 +86,7 @@ jobs: if [[ ! -n `grep "Ran 26 tests" testflo_report.out` ]]; then echo "Expected 26 tests." - exit 7 + exit 26 fi if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then @@ -117,12 +117,7 @@ jobs: if [[ ! -n `grep "Ran 26 tests using 1 processes" testflo_report.out` ]]; then echo "Expected 26 tests on one process." - exit 7 - fi - - if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then - echo "Expected 7 tests to pass." - exit 7 + exit 26 fi if [[ ! -n `grep "Passed: 7" testflo_report.out` ]]; then From 7e9eecefdfba961cadfc8150c8a2f5a927753dec Mon Sep 17 00:00:00 2001 From: swryan Date: Tue, 12 Mar 2024 14:03:47 -0400 Subject: [PATCH 3/3] reduce timeout to 20 mins --- .github/workflows/test_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_workflow.yml b/.github/workflows/test_workflow.yml index fc6b84c..54f9b50 100644 --- a/.github/workflows/test_workflow.yml +++ b/.github/workflows/test_workflow.yml @@ -22,7 +22,7 @@ jobs: tests: - timeout-minutes: 120 + timeout-minutes: 20 strategy: fail-fast: false