Skip to content

Commit

Permalink
[VCQ-101] Remove redundant whitespace from commands when asserting eq…
Browse files Browse the repository at this point in the history
…uivalent commands
  • Loading branch information
nilfm99 authored and nilfm committed Jul 31, 2023
1 parent 274a88f commit 7a1f14f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion python/vmaf/tools/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,27 @@ def replace_root(command_line: str, root: str) -> str:
return re.sub(root, '[ROOT]', command_line)


def remove_redundant_whitespace(command_line: str) -> str:
"""
Replaces multiple whitespace between words with a single one, and removes redundant whitespace at the start and end
>>> remove_redundant_whitespace(' a b c d e f ')
'a b c d e f'
>>> remove_redundant_whitespace('cat /opt/project/vmaf/workspace/workdir/9e693ccc-7706-49c5-8c8e-40f5242e81a6/dis_test_0_0_seeking_10_288_375_notyuv_lanczos_accurate_rnd_10to14_prece_FFmpegDecoder_postunsharpunsharp_q_480x360_PostDecode_tmp/pixfmt/* > /opt/project/vmaf/workspace/workdir/9e693ccc-7706-49c5-8c8e-40f5242e81a6/dis_test_0_0_seeking_10_288_375_notyuv_lanczos_accurate_rnd_10to14_prece_FFmpegDecoder_postunsharpunsharp_q_480x360_PostPreresamplingFilter0 ')
'cat /opt/project/vmaf/workspace/workdir/9e693ccc-7706-49c5-8c8e-40f5242e81a6/dis_test_0_0_seeking_10_288_375_notyuv_lanczos_accurate_rnd_10to14_prece_FFmpegDecoder_postunsharpunsharp_q_480x360_PostDecode_tmp/pixfmt/* > /opt/project/vmaf/workspace/workdir/9e693ccc-7706-49c5-8c8e-40f5242e81a6/dis_test_0_0_seeking_10_288_375_notyuv_lanczos_accurate_rnd_10to14_prece_FFmpegDecoder_postunsharpunsharp_q_480x360_PostPreresamplingFilter0'
"""
return " ".join(command_line.split())


def assert_equivalent_commands(self, cmds: List[str], cmds_expected: List[str], root: str, root_expected: str):
assert len(cmds) == len(cmds_expected), f"length of cmds and cmds_expected are not equal: {len(cmds)} vs. {len(cmds_expected)}"
for cmd, cmd_expected in zip(cmds, cmds_expected):

cmd1 = replace_uuid(cmd)
cmd2 = replace_root(cmd1, root)
cmd3 = remove_redundant_whitespace(cmd2)

cmd_expected1 = replace_uuid(cmd_expected)
cmd_expected2 = replace_root(cmd_expected1, root_expected)
cmd_expected3 = remove_redundant_whitespace(cmd_expected2)

self.assertEqual(cmd2, cmd_expected2, msg=f"cmd and cmd_expected are not matched:\ncmd: {cmd}\ncmd:expected: {cmd_expected}")
self.assertEqual(cmd3, cmd_expected3, msg=f"cmd and cmd_expected are not matched:\ncmd: {cmd}\ncmd:expected: {cmd_expected}")

0 comments on commit 7a1f14f

Please sign in to comment.