Skip to content

Commit

Permalink
Add manifest and format by black
Browse files Browse the repository at this point in the history
  • Loading branch information
baconYao committed Apr 18, 2024
1 parent 997092d commit 7cda806
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, args: Any, scenarios: dict):
self._args = args
self._resource_items = []

def _gst_v4l2_video_decoder_md5_checksum_comparison_helper(
def _v4l2_video_decoder_md5_checksum_comparison_helper(
self,
decoder_plugin: str,
width: dict,
Expand Down Expand Up @@ -122,17 +122,19 @@ def gst_v4l2_video_decoder_md5_checksum_comparison(
self, scenario_data: List[Dict]
) -> None:
for item in scenario_data:
self._resource_items.extend([
self._gst_v4l2_video_decoder_md5_checksum_comparison_helper(
decoder_plugin=item["decoder_plugin"],
width=resolution["width"],
height=resolution["height"],
color_space=color_space,
source_format=item["source_format"],
)
for resolution in item["resolutions"]
for color_space in item["color_spaces"]
])
self._resource_items.extend(
[
self._v4l2_video_decoder_md5_checksum_comparison_helper(
decoder_plugin=item["decoder_plugin"],
width=resolution["width"],
height=resolution["height"],
color_space=color_space,
source_format=item["source_format"],
)
for resolution in item["resolutions"]
for color_space in item["color_spaces"]
]
)

def main(self):
for scenario in self._scenarios:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
import io
import unittest
from unittest.mock import patch, mock_open, MagicMock, call
from gst_resources_generator import (
load_json_config,
GstResources
)
from gst_resources_generator import load_json_config, GstResources


class TestLoadJsonConfig(unittest.TestCase):
@patch('pathlib.Path.exists')
@patch('pathlib.Path.open', new_callable=mock_open)
@patch('json.load')
@patch("pathlib.Path.exists")
@patch("pathlib.Path.open", new_callable=mock_open)
@patch("json.load")
def test_load_json_config(
self,
mock_json_load,
mock_open,
mock_path_exists
self, mock_json_load, mock_open, mock_path_exists
):
mock_path_exists.return_value = True
mock_json_load.return_value = {'key': 'value'}
mock_json_load.return_value = {"key": "value"}
json_path = "/fake.json"
data = load_json_config(json_path)
mock_path_exists.assert_called_once_with()
mock_open.assert_called_once_with('r')
mock_open.assert_called_once_with("r")
mock_json_load.assert_called_once_with(
mock_open.return_value.__enter__.return_value)
self.assertEqual(data, {'key': 'value'})
mock_open.return_value.__enter__.return_value
)
self.assertEqual(data, {"key": "value"})

@patch('pathlib.Path.open', new_callable=mock_open)
@patch('pathlib.Path.exists')
@patch("pathlib.Path.open", new_callable=mock_open)
@patch("pathlib.Path.exists")
def test_load_json_config_file_not_found(self, mock_exists, mock_open):
mock_exists.return_value = False
with self.assertRaises(FileNotFoundError):
load_json_config('/fake.json')
load_json_config("/fake.json")
mock_open.assert_not_called()


Expand All @@ -52,31 +47,29 @@ def test_gst_v4l2_video_decoder_md5_checksum_comparison_helper(self):
"height": 1080,
"color_space": "rgb",
"golden_sample_file": (
"/fake-path/video_golden_samples"
"/1920x1080-plugin1-rgb.mp4"
"/fake-path/video_golden_samples" "/1920x1080-plugin1-rgb.mp4"
),
"golden_md5_checkum_file": (
"/fake-path/scenario1/"
"golden_md5_checksum/platform_conf/1920x1080-plugin1-rgb.md5"
)
),
}

result = ins._gst_v4l2_video_decoder_md5_checksum_comparison_helper(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="rgb",
source_format="mp4"
source_format="mp4",
)

self.assertEqual(result, expected_result)

@patch.object(
GstResources,
'_gst_v4l2_video_decoder_md5_checksum_comparison_helper')
GstResources, "_gst_v4l2_video_decoder_md5_checksum_comparison_helper"
)
def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_color_space(
self,
mock_helper
self, mock_helper
):
args = MagicMock()
ins = GstResources(args, {})
Expand All @@ -86,35 +79,36 @@ def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_color_space(
"decoder_plugin": "plugin1",
"resolutions": [{"width": 1920, "height": 1080}],
"color_spaces": ["rgb", "yuv"],
"source_format": "mp4"
"source_format": "mp4",
}
]

ins.gst_v4l2_video_decoder_md5_checksum_comparison(scenario_data)

mock_helper.assert_has_calls([
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="rgb",
source_format="mp4"
),
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="yuv",
source_format="mp4"
)
])
mock_helper.assert_has_calls(
[
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="rgb",
source_format="mp4",
),
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="yuv",
source_format="mp4",
),
]
)

@patch.object(
GstResources,
'_gst_v4l2_video_decoder_md5_checksum_comparison_helper')
GstResources, "_gst_v4l2_video_decoder_md5_checksum_comparison_helper"
)
def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_resolutions(
self,
mock_helper
self, mock_helper
):
args = MagicMock()
ins = GstResources(args, {})
Expand All @@ -124,38 +118,39 @@ def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_resolutions(
"decoder_plugin": "plugin1",
"resolutions": [
{"width": 320, "height": 320},
{"width": 1920, "height": 1080}
{"width": 1920, "height": 1080},
],
"color_spaces": ["NV12"],
"source_format": "mp4"
"source_format": "mp4",
}
]

ins.gst_v4l2_video_decoder_md5_checksum_comparison(scenario_data)

mock_helper.assert_has_calls([
call(
decoder_plugin="plugin1",
width=320,
height=320,
color_space="NV12",
source_format="mp4"
),
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="NV12",
source_format="mp4"
)
])
mock_helper.assert_has_calls(
[
call(
decoder_plugin="plugin1",
width=320,
height=320,
color_space="NV12",
source_format="mp4",
),
call(
decoder_plugin="plugin1",
width=1920,
height=1080,
color_space="NV12",
source_format="mp4",
),
]
)

@patch.object(
GstResources,
'_gst_v4l2_video_decoder_md5_checksum_comparison_helper')
GstResources, "_gst_v4l2_video_decoder_md5_checksum_comparison_helper"
)
def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_decoders(
self,
mock_helper
self, mock_helper
):
args = MagicMock()
ins = GstResources(args, {})
Expand All @@ -167,46 +162,45 @@ def test_gst_v4l2_video_decoder_md5_checksum_comparison_multi_decoders(
{"width": 320, "height": 320},
],
"color_spaces": ["NV12"],
"source_format": "mp4"
"source_format": "mp4",
},
{
"decoder_plugin": "plugin2",
"resolutions": [
{"width": 3840, "height": 2160},
],
"color_spaces": ["ABC"],
"source_format": "webm"
}
"source_format": "webm",
},
]

ins.gst_v4l2_video_decoder_md5_checksum_comparison(scenario_data)

mock_helper.assert_has_calls([
call(
decoder_plugin="plugin1",
width=320,
height=320,
color_space="NV12",
source_format="mp4"
),
call(
decoder_plugin="plugin2",
width=3840,
height=2160,
color_space="ABC",
source_format="webm"
)
])

@patch('sys.stdout', new_callable=io.StringIO)
mock_helper.assert_has_calls(
[
call(
decoder_plugin="plugin1",
width=320,
height=320,
color_space="NV12",
source_format="mp4",
),
call(
decoder_plugin="plugin2",
width=3840,
height=2160,
color_space="ABC",
source_format="webm",
),
]
)

@patch("sys.stdout", new_callable=io.StringIO)
def test_dump_resources(self, mock_stdout):
args = MagicMock()
ins = GstResources(args, {})
ins._resource_items = [
{
"key1": "value1",
"foo1": "bar1"
},
{"key1": "value1", "foo1": "bar1"},
{
"key2": "value2",
"foo2": "bar2",
Expand All @@ -218,11 +212,12 @@ def test_dump_resources(self, mock_stdout):

expected_output = (
"key1: value1\nfoo1: bar1\n\n"
"key2: value2\nfoo2: bar2\ngood2: bad2\n\n\n")
"key2: value2\nfoo2: bar2\ngood2: bad2\n\n\n"
)

self.assertEqual(mock_stdout.getvalue(), expected_output)
self.assertEqual(ins._resource_items, [])


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 7cda806

Please sign in to comment.