Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python module #5

Merged
merged 4 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: install test dependency
run: python3 -m pip install pytest
- name: install module
run: python3 -m pip install .
- name: test
run: python magic_python/core.py 17. 15
run: python3 -m pytest
1 change: 1 addition & 0 deletions magic_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import my_magic_function
5 changes: 3 additions & 2 deletions magic_python/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
import numpy as np

def my_magic_function(x, y):
return x + y
return np.log(x) + np.log(y)

def main(argv):
if len(argv) == 0:
Expand All @@ -15,4 +16,4 @@ def main(argv):
print(magic_result)

if __name__ == "__main__":
exit(main(sys.argv[1:]))
sys.exit(main(sys.argv[1:]))
27 changes: 27 additions & 0 deletions magic_python/tests/test_my_magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
import numpy as np
# We want numpy to give us expections
np.seterr(all='raise')
import magic_python

def test_values():
result = magic_python.my_magic_function(17., 45.)
expected_result = np.log(17.) + np.log(45.)
assert result == expected_result

def test_math():
result = magic_python.my_magic_function(14., 72.)
expected_result = np.log(14. *72.)
# with pytest.raises(AssertionError):
# assert expected_result == result
assert pytest.approx(expected_result, 1e-6) == result

def test_test_negative():
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(-1, 23.)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(5, -23.)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(0, 2.)
with pytest.raises(FloatingPointError):
magic_python.my_magic_function(7, 0.)
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = ["setuptools>=60", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
testpaths = [
"magic_python/tests",
]
23 changes: 23 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[metadata]
name = magic_python
version = 0.0.0
description = A test python module to introduce automated workflow
long_description = file: README.md
long_description_content_type = text/markdown
author = Ludwig Schneider
url = https://github.com/InnocentBug/workflow-tutorial
license = MIT
license_files = LICENSE
platforms = any
classifiers =
Development Status :: 3 - Alpha
Topic :: Scientific/Engineering
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7

[options]
packages = find:
python_requires = >=3.7
include_package_data = True
install_requires = numpy>=1.16
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup

if __name__ == "__main__":
setup()