diff --git a/providers/base/bin/camera_test_auto_gst_source.py b/providers/base/bin/camera_test_auto_gst_source.py index 4d9cb5bb84..a3a7bd3b25 100755 --- a/providers/base/bin/camera_test_auto_gst_source.py +++ b/providers/base/bin/camera_test_auto_gst_source.py @@ -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( @@ -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( @@ -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( diff --git a/providers/base/tests/test_camera_test_auto_gst_source.py b/providers/base/tests/test_camera_test_auto_gst_source.py index 2aecd14764..c45cef1c15 100644 --- a/providers/base/tests/test_camera_test_auto_gst_source.py +++ b/providers/base/tests/test_camera_test_auto_gst_source.py @@ -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 @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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" @@ -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" @@ -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( @@ -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, @@ -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, @@ -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