-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lewinfox/develop
Add unit tests
- Loading branch information
Showing
10 changed files
with
266 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Run unit tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
run_tests: | ||
name: Test with Python ${{ matrix.python-version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
python-version: | ||
- "3.x" | ||
- "pypy-3.6" | ||
- "pypy-3.7" | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Run tests | ||
run: make test |
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 |
---|---|---|
@@ -1,16 +1,149 @@ | ||
# IDE stuff | ||
.venv/ | ||
.vscode/ | ||
# From https://github.com/github/gitignore/blob/master/Python.gitignore | ||
|
||
# Package stuff | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.py[cod] | ||
__pycache__/ | ||
*.so | ||
*~ | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# vscode | ||
.vscode | ||
|
||
# Don't want to have the .dat file under VCS | ||
# Data files | ||
*.dat |
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 |
---|---|---|
@@ -1,33 +1,50 @@ | ||
.RECIPEPREFIX = > | ||
|
||
# Remove build artefacts | ||
.PHONY: clean | ||
clean: | ||
> @echo Cleaning | ||
> @rm -rf build | ||
|
||
# Rebuild the pickled `.dat` file from `rmsfact.txt` | ||
.PHONY: build_binary_data | ||
build_binary_data: | ||
> rm -f rmsfact/data/rmsfact.dat | ||
> python rmsfact/data/build_rmsfact.py | ||
> @echo Building binary data | ||
> @rm -f rmsfact/data/rmsfact.dat | ||
> @python rmsfact/data/build_rmsfact.py | ||
|
||
# Build the package in wheel and source form | ||
.PHONY: build | ||
build: build_binary_data | ||
> rm -rf dist | ||
> python -m build | ||
build: clean build_binary_data | ||
> @echo Building package | ||
> @python -m build | ||
|
||
# Build the package and install locally for development | ||
.PHONY: install_dev | ||
install_dev: build | ||
> python -m pip install -e . | ||
> @echo Installing locally | ||
> @python -m pip install -e . | ||
|
||
# Install | ||
.PHONY: install | ||
install: build | ||
> python -m pip install . | ||
> @echo Installing | ||
> @python -m pip install . | ||
|
||
# Build the package and upload to TestPyPI | ||
.PHONY: upload_test | ||
upload_test: build | ||
> python -m twine upload --repository testpypi dist/* | ||
upload_test: test build | ||
> @echo Uploading to testpypi | ||
> @python -m twine upload --repository testpypi dist/* | ||
|
||
# Build the package and upload to PyPI | ||
.PHONY: upload | ||
upload: build | ||
> python -m twine upload dist/* | ||
upload: test build | ||
> @echo Uploading to PyPi | ||
> @python -m twine upload dist/* | ||
|
||
# Run unit tests | ||
.PHONY: test | ||
test: clean build_binary_data | ||
> @echo Running tests | ||
> @python test |
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
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
Empty file.
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,17 @@ | ||
import sys | ||
import unittest | ||
|
||
# Make sure the package is importable | ||
sys.path.append("../rmsfact") | ||
|
||
loader = unittest.TestLoader() | ||
test_suite = loader.discover("test") | ||
test_runner = unittest.TextTestRunner() | ||
result = test_runner.run(test_suite) | ||
|
||
# Ensure that if any tests fail we return a failure code from the process. This is useful for things | ||
# like `make` and CI/CD pipelines. | ||
if result.wasSuccessful(): | ||
exit(0) | ||
|
||
exit(1) |
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,19 @@ | ||
import unittest | ||
|
||
import rmsfact | ||
|
||
|
||
class TestNewRMSFact(unittest.TestCase): | ||
|
||
# The `_new_rmsfact()` function should return a function | ||
def test_new_rms_fact_returns_function(self): | ||
self.assert_(hasattr(rmsfact._new_rmsfact(), "__call__")) | ||
|
||
# `rmsfact.rmsfact()` should be a function | ||
def test_rmsfact_is_function(self): | ||
self.assert_(hasattr(rmsfact.rmsfact, "__call__")) | ||
|
||
# `rmsfact.rmsfact()` should return a string | ||
def test_returns_string(self): | ||
fact = rmsfact.rmsfact() | ||
self.assertIsInstance(fact, str) |