Skip to content

Commit

Permalink
test: update validator usage in unit tests, remove fspath
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Jan 15, 2025
1 parent 711dc61 commit 77d16d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 3 additions & 2 deletions providers/base/bin/camera_test_auto_gst_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def validate_image_dimensions(

try:
info = self.discoverer.discover_uri(
"file://{}".format(os.fspath(image_file_path))
"file://{}".format(str(image_file_path))
)
except (GLib.GError, GLib.Error) as e:
logger.error(
Expand Down Expand Up @@ -96,7 +96,7 @@ def validate_video_info(

try:
info = self.discoverer.discover_uri(
"file://{}".format(os.fspath(video_file_path))
"file://{}".format(str(video_file_path))
)
except (GLib.GError, GLib.Error) as e:
logger.error(
Expand Down Expand Up @@ -375,6 +375,7 @@ def main() -> int:
),
)

# conditionally enter the temp file context
with ExitStack() as stack:
if not (hasattr(args, "path") and args.path):
tmp_dir = stack.enter_context(
Expand Down
29 changes: 13 additions & 16 deletions providers/base/tests/test_camera_test_auto_gst_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from os import fspath
import unittest as ut
from unittest.mock import MagicMock, call, patch
from shlex import split as sh_split
Expand Down Expand Up @@ -86,10 +85,8 @@ def test_image_validator(
mock_pbutils, expected_width, expected_height
)

validator = CTAGS.MediaValidator()

self.assertTrue(
validator.validate_image_dimensions(
CTAGS.MediaValidator().validate_image_dimensions(
Path("some/path"),
expected_height=expected_height,
expected_width=expected_width,
Expand All @@ -101,7 +98,7 @@ def test_image_validator(
self._make_mock_video_info(mock_pbutils, bad_width, bad_height)

self.assertFalse(
validator.validate_image_dimensions(
CTAGS.MediaValidator().validate_image_dimensions(
Path("some/path"),
expected_height=expected_height,
expected_width=expected_width,
Expand Down Expand Up @@ -151,8 +148,7 @@ def test_video_validator(
expected_duration,
)
mock_isfile.return_value = True
validator = CTAGS.MediaValidator()
result = validator.validate_video_info(
result = CTAGS.MediaValidator().validate_video_info(
Path("some/path"),
expected_width=expected_width,
expected_height=expected_height,
Expand All @@ -176,7 +172,7 @@ def test_video_validator(
)

mock_gst.SECOND = 1
result = validator.validate_video_info(
result = CTAGS.MediaValidator().validate_video_info(
Path("some/path"),
expected_width=expected_width,
expected_height=expected_height,
Expand Down Expand Up @@ -216,7 +212,7 @@ def test_video_validator(

mock_isfile.return_value = False

result = validator.validate_video_info(
result = CTAGS.MediaValidator().validate_video_info(
Path("some/path"),
expected_width=expected_width,
expected_height=expected_height,
Expand Down Expand Up @@ -277,7 +273,7 @@ def test_encoding_arg_group(
)
self.assertIn(
CTAGS.ENCODING_PROFILES["mp4_h264"]["file_extension"],
fspath(last_called_args["file_path"]),
str(last_called_args["file_path"]),
)

file_ext = "ext"
Expand All @@ -296,7 +292,7 @@ def test_encoding_arg_group(
)
self.assertIn(
file_ext,
fspath(last_called_args["file_path"]),
str(last_called_args["file_path"]),
)

encoding_str = "video/something, str"
Expand All @@ -316,7 +312,7 @@ def test_encoding_arg_group(
)
self.assertIn(
file_ext,
fspath(last_called_args["file_path"]),
str(last_called_args["file_path"]),
)

with patch(
Expand Down Expand Up @@ -357,7 +353,7 @@ class GError(BaseException):
import camera_test_auto_gst_source as CTAGS

self.assertFalse(
CTAGS.MediaValidator.validate_image_dimensions(
CTAGS.MediaValidator().validate_image_dimensions(
Path("some/path"),
expected_height=1,
expected_width=1,
Expand All @@ -369,7 +365,7 @@ class GError(BaseException):
)

self.assertFalse(
CTAGS.MediaValidator.validate_video_info(
CTAGS.MediaValidator().validate_video_info(
Path("some/path"),
expected_height=1,
expected_width=1,
Expand All @@ -395,9 +391,10 @@ def _make_mock_video_info(
video_info = MagicMock()
if duration is not None:
video_info.get_duration.return_value = duration
mock_pbutils.Discoverer.return_value = MagicMock()
mock_discoverer = MagicMock()
mock_pbutils.Discoverer.return_value = mock_discoverer

mock_pbutils.Discoverer().discover_uri.return_value = video_info
mock_discoverer.discover_uri.return_value = video_info
video_stream = MagicMock()
video_stream.get_width.return_value = width
video_stream.get_height.return_value = height
Expand Down

0 comments on commit 77d16d0

Please sign in to comment.