Skip to content

Commit

Permalink
test with pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
naaci committed Jun 20, 2023
1 parent 4204786 commit aca64d4
Show file tree
Hide file tree
Showing 73 changed files with 430 additions and 345 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test-with-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pytest

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
# with:
# python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy scipy pywavelets fpdf pillow simplejpeg scikit-image tifffile
pip install pytest
- name: Run tests
run: |
pytest tests/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
**/__pycache__/*.pyc
tests/results/*
34 changes: 0 additions & 34 deletions Ambadekar2019.py

This file was deleted.

16 changes: 0 additions & 16 deletions _test_with_random_matrix.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![DOI](https://zenodo.org/badge/444999271.svg)](https://zenodo.org/badge/latestdoi/444999271)
[![Pytest](https://github.com/naaci/watermarking/actions/workflows/test-with-latest.yml/badge.svg)](https://github.com/naaci/watermarking/actions/workflows/test-with-latest.yml)

# watermarking
Implementations of some digital image watermarking schemes for grayscale images proposed by various authors.
Expand Down
39 changes: 4 additions & 35 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
## Welcome to GitHub Pages
[![DOI](https://zenodo.org/badge/444999271.svg)](https://zenodo.org/badge/latestdoi/444999271)

You can use the [editor on GitHub](https://github.com/naaci/Digital-Image-Watermarking/edit/PhD/docs/index.md) to maintain and preview the content for your website in Markdown files.
# watermarking
Implementations of some digital image watermarking schemes for grayscale images proposed by various authors.

Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.

### Markdown

Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for

```markdown
Syntax highlighted code block

# Header 1
## Header 2
### Header 3

- Bulleted
- List

1. Numbered
2. List

**Bold** and _Italic_ and `Code` text

[Link](url) and ![Image](src)
```

For more details see [Basic writing and formatting syntax](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).

### Jekyll Themes

Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/naaci/Digital-Image-Watermarking/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file.

### Support or Contact

Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out.
Each module defines a class named `watermarking` with two methods namely `add_watermark` and `extract_watermark`. Some modules `watermarking` class has additional method `extract_watermarks`.
Empty file added tests/__init__.py
Empty file.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
53 changes: 53 additions & 0 deletions tests/test_with_random_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys
from importlib import import_module
from pathlib import Path

from numpy import asarray, isclose, random

cwd = Path(__file__).parent.parent / "watermarking"
sys.path.append(str(cwd))


def _test_watermark(watermarker):
if hasattr(watermarker, "SQUARE_IMAGE_ONLY"):
host = random.random((64, 64))
else:
host = random.random((64, 512))

watermark = random.random(
asarray(host.shape) // watermarker.IMAGE_TO_WATERMARK_RATIO
)

if hasattr(watermarker, "BINARY_WATERMARK"):
watermark[watermark >= 0.5] = 1
watermark[watermark < 0.5] = 0

watermarked = watermarker.add_watermark(host, watermark)
watermark_ = watermarker.extract_watermark(watermarked)
assert isclose(watermark, watermark_).all(), watermarker.__module__

# c = isclose(watermark, watermark_)
# print("Watermarking Test result:")
# print("method:".ljust(10), Watermarker.__module__)
# print("max err:".ljust(10), abs(watermark - watermark_).max())
# print("isclose:".ljust(10), f"{watermark[c].size / watermark.size:>.2%}")


def test_watermarks():
for module in cwd.iterdir():
if (
module.name.startswith(".")
or module.name.startswith("_")
or module.is_dir()
or not module.name.endswith(".py")
):
continue
module = module.name.removesuffix(".py")
print(module)

watermarker = import_module(module).Watermarker(0.01)
_test_watermark(watermarker)


if __name__ == "__main__":
test_watermarks()
Loading

0 comments on commit aca64d4

Please sign in to comment.