-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ Add unit tests for SpectraFit version and Python 3.8 deprecat…
…ion warning (#1641) * refactor: ♻️ Improve Python 3.8 deprecation warning message format * refactor: ♻️ Update docstrings to use 'dataframe' consistently * test: ✅ Add unit tests for SpectraFit version and Python 3.8 deprecation warning
- Loading branch information
Showing
3 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Tests for the SpectraFit __init__.py file.""" | ||
|
||
import importlib | ||
import sys | ||
import warnings | ||
|
||
import spectrafit | ||
|
||
from pytest import MonkeyPatch | ||
from spectrafit import PYTHON_38_VERSION | ||
from spectrafit import __version__ | ||
|
||
|
||
def test_version() -> None: | ||
"""Test the version string.""" | ||
assert __version__ == "1.0.5" | ||
|
||
|
||
def test_python_38_warning(monkeypatch: MonkeyPatch) -> None: | ||
"""Test that a warning is issued for Python 3.8.""" | ||
# Set the Python version to 3.8 | ||
monkeypatch.setattr(sys, "version_info", (3, 8, 0)) | ||
|
||
version_str = f"{PYTHON_38_VERSION[0]}.{PYTHON_38_VERSION[1]}" | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
# Reload the module to trigger the warning | ||
importlib.reload(spectrafit) | ||
|
||
# Check that a warning was issued | ||
assert len(w) == 1 | ||
assert issubclass(w[-1].category, DeprecationWarning) | ||
assert ( | ||
f"Support for Python {version_str} is approaching its end-of-life." | ||
in str(w[-1].message) | ||
) | ||
|
||
|
||
def test_no_warning_for_other_versions(monkeypatch: MonkeyPatch) -> None: | ||
"""Test that no warning is issued for Python versions other than 3.8.""" | ||
# Set the Python version to 3.9 | ||
monkeypatch.setattr(sys, "version_info", (3, 9, 0)) | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
# Reload the module to ensure no warning is triggered | ||
importlib.reload(spectrafit) | ||
|
||
# Check that no warning was issued | ||
assert len(w) == 0 |