Skip to content

Commit

Permalink
fix #155 (#156)
Browse files Browse the repository at this point in the history
* fix #155

* Update pyorc-test.yml because of lazy_fixtures bug

* raise cli test coverage #155

* Update tests.yml for OpenCV dependencies

* Update tests.yml added apt update

* Update tests.yml correction libegl1

* remove axes swap test #155

* bumping version #155
  • Loading branch information
hcwinsemius authored Mar 25, 2024
1 parent 5eda03b commit ff263c4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ jobs:
run: |
conda info
conda list
- name: OpenCV dependencies
run: |
sudo apt update
sudo apt install libegl1 libopengl0 -y
- name: Test
run: python -m pytest --verbose --cov=pyorc --cov-report xml

Expand Down
2 changes: 1 addition & 1 deletion envs/pyorc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- numba
- opencv
- pip
- pytest
- pytest<8.0.0 # due to temporary problem with lazy_fixtures, see https://github.com/pytest-dev/pytest/issues/11890
- pytest-cov
- pytest-benchmark
- pytest-lazy-fixture
Expand Down
2 changes: 1 addition & 1 deletion pyorc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.3"
__version__ = "0.5.4"
from .api.cameraconfig import CameraConfig, load_camera_config, get_camera_config
from .api.video import Video
from .api.frames import Frames
Expand Down
4 changes: 2 additions & 2 deletions pyorc/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ def validate_dst(value):
# assume [x, y] pairs are provided
len_points = 2
elif len(value) < 6:
raise click.UsageError(f"--dst must contain at least 2 or 4 with [x, y] or 6 with [x, y, z] points, contains {len(value)}.")
raise click.UsageError(f"--dst must contain exactly 2 or 4 with [x, y], or at least 6 with [x, y, z] points, contains {len(value)}.")
else:
len_points = 3
for n, val in enumerate(value):
assert(isinstance(val, list)), f"--dst value {n} is not a list {val}"
assert(len(val) == len_points), f"--src value {n} must contain row, column coordinate but consists of {len(val)} numbers"
assert(len(val) == len_points), f"--dst value {n} must contain 3 coordinates (x, y, z) but consists of {len(val)} numbers, value is {val}"
return value

def validate_recipe(recipe):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="pyopenrivercam",
description="pyopenrivercam (pyorc) is a front and backend to control river camera observation locations",
version="0.5.3",
version="0.5.4",
long_description=readme + "\n\n",
long_description_content_type="text/markdown",
url="https://github.com/localdevices/pyorc",
Expand Down Expand Up @@ -70,8 +70,9 @@
"Topic :: Scientific/Engineering :: Image Processing",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords="hydrology, hydrometry, river-flow, pyorc",
)
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def cli_cam_config_output():
# remove after test
# os.remove(cam_config_fn)

@pytest.fixture
def cli_click_event(mocker):
event_props = {
"xdata": 5,
"ydata": 5,

}
event = backend_bases.MouseEvent(
name="click", canvas=pyplot.axes(), x=5, y=5,
)

# mocker.patch(
# "matplotlib.backend_bases.MouseEvent",
# return_value=event_props
# )
return event

@pytest.fixture
def gcps_src():
Expand Down
44 changes: 38 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path

from click.testing import CliRunner
from matplotlib import backend_bases

import pyorc.service
from pyorc.cli.main import cli
Expand All @@ -27,8 +28,8 @@ def test_cli_cam_config_video(cli_obj, vid_file, gcps_src, gcps_dst, lens_positi
'camera-config',
'-V',
vid_file,
'--src',
json.dumps(gcps_src),
# '--src',
# json.dumps(gcps_src),
'--dst',
json.dumps(gcps_dst),
'--crs',
Expand Down Expand Up @@ -115,8 +116,17 @@ def test_gcps_interact(gcps_dst, frame_rgb):
dst = gcps_dst
selector = GcpSelect(frame_rgb, dst, crs=crs)
# uncomment below to test the interaction, not suitable for automated unit test
plt.show(block=True)

# plt.show(block=True)
# make a click event for testing callbacks
event = backend_bases.MouseEvent(
name="click", canvas=selector.fig.canvas, x=5, y=5,
)
selector.on_press(event)
selector.on_move(event)
selector.on_click(event)
selector.on_left_click(event)
selector.on_right_click(event)
selector.on_release(event)


def test_aoi_interact(frame_rgb, cam_config_without_aoi):
Expand All @@ -131,14 +141,36 @@ def test_aoi_interact(frame_rgb, cam_config_without_aoi):
selector = AoiSelect(frame_rgb, src, dst, cam_config_without_aoi)
# uncomment below to test the interaction, not suitable for automated unit test
# plt.show(block=True)
# make a click event for testing callbacks
event = backend_bases.MouseEvent(
name="click", canvas=selector.fig.canvas, x=5, y=5,
)
selector.on_press(event)
selector.on_move(event)
selector.on_click(event)
selector.on_left_click(event)
selector.on_right_click(event)
selector.on_release(event)


def test_stabilize_interact(frame_rgb):
import matplotlib.pyplot as plt
selector = StabilizeSelect(frame_rgb)
event = backend_bases.MouseEvent(
name="click", canvas=selector.fig.canvas, x=5, y=5,
)

selector.on_press(event)
selector.on_move(event)
selector.on_click(event)
selector.on_left_click(event)
selector.on_right_click(event)
selector.on_release(event)
selector.on_close(event)
selector.close_window(event)
# uncomment below to test the interaction, not suitable for automated unit test
# plt.show(block=True)

# cli utils

def test_read_shape(gcps_fn):
coords, wkt = cli_utils.read_shape(gcps_fn)
assert(isinstance(wkt, str))
Expand Down

0 comments on commit ff263c4

Please sign in to comment.