Skip to content

Commit

Permalink
Added test template to be used for pytest unittesting
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashAkbarinia committed Dec 13, 2023
1 parent 7aa0b6b commit 46b8107
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package
name: build

on:
push:
Expand All @@ -13,6 +13,8 @@ jobs:
build:

runs-on: ubuntu-latest
env:
MODULE_NAME: osculari
strategy:
fail-fast: false
matrix:
Expand All @@ -37,7 +39,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest --doctest-modules --ignore=$MODULE_NAME/tests $MODULE_NAME
pytest
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ build-backend = "setuptools.build_meta"
[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
version = {attr = "osculari.__version__"}
readme = {file = ["README.md"], content-type = "text/markdown"}
readme = {file = ["README.md"], content-type = "text/markdown"}

[tool.setuptools.dynamic.optional-dependencies]
dev = {file = "requirements-dev.txt"}

[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
"--color=yes"
]
testpaths = ["tests"]
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
39 changes: 39 additions & 0 deletions tests/datasets/imutils_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Unit tests for imutils_test.py
"""

import numpy as np
import pytest

from osculari.datasets import imutils


@pytest.fixture
def sample_image():
"""Create a sample grayscale image for testing"""
return np.array([[50, 100, 150],
[75, 125, 175],
[100, 150, 200]], dtype='uint8')


def test_michelson_contrast_valid_input(sample_image):
contrast_factor = 0.5
result = imutils.michelson_contrast(sample_image, contrast_factor)

# Ensure that the output has the same shape as the input
assert result.shape == sample_image.shape

# Ensure that the output is a NumPy array
assert isinstance(result, np.ndarray)

# Ensure that the contrast is applied correctly
expected_result = np.array([[108, 120, 133],
[114, 126, 139],
[120, 133, 145]], dtype='uint8')
np.testing.assert_almost_equal(result, expected_result)


def test_michelson_contrast_invalid_contrast():
with pytest.raises(AssertionError):
contrast_factor = 1.5 # Invalid contrast value
imutils.michelson_contrast(np.array([[1, 2], [3, 4]]), contrast_factor)

0 comments on commit 46b8107

Please sign in to comment.