Skip to content

Commit

Permalink
Fix(versioning): Fixed how versioning is done in all cases, and made …
Browse files Browse the repository at this point in the history
…tests more robust.

Made test for versioning system.
  • Loading branch information
MicahGale authored Apr 15, 2024
2 parents 6490485 + cee5cea commit 74ae807
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,33 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- run: pip install --user . montepy[test]
- run: pip install --user . montepy[build]
- run: coverage run -m pytest --junitxml=test_report.xml
- run: coverage report
if: ${{ success() || failure() }}
- run: coverage xml
if: ${{ success() || failure() }}
- name: Upload test report
if: ${{ matrix.python-version == '3.9' }}
if: ${{ matrix.python-version == '3.9' && (success() || failure() )}}
uses: actions/upload-artifact@v4
with:
name: test
path: test_report.xml
- name: Upload coverage report
if: ${{ matrix.python-version == '3.9' }}
if: ${{ matrix.python-version == '3.9' && (success() || failure() )}}
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.xml
- name: Test Reporter
if: ${{ matrix.python-version == '3.9' }}
if: ${{ matrix.python-version == '3.9' && (success() || failure() )}}
uses: dorny/[email protected]
with:
name: CI-test-report
path: test_report.xml
reporter: java-junit
- name: Coveralls GitHub Action
if: ${{ matrix.python-version == '3.9' }}
if: ${{ matrix.python-version == '3.9' && (success() || failure() )}}
uses: coverallsapp/[email protected]
with:
file: coverage.xml
Expand All @@ -92,7 +95,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.8
- run: pip install . montepy[doc]
- run: pip install . montepy[doc,build]
- run: sphinx-build doc/source/ doc/build/ -W --keep-going -E
- run: sphinx-build -b html doc/source/ doc/build/html
- uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude tests/test_version.py
2 changes: 1 addition & 1 deletion montepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from setuptools_scm import get_version

__version__ = get_version()
except ImportError:
except (ImportError, LookupError):
__version__ = "Undefined"


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ version_file = "montepy/_version.py"
include = ["montepy*"]

[tool.coverage.run]
omit = ["montepy/_version.py","tests/*"]
omit = ["tests/*"]

[tool.coverage.report]
precision = 2
Expand Down
38 changes: 38 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import importlib
import os
import sys
from unittest import TestCase


class TestVersion(TestCase):
def test_version(self):
self.assertTrue(os.path.exists(os.path.join("montepy", "_version.py")))
# Test without version.py
try:
# try without setuptools_scm
old_file = os.path.join("montepy", "_version.py")
new_file = os.path.join("montepy", "_version.bak")
os.rename(old_file, new_file)
# clear out previous imports
to_delete = set()
for mod in sys.modules:
for bad_mod in ["setuptools_scm", "montepy"]:
if bad_mod in mod:
to_delete.add(mod)
for mod in to_delete:
del sys.modules[mod]
sys.modules["setuptools_scm"] = None
import montepy

self.assertEqual(montepy.__version__, "Undefined")
# try with setuptools_scm
del sys.modules["setuptools_scm"]
importlib.reload(montepy)
print(f"From setuptools_scm: {montepy.__version__}")
self.assertTrue(len(montepy.__version__.split(".")) >= 3)
finally:
os.rename(new_file, old_file)
# do base with _version
importlib.reload(montepy)
print(f"From _version.py: {montepy.__version__}")
self.assertTrue(len(montepy.__version__.split(".")) >= 3)

0 comments on commit 74ae807

Please sign in to comment.