Skip to content

Commit

Permalink
Migration to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Dec 16, 2020
1 parent a7b9e38 commit 6fc11ec
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 526 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ jobs:
# Note the use of the -Wa flag to show DeprecationWarnings
- name: Unit tests
run: |
python -Wa -m unittest discover --verbose --buffer
pip install -r dev-requirements.txt
python setup.py install
cd ~
python -Wa -m pytest --pyargs iris
- name: Build documentation
run: |
pip install -r dev-requirements.txt
python setup.py build_sphinx
- name: Doctests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.pytest_cache/
htmlcov/
.tox/
.coverage
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----

* Code snippets in documentation are now tested for correctness.
* Migration of test infrastructure to pytest.
* Tests are now included in source distributions.

5.2.4
Expand All @@ -19,7 +20,7 @@
5.2.2
-----

* Fixed an issue where a broken plug-in would crash Iris. Instead, broken plug-in will not be loaded.
* Fixed an issue where a broken plug-in would crash Iris. Instead, broken plug-ins will not be loaded.

5.2.1
-----
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ To install the latest development version from
python -m pip install git+git://github.com/LaurentRDC/iris-ued.git

Each version is tested against Python 3.6+. If you are using a different
version, tests can be run using the standard library\'s
[unittest]{.title-ref} module.
version, tests can be run using the `pytest` package.

## Usage

Expand Down
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sphinx >= 3
sphinx_rtd_theme >= 0.4
sphinx_rtd_theme >= 0.4
pytest >= 6
2 changes: 2 additions & 0 deletions iris/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
# Parser to reach documentation
docs_parser = subparsers.add_parser("docs", help=DOCS_HELP)


def main():
# This is to support the PyInstaller-built executables
# as described here:
Expand All @@ -73,5 +74,6 @@ def main():
else:
sys.exit(run(path=None))


if __name__ == "__main__":
main()
9 changes: 4 additions & 5 deletions iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from iris import AbstractRawDataset, check_raw_bounds
from iris.meta import ExperimentalParameter
import numpy as np
import unittest


class TestRawDataset(AbstractRawDataset):
""" Class for using raw datasets in tests """

# We don't want pytest to collect this class as a test
# https://stackoverflow.com/a/63430765
__test__ = False

test = ExperimentalParameter("test", int, default=0)
resolution = ExperimentalParameter("resolution", tuple, (16, 16))

Expand All @@ -20,7 +23,3 @@ def __init__(self, *args, **kwargs):
@check_raw_bounds
def raw_data(self, timedelay, scan=1):
return np.ones((self.resolution), dtype=np.uint8)


if __name__ == "__main__":
unittest.main()
9 changes: 4 additions & 5 deletions iris/tests/plugin_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from iris import AbstractRawDataset, ExperimentalParameter
import numpy as np
import unittest


class TestRawDatasetPlugin(AbstractRawDataset):
Expand All @@ -16,6 +15,10 @@ class TestRawDatasetPlugin(AbstractRawDataset):
temperature = ExperimentalParameter("temperature", ptype=float, default=500)
is_useful = ExperimentalParameter("is_useful", ptype=bool, default=True)

# We don't want pytest to collect this class as a test
# https://stackoverflow.com/a/63430765
__test__ = False

def __init__(self, source=None, metadata=dict()):
# Metadata can be filled as a dictionary before
# initialization. # Attributes which are not
Expand All @@ -33,7 +36,3 @@ def __init__(self, source=None, metadata=dict()):

def raw_data(self, *args, **kwargs):
return np.random.random(size=self.resolution)


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 6fc11ec

Please sign in to comment.