Skip to content

Commit

Permalink
test auto badges
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclifford1 committed Oct 9, 2024
1 parent 416cf0f commit 881ff67
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
IQM_Vis/examples/*
2 changes: 1 addition & 1 deletion IQM_Vis/UI/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class get_range_results_worker(QObject):

@pyqtSlot(dict)
def do_work(self, data):
t0 = time.time()
# t0 = time.time()

metric_over_range_results = []
max_val = 0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| Installation | [![Generic badge](https://img.shields.io/badge/INSTALL-View-green.svg)](https://mattclifford1.github.io/IQM-Vis/getting_started.html) |
| Tutorials | [![Generic badge](https://img.shields.io/badge/TUTORIALS-View-blue.svg)](https://mattclifford1.github.io/IQM-Vis/Tutorials.html) |
| Demos | [![Generic badge](https://img.shields.io/badge/HuggingFaceSpace-Launch-red.svg)](https://huggingface.co/spaces/mattclifford1/IQM-VIS) |

| Tests | [![Generic badge](./tests/reports/tests_badge.svg)](./tests) [![Generic badge](./tests/reports/coverage_badge.svg)](./tests) |


# IQM-Vis
Expand Down
2 changes: 2 additions & 0 deletions dev_resources/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ pydata-sphinx-theme
sphinx-book-theme
cloud-sptheme
Jinja2==3.0
genbadge
packaging
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
; addopts = --maxfail=3 --tb=short -p no:xdist -s
qt_api=pyqt6
addopts=--forked
addopts=--forked --cov=IQM_Vis --junitxml=tests/reports/junit/junit.xml
; --numprocesses=auto
8 changes: 8 additions & 0 deletions scripts/pytest_and_badges.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/bash
# Author: Matt Clifford <[email protected]>
# License: BSD 3-Clause License

pytest
genbadge tests --input-file tests/reports/junit/junit.xml --output-file tests/reports/tests_badge.svg
coverage xml -o tests/reports/coverage/coverage.xml
genbadge coverage --input-file tests/reports/coverage/coverage.xml --output-file tests/reports/coverage_badge.svg
82 changes: 82 additions & 0 deletions tests/UI/test_sliders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Author: Matt Clifford <[email protected]>
# License: BSD 3-Clause License

import pytest
from PyQt6 import QtTest, QtWidgets, QtCore
from pytestqt.plugin import QtBot
import IQM_Vis


def get_UI():
image1 = IQM_Vis.examples.images.IMAGE1
image2 = IQM_Vis.examples.images.IMAGE2
images = [image1, image2]

MAE = IQM_Vis.metrics.MAE()
MSE = IQM_Vis.metrics.MSE()
SSIM = IQM_Vis.metrics.SSIM()

metrics = {'MAE': MAE,
'MSE': MSE,
'1-SSIM': SSIM}

MSE_image = IQM_Vis.metrics.MSE(return_image=True)
SSIM_image = IQM_Vis.metrics.SSIM(return_image=True)
metric_images = {'MSE': MSE_image,
'1-SSIM': SSIM_image}

rotation = IQM_Vis.transforms.rotation
blur = IQM_Vis.transforms.blur
brightness = IQM_Vis.transforms.brightness
jpeg_compression = IQM_Vis.transforms.jpeg_compression

transformations = {
# normal input
'rotation': {'min': -180, 'max': 180, 'function': rotation},
# only odd ints since it's a kernel
'blur': {'min': 1, 'max': 41, 'function': blur, 'normalise': 'odd'},
# float values
'brightness': {'min': -1.0, 'max': 1.0, 'function': brightness},
# non zero inital value
'jpg comp.': {'min': 1, 'max': 100, 'function': jpeg_compression, 'init_value': 100},
}

test_app = IQM_Vis.make_UI(transformations=transformations,
image_list=images,
metrics=metrics,
metric_images=metric_images,
test=True)
return test_app


# building and closing function of UI for testing
@pytest.fixture(scope='function')
def build_IQM_Vis():
# QtTest.QTest.qWait(5000)
# Setup
test_window = get_UI()
qtbotbis = QtBot(test_window.window)

yield test_window, qtbotbis

# Clean up
QtTest.QTest.qWait(100)

# need to handle the closing dialog
def handle_dialog():
messagebox = QtWidgets.QApplication.activeWindow()
yes_button = messagebox.button(
QtWidgets.QMessageBox.StandardButton.Yes)
qtbotbis.mouseClick(
yes_button, QtCore.Qt.MouseButton.LeftButton, delay=1)

QtCore.QTimer.singleShot(100, handle_dialog)

# test_window.window.quit()
test_window.window.main.close()
# QtTest.QTest.qWait(5000)


def test_sliders(build_IQM_Vis):
test_window, qtbotbis = build_IQM_Vis
assert test_window.showing == True
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def get_UI():
image1 = IQM_Vis.examples.images.IMAGE1
image2 = IQM_Vis.examples.images.IMAGE2
images = [image1, image2]
print(f'Images files: {images}')

MAE = IQM_Vis.metrics.MAE()
MSE = IQM_Vis.metrics.MSE()
Expand Down
21 changes: 20 additions & 1 deletion tests/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Testing
We test the install using pytest and simulate user interaction with the plugin pytest-qt, all addional dependancies can be found under dev_resources/requirements-dev.txt

To run all tests and make badges automatically use the bash script
```
./scripts/pytest_and_badges.sh
```
Other wise refer below for running the individual steps


## Running tests
It is important to run all tests on a separate process to avoid conflicts. We do this using pytest-forked by:
```
Expand All @@ -12,11 +19,23 @@ If you want to speed it up with multiprocessing use
pytest --forked --numprocesses=auto
```

If you want a coverage report use:
If you want a coverage report use (this should happen automatically though):
```
pytest --forked --cov=IQM_Vis
```

## Badges
To generate the test success report badge use
```
genbadge tests --input-file tests/reports/junit/junit.xml --output-file tests/reports/tests_badge.svg
```

To get the coverage badge use
```
coverage xml -o tests/reports/coverage/coverage.xml
genbadge coverage --input-file tests/reports/coverage/coverage.xml--output-file tests/reports/coverage_badge.svg
```

## Linux (Ubuntu 22.04 and 24.04)
If you are having issues with the tests not running/hanging then try to use XOrg display server instead of Wayland (default for many distros without Nvidia GPU). To do this, log out and when you log in again click the gear icon in the bottom right on the screen and select XOrg instead of default/wayland.

Expand Down
1 change: 1 addition & 0 deletions tests/reports/coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/reports/junit/junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="13" time="19.434" timestamp="2024-10-09T11:25:38.954759" hostname="Dell-5320"><testcase classname="tests.test_metrics" name="test_all_metrics_initialise" time="0.221" /><testcase classname="tests.test_metrics" name="test_all_metrics_images_initialise" time="0.236" /><testcase classname="tests.test_metrics" name="test_all_metrics_process_image" time="1.950" /><testcase classname="tests.test_metrics" name="test_all_metric_images_process_image" time="0.251" /><testcase classname="tests.test_transforms" name="test_all_transforms_init_value_no_change_image" time="0.237" /><testcase classname="tests.test_transforms" name="test_all_transforms_min_max_specified" time="0.234" /><testcase classname="tests.test_transforms" name="test_all_transforms_min_change_image" time="0.269" /><testcase classname="tests.test_transforms" name="test_all_transforms_max_change_image" time="0.328" /><testcase classname="tests.UI.test_sliders" name="test_sliders" time="1.310" /><testcase classname="tests.notebook_examples.test_1_making_the_UI" name="test_build_1" time="1.030" /><testcase classname="tests.notebook_examples.test_2_simple_customisation" name="test_build_2" time="1.180" /><testcase classname="tests.notebook_examples.test_3_customisation_details" name="test_3" time="3.010" /><testcase classname="tests.notebook_examples.test_4_experiment" name="test_experiment_runs" time="6.186" /></testsuite></testsuites>
1 change: 1 addition & 0 deletions tests/reports/tests_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 881ff67

Please sign in to comment.