-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test workflow * Add test directory * Alpha test for Container * Bump version to 1.1.0 * Add Container test * Update docstring on container.py * Update docstring on block.py * Add default precision to Block.compute_xx() * Update Block.compute_pca * Prevents ZeroDivisionError on Block * Add Block test * Update the return value of ImageObject.is_valid()
- Loading branch information
1 parent
37cc1b6
commit ba112ff
Showing
8 changed files
with
122 additions
and
14 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,40 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Python application | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
cd src | ||
pytest |
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,28 @@ | ||
from pimage.block import Block | ||
from PIL import Image | ||
|
||
rgb_image = Image.new(mode="RGB", size=(64, 64)) | ||
grayscale_image = Image.new(mode="L", size=(64, 64)) | ||
|
||
|
||
def test_block_initiate(): | ||
block = Block(grayscale_image, rgb_image, 10, 20, 32) | ||
assert block.block_dimension == 32 | ||
assert block.coordinate == (10, 20) | ||
|
||
|
||
def test_block_compute_pca(): | ||
block = Block(grayscale_image, rgb_image, 10, 20, 32) | ||
result = block.compute_pca() | ||
assert isinstance(result, list) | ||
assert len(result) == 64 | ||
assert result[0] == 1.0 | ||
assert result[1] == 0.0 | ||
|
||
|
||
def test_block_compute_characteristic_feature(): | ||
block = Block(grayscale_image, rgb_image, 10, 20, 32) | ||
result = block.compute_characteristic_features() | ||
assert isinstance(result, list) | ||
assert len(result) == 7 | ||
assert result == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] |
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,27 @@ | ||
from pimage.container import Container | ||
|
||
|
||
def test_container_initiate(): | ||
container = Container() | ||
assert container.get_length() == 0 | ||
|
||
|
||
def test_container_add(): | ||
container = Container() | ||
container.append_block(((0, 1), [0, 1, 2], [3, 4, 5])) | ||
assert container.get_length() == 1 | ||
|
||
|
||
def test_container_sort_feature(): | ||
container = Container() | ||
container.append_block(((0, 3), [1, 2, 3], [4, 5, 7])) | ||
container.append_block(((0, 2), [1, 2, 3], [4, 5, 6])) | ||
container.append_block(((0, 1), [0, 1, 2], [3, 4, 5])) | ||
|
||
container.sort_by_features() | ||
assert container.get_length() == 3 | ||
assert container.container == [ | ||
((0, 1), [0, 1, 2], [3, 4, 5]), | ||
((0, 2), [1, 2, 3], [4, 5, 6]), | ||
((0, 3), [1, 2, 3], [4, 5, 7]) | ||
] |