GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
2
Releases
1
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
nigel.stanger
/
process_podcast
Browse code
Made more effective use of subtests (ref #31).
master
1 parent
2a1d133
commit
14850c55eedf4cae18a09f95cbf5eb59263ec7ee
Nigel Stanger
authored
on 21 Sep 2018
Patch
Showing
3 changed files
test_ffmpeg_concat_command.py
test_shared.py
test_shell_command.py
Ignore Space
Show notes
View
test_ffmpeg_concat_command.py
from datetime import timedelta from pathlib import Path import shutil import tempfile import unittest from unittest.mock import MagicMock from segment import Segment, AudioSegment, FrameSegment, VideoSegment from shell_command import FFmpegConcatCommand from test_shared import ShellCommandSharedTestCase class FFmpegConcatCommandTestCase(ShellCommandSharedTestCase): """Test the FFmpegConcatCommand class.""" # What about testing different permutations of audio and video? def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set, # otherwise they hang around from previous tests. self.command = FFmpegConcatCommand( input_options=["-i", "in.mov"], output_options=["out.mov"], has_video=True, has_audio=True, quiet=True) self.expected_executable = shutil.which("ffmpeg") self.expected_base_options = ["-y", "-nostdin",] self.expected_input_options = ["-i", "in.mov"] self.expected_filter_options = ["-filter_complex", ""] self.expected_output_options = [ "-codec:a", self.command.audio_codec, "-ac", "1", "-map", "[anorm]", "-codec:v", self.command.video_codec, "-pix_fmt", "yuv420p", "-map", "[vconc]", "out.mov" ] def tearDown(self): """Clean up after test.""" self.command = None def test_append_filter(self): """Test appending to the filter list.""" test_data = ( ("", [], "append empty filter"), ("normal_filter", ["normal_filter"], "append normal filter"), ) for appended, expected, description in test_data: with self.subTest(msg=description): self.command.append_filter(appended) self.assertEqual(self.command.filters, expected) def test_append_normalisation_filter(self): """Test appending a normalisation filter.""" filters = ["[aconc] dynaudnorm=r=0.25:f=10:b=y [anorm]"] self.command.append_normalisation_filter() self.assertEqual(self.command.filters, filters) def test_append_concat_filter(self): """Test appending various concat filters.""" test_data = ( ("a", "audio"), # ("v", "video"), # ("f", "frame"), ) for frame_type, description in test_data: for num_segments in range(0, 3): print("[{t}{n}]".format(t=frame_type, n=num_segments)) segments = None if frame_type == "a": segments = num_segments * [AudioSegment( file="file.in", punch_in=timedelta(), punch_out=timedelta(20), input_stream=0)] elif frame_type == "v": segments = num_segments * [VideoSegment( file="file.in", punch_in=timedelta(), punch_out=timedelta(20), input_stream=0)] elif frame_type == "f": segments = num_segments * [FrameSegment( file="file.in", punch_in=timedelta(), punch_out=timedelta(20), input_stream=0, frame_number=1)] else: raise TypeError self.command.append_concat_filter( frame_type=frame_type, segments=segments) if num_segments > 1: expected = [ "{inspecs} concat=n={n}:v={v}:a={a} [{t}conc]".format( inspecs=" ".join([s.output_stream_specifier() for s in segments]), n=num_segments, v=int(type == "v"), a=int(type == "a"), t=frame_type) ] elif num_segments == 1: expected = [ "{inspec} {a}null [{t}conc]".format( inspec=segments[0].output_stream_specifier(), a=frame_type if frame_type == "a" else "", t=frame_type) ] else: expected = [] print(" expected: {}".format(expected)) print(" actual: {}".format(self.command.filters)) with self.subTest( msg="{d}: {n}".format(d=description, n=num_segments)): self.assertEqual(self.command.filters, expected) # def test_append_concat_filter_0(self): # """Test appending a concat filter with no segments.""" # self.command.append_concat_filter(type="a", segments=[]) # with self.subTest(msg="audio"): # self.assertEqual(self.command.filters, []) # self.command.append_concat_filter(type="v", segments=[]) # with self.subTest(msg="video"): # self.assertEqual(self.command.filters, []) # self.command.append_concat_filter(type="f", segments=[]) # with self.subTest(msg="frame"): # self.assertEqual(self.command.filters, []) # def test_append_concat_filter_f(self): # """Test appending a concat filter with a frame segment.""" # self.command.append_concat_filter(type="f", segments=[Segment()]) # self.assertEqual( # self.command.filters, [], # msg="frame segments should be ignored") # def test_append_concat_filter_1_a(self): # """Test appending a concat filter with 1 audio segment.""" # self.command.append_concat_filter( # type="a", # segments=[Segment(file="a.mov", punch_in=10, # punch_out=20, input_stream=1)]) # with self.subTest(msg="audio"): # self.assertEqual(self.command.filters, []) # def test_append_concat_filter_1_v(self): # """Test appending a concat filter with 1 video segment.""" # concat = # self.command.append_concat_filter(type="v", # segments=[Segment(file="v.mov", punch_in=10, # punch_out=20, input_stream=1)]) # with self.subTest(msg="audio"): # self.assertEqual() # def test_append_concat_filter_2(self): # """Test appending a concat filter with >1 segment.""" # def test_build_complex_filter(self): # """Test building the complex filter.""" # Remove ShellCommandSharedTestCase from the namespace so we don't run # the shared tests twice. See <https://stackoverflow.com/a/22836015>. del(ShellCommandSharedTestCase)
import shutil from pathlib import Path import tempfile import unittest from unittest.mock import MagicMock from segment import Segment from shell_command import FFmpegConcatCommand from test_shared import ShellCommandSharedTestCase class FFmpegConcatCommandTestCase(ShellCommandSharedTestCase): """Test the FFmpegConcatCommand class.""" # What about testing different permutations of audio and video? def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set, # otherwise they hang around from previous tests. self.command = FFmpegConcatCommand( input_options=["-i", "in.mov"], output_options=["out.mov"], has_video=True, has_audio=True, quiet=True) self.expected_executable = shutil.which("ffmpeg") self.expected_base_options = ["-y", "-nostdin",] self.expected_input_options = ["-i", "in.mov"] self.expected_filter_options = ["-filter_complex", ""] self.expected_output_options = [ "-codec:a", self.command.audio_codec, "-ac", "1", "-map", "[anorm]", "-codec:v", self.command.video_codec, "-pix_fmt", "yuv420p", "-map", "[vconc]", "out.mov" ] def tearDown(self): """Clean up after test.""" self.command = None def test_append_filter(self): """Test appending to the filter list.""" # append empty filter => no change with self.subTest(msg="empty"): filters = [] self.command.append_filter("") self.assertEqual(self.command.filters, filters) # append an actual filter with self.subTest(msg="normal"): filters = ["this_is_a_weird_filter"] self.command.append_filter("this_is_a_weird_filter") self.assertEqual(self.command.filters, filters) def test_append_normalisation_filter(self): """Test appending a normalisation filter.""" filters = ["[aconc] dynaudnorm=r=0.25:f=10:b=y [anorm]"] self.command.append_normalisation_filter() self.assertEqual(self.command.filters, filters) def test_append_concat_filter_0(self): """Test appending a concat filter with no segments.""" self.command.append_concat_filter(type="a", segments=[]) with self.subTest(msg="audio"): self.assertEqual(self.command.filters, []) self.command.append_concat_filter(type="v", segments=[]) with self.subTest(msg="video"): self.assertEqual(self.command.filters, []) self.command.append_concat_filter(type="f", segments=[]) with self.subTest(msg="frame"): self.assertEqual(self.command.filters, []) def test_append_concat_filter_f(self): """Test appending a concat filter with a frame segment.""" self.command.append_concat_filter(type="f", segments=[Segment()]) self.assertEqual( self.command.filters, [], msg="frame segments should be ignored") # def test_append_concat_filter_1_a(self): # """Test appending a concat filter with 1 audio segment.""" # self.command.append_concat_filter( # type="a", # segments=[Segment(file="a.mov", punch_in=10, # punch_out=20, input_stream=1)]) # with self.subTest(msg="audio"): # self.assertEqual(self.command.filters, []) # def test_append_concat_filter_1_v(self): # """Test appending a concat filter with 1 video segment.""" # concat = # self.command.append_concat_filter(type="v", # segments=[Segment(file="v.mov", punch_in=10, # punch_out=20, input_stream=1)]) # with self.subTest(msg="audio"): # self.assertEqual() # def test_append_concat_filter_2(self): # """Test appending a concat filter with >1 segment.""" # def test_build_complex_filter(self): # """Test building the complex filter.""" # Remove ShellCommandSharedTestCase from the namespace so we don't run # the shared tests twice. See <https://stackoverflow.com/a/22836015>. del(ShellCommandSharedTestCase)
Ignore Space
Show notes
View
test_shared.py
import unittest from shell_command import ShellCommand class ShellCommandSharedTestCase(unittest.TestCase): """Shared tests for ShellCommand and its subclasses.""" def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set to # [] otherwise they hang around from previous tests. self.command = ShellCommand(input_options=[], output_options=[]) self.expected_executable = "" self.expected_base_options = [] self.expected_input_options = [] self.expected_filter_options = [] self.expected_output_options = [] def tearDown(self): """Clean up after test.""" self.command = None def test_base_options(self): """Test that base options match expected.""" self.assertEqual( self.command._base_options, self.expected_base_options) def test_input_options(self): """Test that input options match expected.""" self.assertEqual( self.command.input_options, self.expected_input_options) def test_output_options(self): """Test that output options match expected.""" self.assertEqual( self.command.output_options, self.expected_output_options) def test_executable_string(self): """Test that executable path matches expected.""" with self.subTest(msg="unquoted paths match"): self.assertEqual( self.command.executable_string(quote=False), self.expected_executable) with self.subTest(msg="unquoted paths match"): # Note: don't explicitly specify quoted value, because # the executable path will vary across different systems. self.assertEqual( self.command.executable_string(quote=True), ShellCommand.shellquote(self.expected_executable)) def test_argument_string(self): """Test that argument string matches expected.""" args = (self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) with self.subTest(msg="unquoted agruments match"): self.assertEqual( self.command.argument_string(quote=False), " ".join(args)) with self.subTest(msg="quoted agruments match"): self.assertEqual( self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that argument list matches expected.""" self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) def test_command_string(self): """Test that command string matches expected.""" args = (self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) expected_cmd_unquoted = ( "{exe} {arg}".format(exe=self.expected_executable, arg=" ".join(args)) ) expected_cmd_quoted = ( '{exe} {arg}'.format( exe=ShellCommand.shellquote(self.expected_executable), arg=" ".join([ShellCommand.shellquote(a) for a in args])) ) with self.subTest(msg="unquoted command string matches"): self.assertEqual( self.command.command_string(quote=False), expected_cmd_unquoted) with self.subTest(msg="quoted command string matches"): self.assertEqual( self.command.command_string(quote=True), expected_cmd_quoted)
import unittest from shell_command import ShellCommand class ShellCommandSharedTestCase(unittest.TestCase): """Shared tests for ShellCommand and its subclasses.""" def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set to # [] otherwise they hang around from previous tests. self.command = ShellCommand(input_options=[], output_options=[]) self.expected_executable = "" self.expected_base_options = [] self.expected_input_options = [] self.expected_filter_options = [] self.expected_output_options = [] def tearDown(self): """Clean up after test.""" self.command = None def test_base_options(self): """Test that base options match expected.""" self.assertEqual( self.command._base_options, self.expected_base_options) def test_input_options(self): """Test that input options match expected.""" self.assertEqual( self.command.input_options, self.expected_input_options) def test_output_options(self): """Test that output options match expected.""" self.assertEqual( self.command.output_options, self.expected_output_options) def test_executable_string(self): """Test that executable path matches expected.""" with self.subTest(msg="unquoted"): self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) with self.subTest(msg="quoted"): # Note: don't explicitly specify quoted value, because # the executable path will vary across different systems. self.assertEqual(self.command.executable_string(quote=True), ShellCommand.shellquote(self.expected_executable)) def test_argument_string(self): """Test that argument string matches expected.""" args = (self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) with self.subTest(msg="unquoted"): self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) with self.subTest(msg="quoted"): self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that argument list matches expected.""" self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) def test_command_string(self): """Test that command string matches expected.""" args = (self.expected_base_options + self.expected_input_options + self.expected_filter_options + self.expected_output_options) expected_cmd_unquoted = ( "{exe} {arg}".format(exe=self.expected_executable, arg=" ".join(args)) ) expected_cmd_quoted = ( '{exe} {arg}'.format( exe=ShellCommand.shellquote(self.expected_executable), arg=" ".join([ShellCommand.shellquote(a) for a in args])) ) with self.subTest(msg="unquoted"): self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) with self.subTest(msg="quoted"): self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted)
Ignore Space
Show notes
View
test_shell_command.py
import unittest from shell_command import ShellCommand from test_shared import ShellCommandSharedTestCase class ShellCommandTestCase(ShellCommandSharedTestCase): """Test the ShellCommand class.""" def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set to # [] otherwise they hang around from previous tests. self.command = ShellCommand(input_options=[], output_options=[]) self.expected_executable = "" self.expected_base_options = [] self.expected_input_options = [] self.expected_filter_options = [] self.expected_output_options = [] def tearDown(self): """Clean up after test.""" self.command = None def test_shellquote(self): """Test shell quoting (static method).""" test_data = ( (None, None, "None ⇒ None"), ("", "", "(empty string) ⇒ (empty string)"), (" ", '" "', '␢ ⇒ " "'), (" ", '" "', '␢␢␢␢␢ ⇒ " "'), ("foobar", "foobar", "foobar ⇒ foobar"), ("foo bar", '"foo bar"', 'foo bar ⇒ "foo bar"'), ('"foobar"', '\'"foobar"\'', '"foobar" ⇒ \'"foobar"\''), ("'foobar'", "'foobar'", "'foobar' ⇒ 'foobar'"), ("foo 'bar'", '"foo \'bar\'"', "foo 'bar' ⇒ \"foo 'bar'\""), ('foo"bar', '\'foo"bar\'', 'foo"bar ⇒ \'foo"bar\''), ("foo.bar", '"foo.bar"', 'foo.bar ⇒ "foo.bar"'), ("foo(bar)", '"foo(bar)"', 'foo(bar) ⇒ "foo(bar)"'), ("[foobar]", '"[foobar]"', '[foobar] ⇒ "[foobar]"'), ("foo[bar", '"foo[bar"', 'foo[bar ⇒ "foo[bar"'), ("/foo/bar", "/foo/bar", "/foo/bar ⇒ /foo/bar"), ("-f", "-f", "-f ⇒ -f"), ("--foobar", "--foobar", "--foobar ⇒ --foobar"), ("(", r"\(", r"( ⇒ \("), (")", r"\)", r"( ⇒ \)"), ("'", '"\'"', '\' ⇒ "\'"'), ) for original, expected, description in test_data: with self.subTest(msg=description): self.assertEqual(ShellCommand.shellquote(original), expected) def test_append_input_options(self): """Test appending to input options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.input_options, []) test_data = ( ([], [], "[] ⇒ []"), (["foo"], ["foo"], '["foo"] ⇒ ["foo"]'), (["bar"], ["foo", "bar"], '["bar"] ⇒ ["foo", "bar"]'), (["baz", 42], ["foo", "bar", "baz", 42], '["baz", 42] ⇒ ["foo", "bar", "baz", 42]'), ) for appended, expected, description in test_data: with self.subTest(msg="appending {}".format(description)): self.command.append_input_options(appended) self.assertEqual(self.command.input_options, expected) def test_prepend_input_options(self): """Test prepending to input options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.input_options, []) test_data = ( ([], [], "[] ⇒ []"), (["foo"], ["foo"], '["foo"] ⇒ ["foo"]'), (["bar"], ["bar", "foo"], '["bar"] ⇒ ["bar", "foo"]'), (["baz", 42], ["baz", 42, "bar", "foo"], '["baz", 42] ⇒ ["baz", 42, "bar", "foo"]'), ) for prepended, expected, description in test_data: with self.subTest(msg="prepending {}".format(description)): self.command.prepend_input_options(prepended) self.assertEqual(self.command.input_options, expected) def test_append_output_options(self): """Test appending to output options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.output_options, []) test_data = ( ([], [], "[] ⇒ []"), (["foo"], ["foo"], '["foo"] ⇒ ["foo"]'), (["bar"], ["foo", "bar"], '["bar"] ⇒ ["foo", "bar"]'), (["baz", 42], ["foo", "bar", "baz", 42], '["baz", 42] ⇒ ["foo", "bar", "baz", 42]'), ) for appended, expected, description in test_data: with self.subTest(msg="appending {}".format(description)): self.command.append_output_options(appended) self.assertEqual(self.command.output_options, expected) def test_prepend_output_options(self): """Test prepending to output options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.output_options, []) test_data = ( ([], [], "[] ⇒ []"), (["foo"], ["foo"], '["foo"] ⇒ ["foo"]'), (["bar"], ["bar", "foo"], '["bar"] ⇒ ["bar", "foo"]'), (["baz", 42], ["baz", 42, "bar", "foo"], '["baz", 42] ⇒ ["baz", 42, "bar", "foo"]'), ) for prepended, expected, description in test_data: with self.subTest(msg="prepending {}".format(description)): self.command.prepend_output_options(prepended) self.assertEqual(self.command.output_options, expected) def test_process_pattern(self): """ Test pattern processing.""" # True on EOF (0) with self.subTest(msg="returns True on EOF"): self.assertTrue(self.command.process_pattern(0)) # False on anything else for i in (x for x in range(-1000, 1001) if x is not 0): with self.subTest(msg="returns False on {}".format(i)): self.assertFalse(self.command.process_pattern(i)) # The following two will require mocking of pexpect? def test_run(self): """Test running of subprocess.""" pass def test_get_output(self): """Test getting output from subprocess.""" pass # Remove ShellCommandSharedTestCase from the namespace so we don't run # the shared tests twice. See <https://stackoverflow.com/a/22836015>. del(ShellCommandSharedTestCase)
import unittest from shell_command import ShellCommand from test_shared import ShellCommandSharedTestCase class ShellCommandTestCase(ShellCommandSharedTestCase): """Test the ShellCommand class.""" def setUp(self): """Set up for test.""" # Make sure the input and output options are explicitly set to # [] otherwise they hang around from previous tests. self.command = ShellCommand(input_options=[], output_options=[]) self.expected_executable = "" self.expected_base_options = [] self.expected_input_options = [] self.expected_filter_options = [] self.expected_output_options = [] def tearDown(self): """Clean up after test.""" self.command = None def test_shellquote(self): """Test shell quoting (static method).""" with self.subTest(msg="None ⇒ None"): self.assertIsNone(ShellCommand.shellquote(None)) with self.subTest(msg='(empty string) ⇒ (empty string)'): self.assertEqual(ShellCommand.shellquote(""), "") with self.subTest(msg='␢ ⇒ " "'): self.assertEqual(ShellCommand.shellquote(" "), '" "') with self.subTest(msg='␢␢␢␢␢ ⇒ " "'): self.assertEqual(ShellCommand.shellquote(" "), '" "') with self.subTest(msg='foobar ⇒ foobar'): self.assertEqual(ShellCommand.shellquote("foobar"), "foobar") with self.subTest(msg='foo bar ⇒ "foo bar"'): self.assertEqual( ShellCommand.shellquote("foo bar"), '"foo bar"') with self.subTest(msg='"foobar" ⇒ \'"foobar"\''): self.assertEqual( ShellCommand.shellquote('"foobar"'), '\'"foobar"\'') with self.subTest(msg="'foobar' ⇒ 'foobar'"): self.assertEqual( ShellCommand.shellquote("'foobar'"), "'foobar'") with self.subTest(msg="foo 'bar' ⇒ \"foo 'bar'\""): self.assertEqual( ShellCommand.shellquote("foo 'bar'"), '"foo \'bar\'"') with self.subTest(msg='foo"bar ⇒ \'foo"bar\''): self.assertEqual( ShellCommand.shellquote('foo"bar'), '\'foo"bar\'') with self.subTest(msg='foo.bar ⇒ "foo.bar"'): self.assertEqual(ShellCommand.shellquote("foo.bar"), '"foo.bar"') with self.subTest(msg='foo(bar) ⇒ "foo(bar)"'): self.assertEqual( ShellCommand.shellquote("foo(bar)"), '"foo(bar)"') with self.subTest(msg='[foobar] ⇒ "[foobar]"'): self.assertEqual( ShellCommand.shellquote("[foobar]"), '"[foobar]"') with self.subTest(msg='foo[bar ⇒ "foo[bar"'): self.assertEqual(ShellCommand.shellquote("foo[bar"), '"foo[bar"') with self.subTest(msg="/foo/bar ⇒ /foo/bar"): self.assertEqual(ShellCommand.shellquote("/foo/bar"), "/foo/bar") with self.subTest(msg="-f ⇒ -f"): self.assertEqual(ShellCommand.shellquote("-f"), "-f") with self.subTest(msg="-foobar ⇒ -foobar"): self.assertEqual(ShellCommand.shellquote("--foobar"), "--foobar") with self.subTest(msg=r"( ⇒ \("): self.assertEqual(ShellCommand.shellquote("("), r"\(") with self.subTest(msg=r") ⇒ \)"): self.assertEqual(ShellCommand.shellquote(")"), r"\)") # ' => "'" with self.subTest(msg='\' ⇒ "\'"'): self.assertEqual(ShellCommand.shellquote("'"), '"\'"') def test_append_input_options(self): """Test appending to input options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.input_options, []) with self.subTest(msg="appending [] ⇒ []"): self.command.append_input_options([]) self.assertEqual(self.command.input_options, []) with self.subTest(msg='appending ["foo"] ⇒ ["foo"]'): self.command.append_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) with self.subTest(msg='appending ["bar"] ⇒ ["foo", "bar"]'): self.command.append_input_options(["bar"]) self.assertEqual(self.command.input_options, ["foo", "bar"]) with self.subTest( msg='appending ["baz", 42] ⇒ ["foo", "bar", "baz", 42]'): self.command.append_input_options(["baz", 42]) self.assertEqual( self.command.input_options, ["foo", "bar", "baz", 42]) def test_prepend_input_options(self): """Test prepending to input options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.input_options, []) with self.subTest(msg="prepending [] ⇒ []"): self.command.prepend_input_options([]) self.assertEqual(self.command.input_options, []) with self.subTest(msg='prepending ["foo"] ⇒ ["foo"]'): self.command.prepend_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) with self.subTest(msg='prepending ["bar"] ⇒ ["bar", "foo"]'): self.command.prepend_input_options(["bar"]) self.assertEqual(self.command.input_options, ["bar", "foo"]) with self.subTest( msg='prepending ["baz", 42] ⇒ ["baz", 42, "bar", "foo]'): self.command.prepend_input_options(["baz", 42]) self.assertEqual( self.command.input_options, ["baz", 42, "bar", "foo"]) def test_append_output_options(self): """Test appending to output options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.output_options, []) with self.subTest(msg="appending [] ⇒ []"): self.command.append_output_options([]) self.assertEqual(self.command.output_options, []) with self.subTest(msg='appending ["foo"] ⇒ ["foo"]'): self.command.append_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) with self.subTest(msg='appending ["bar"] ⇒ ["foo", "bar"]'): self.command.append_output_options(["bar"]) self.assertEqual(self.command.output_options, ["foo", "bar"]) with self.subTest( msg='appending ["baz", 42] ⇒ ["foo", "bar", "baz", 42]'): self.command.append_output_options(["baz", 42]) self.assertEqual( self.command.output_options, ["foo", "bar", "baz", 42]) def test_prepend_output_options(self): """Test prepending to output options.""" with self.subTest(msg="should initially be []"): self.assertEqual(self.command.output_options, []) with self.subTest(msg="prepending [] ⇒ []"): self.command.prepend_output_options([]) self.assertEqual(self.command.output_options, []) with self.subTest(msg='prepending ["foo"] ⇒ ["foo"]'): self.command.prepend_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) with self.subTest(msg='prepending ["bar"] ⇒ ["bar", "foo"]'): self.command.prepend_output_options(["bar"]) self.assertEqual(self.command.output_options, ["bar", "foo"]) with self.subTest( msg='prepending ["baz", 42] ⇒ ["baz", 42, "bar", "foo]'): self.command.prepend_output_options(["baz", 42]) self.assertEqual( self.command.output_options, ["baz", 42, "bar", "foo"]) def test_process_pattern(self): """ Test pattern processing.""" # True on EOF (0) with self.subTest(msg="returns True on EOF"): self.assertTrue(self.command.process_pattern(0)) # False on anythingthing else with self.subTest(msg="returns False on 1"): self.assertFalse(self.command.process_pattern(1)) with self.subTest(msg="returns False on -1"): self.assertFalse(self.command.process_pattern(-1)) with self.subTest(msg="returns False on None"): self.assertFalse(self.command.process_pattern(None)) # The following two will require mocking of pexpect? def test_run(self): """Test running of subprocess.""" pass def test_get_output(self): """Test getting output from subprocess.""" pass # Remove ShellCommandSharedTestCase from the namespace so we don't run # the shared tests twice. See <https://stackoverflow.com/a/22836015>. del(ShellCommandSharedTestCase)
Show line notes below