Skip to content

Commit

Permalink
test: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Jan 8, 2025
1 parent 1cd3bcd commit 7e32164
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion providers/base/bin/camera_test_auto_gst_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def validate_image_dimensions(
)
except (GLib.GError, GLib.Error) as e:
logger.error(
"Encountered an error when attempting to read {}.".format(
"Encountered an error when attempting to read {}. ".format(
image_file_path
)
+ str(e) # cleaner message is in e.message
Expand Down
34 changes: 29 additions & 5 deletions providers/base/tests/test_camera_test_auto_gst_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,30 +335,54 @@ def test_encoding_arg_group(
@patch("os.path.isfile")
@patch("camera_test_auto_gst_source.GstPbutils")
@patch("camera_test_auto_gst_source.GLib")
@patch("camera_test_auto_gst_source.logger")
def test_handle_glib_errors(
self,
mock_logger: MagicMock,
mock_glib: MagicMock,
mock_pbutils: MagicMock,
mock_isfile: MagicMock,
):
mock_glib.GError = Exception
class GError(BaseException):
pass

mock_glib.GError = GError
mock_glib.Error = GError
mock_isfile.return_value = True
mock_discoverer = MagicMock()
mock_discoverer.name = "bruh"
mock_pbutils.Discoverer.return_value = mock_discoverer
mock_discoverer.discover_uri.side_effect = Exception()
mock_discoverer.discover_uri.side_effect = GError("some message")

import camera_test_auto_gst_source as CTAGS

self.assertRaises(
Exception,
lambda: CTAGS.MediaValidator.validate_image_dimensions(
self.assertFalse(
CTAGS.MediaValidator.validate_image_dimensions(
Path("some/path"),
expected_height=1,
expected_width=1,
),
)

mock_logger.error.assert_called_with(
"Encountered an error when attempting to read some/path. some message"
)

self.assertFalse(
CTAGS.MediaValidator.validate_video_info(
Path("some/path"),
expected_height=1,
expected_width=1,
duration_tolerance_seconds=1,
expected_duration_seconds=1,
expected_fps=1,
),
)

mock_logger.error.assert_called_with(
"Encountered an error when attempting to read some/path. some message"
)

def _make_mock_video_info(
self,
mock_pbutils: MagicMock,
Expand Down

0 comments on commit 7e32164

Please sign in to comment.