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
Renamed test case classes (ref #31).
master
1 parent
891857d
commit
634e6ab3f53a79295fa8df3a8b650b255d22776a
Nigel Stanger
authored
on 20 Sep 2018
Patch
Showing
4 changed files
test_convert_command.py
test_ffmpeg_command.py
test_ffprobe_command.py
test_shell_command.py
Ignore Space
Show notes
View
test_convert_command.py
import shutil import unittest from shell_command import ( ShellCommand, ConvertCommand ) class ConvertCommandTestCase(unittest.TestCase): """Test the ConvertCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. """ self.command = ConvertCommand( input_options=["in.pdf[12]"], output_options=["out.png"]) self.expected_executable = shutil.which("convert") self.expected_base_options = [ "-size", "2048x1536", "-density", "600", "xc:dimgrey", "null:", "(" ] self.expected_input_options = [ "in.pdf[12]", "-resize", "2048x1536", "-background", "white", "-alpha", "remove", "-type", "truecolor", "-define", "colorspace:auto-grayscale=off", ] self.expected_output_options = [ ")", "-gravity", "center", "-layers", "composite", "-flatten", "out.png", ] def tearDown(self): """Cleanup. """ 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted)
import shutil import unittest from shell_command import ( ShellCommand, ConvertCommand ) class TestConvertCommand(unittest.TestCase): """Test the ConvertCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. """ self.command = ConvertCommand( input_options=["in.pdf[12]"], output_options=["out.png"]) self.expected_executable = shutil.which("convert") self.expected_base_options = [ "-size", "2048x1536", "-density", "600", "xc:dimgrey", "null:", "(" ] self.expected_input_options = [ "in.pdf[12]", "-resize", "2048x1536", "-background", "white", "-alpha", "remove", "-type", "truecolor", "-define", "colorspace:auto-grayscale=off", ] self.expected_output_options = [ ")", "-gravity", "center", "-layers", "composite", "-flatten", "out.png", ] def tearDown(self): """Cleanup. """ 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted)
Ignore Space
Show notes
View
test_ffmpeg_command.py
import shutil from pathlib import Path import tempfile import unittest from shell_command import ( ShellCommand, FFmpegCommand ) class FFmpegCommandTestCase(unittest.TestCase): """Test the FFmpegCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. A fresh temporary file is created for each test. """ self.command = FFmpegCommand( input_options=["-i", "in.mov"], output_options=["out.mov"]) self.expected_executable = shutil.which("ffmpeg") self.expected_base_options = ["-y", "-nostdin",] self.expected_input_options = ["-i", "in.mov"] self.expected_output_options = ["out.mov"] def tearDown(self): """Cleanup. """ 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted)
import shutil from pathlib import Path import tempfile import unittest from shell_command import ( ShellCommand, FFmpegCommand ) class TestFFmpegCommand(unittest.TestCase): """Test the FFmpegCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. A fresh temporary file is created for each test. """ self.command = FFmpegCommand( input_options=["-i", "in.mov"], output_options=["out.mov"]) self.expected_executable = shutil.which("ffmpeg") self.expected_base_options = ["-y", "-nostdin",] self.expected_input_options = ["-i", "in.mov"] self.expected_output_options = ["out.mov"] def tearDown(self): """Cleanup. """ 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted)
Ignore Space
Show notes
View
test_ffprobe_command.py
import shutil from pathlib import Path import tempfile import unittest from shell_command import ( ShellCommand, FFprobeCommand ) class FFprobeCommandTestCase(unittest.TestCase): """Test the FFprobeCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. A fresh temporary file is created for each test. """ self.tmpfile = tempfile.NamedTemporaryFile() self.command = FFprobeCommand( input_options=["-i", self.tmpfile.name], output_options=[]) self.expected_executable = shutil.which("ffprobe") self.expected_base_options = [ "-loglevel", "error", "-show_entries", "format:stream", "-print_format", "json", ] self.expected_input_options = ["-i", self.tmpfile.name] self.expected_output_options = [] def tearDown(self): """Cleanup. """ self.tmpfile.close() 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted) def test_last_modified(self): """Test that last modified time matches tmpfile on disk. """ self.assertEqual( self.command.last_modified, Path(self.tmpfile.name).stat().st_mtime) # get_entries()?
import shutil from pathlib import Path import tempfile import unittest from shell_command import ( ShellCommand, FFprobeCommand ) class TestFFprobeCommand(unittest.TestCase): """Test the FFprobeCommand class. """ def setUp(self): """Initialisation. Make sure the input and output options are explicitly set otherwise they hang around from previous tests. A fresh temporary file is created for each test. """ self.tmpfile = tempfile.NamedTemporaryFile() self.command = FFprobeCommand( input_options=["-i", self.tmpfile.name], output_options=[]) self.expected_executable = shutil.which("ffprobe") self.expected_base_options = [ "-loglevel", "error", "-show_entries", "format:stream", "-print_format", "json", ] self.expected_input_options = ["-i", self.tmpfile.name] self.expected_output_options = [] def tearDown(self): """Cleanup. """ self.tmpfile.close() 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. """ self.assertEqual(self.command.executable_string(quote=False), self.expected_executable) # 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 the argument string matches expected. """ args = (self.expected_base_options + self.expected_input_options + self.expected_output_options) self.assertEqual(self.command.argument_string(quote=False), " ".join(args)) self.assertEqual(self.command.argument_string(quote=True), " ".join([ShellCommand.shellquote(a) for a in args])) def test_argument_list(self): """Test that the argument list matches expected. """ self.assertEqual(self.command.argument_list(), self.expected_base_options + self.expected_input_options + self.expected_output_options) def test_command_string(self): """Test that the command string matches expected. """ args = (self.expected_base_options + self.expected_input_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])) ) self.assertEqual(self.command.command_string(quote=False), expected_cmd_unquoted) self.assertEqual(self.command.command_string(quote=True), expected_cmd_quoted) def test_last_modified(self): """Test that last modified time matches tmpfile on disk. """ self.assertEqual( self.command.last_modified, Path(self.tmpfile.name).stat().st_mtime) # get_entries()?
Ignore Space
Show notes
View
test_shell_command.py
import unittest from shell_command import ( ShellCommand, ConvertCommand, FFmpegConcatCommand, FFprobeCommand ) class ShellCommandTestCase(unittest.TestCase): """Test the ShellCommand class. """ def setUp(self): """Initialisation. 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=[]) def tearDown(self): """Cleanup. """ self.command = None def test_shellquote(self): """Test static method ShellCommand.shellquote(). """ # None => None self.assertIsNone(ShellCommand.shellquote(None)) # (empty string) => (empty string) self.assertEqual(ShellCommand.shellquote(""), "") # (blank) => " " (one or more) self.assertEqual(ShellCommand.shellquote(" "), '" "') self.assertEqual(ShellCommand.shellquote(" "), '" "') # foobar => foobar self.assertEqual(ShellCommand.shellquote("foobar"), "foobar") # foo bar => "foo bar" self.assertEqual(ShellCommand.shellquote("foo bar"), '"foo bar"') # "foobar" => '"foobar"' self.assertEqual(ShellCommand.shellquote('"foobar"'), '\'"foobar"\'') # 'foobar' => 'foobar' self.assertEqual(ShellCommand.shellquote("'foobar'"), "'foobar'") # foo 'bar' => "foo 'bar'" self.assertEqual( ShellCommand.shellquote("foo 'bar'"), '"foo \'bar\'"') # foo"bar => 'foo"bar' self.assertEqual(ShellCommand.shellquote('foo"bar'), '\'foo"bar\'') # foo.bar => "foo.bar" self.assertEqual(ShellCommand.shellquote("foo.bar"), '"foo.bar"') # foo(bar) => "foo(bar)" self.assertEqual(ShellCommand.shellquote("foo(bar)"), '"foo(bar)"') # [foobar] => "[foobar]" self.assertEqual(ShellCommand.shellquote("[foobar]"), '"[foobar]"') # foo[bar => "foo[bar" self.assertEqual(ShellCommand.shellquote("foo[bar"), '"foo[bar"') # /foo/bar => /foo/bar self.assertEqual(ShellCommand.shellquote("/foo/bar"), "/foo/bar") # -f => -f self.assertEqual(ShellCommand.shellquote("-f"), "-f") # --foobar => --foobar self.assertEqual(ShellCommand.shellquote("--foobar"), "--foobar") # ( => \( self.assertEqual(ShellCommand.shellquote("("), r"\(") # ) => \) self.assertEqual(ShellCommand.shellquote(")"), r"\)") # ' => "'" self.assertEqual(ShellCommand.shellquote("'"), '"\'"') def test_append_input_options(self): """Test method ShellCommand.append_input_options(). """ # input_options should be [] initially self.assertEqual(self.command.input_options, []) # append [] => [] self.command.append_input_options([]) self.assertEqual(self.command.input_options, []) # append ["foo"] => ["foo"] self.command.append_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) # append ["bar"] => ["foo", "bar"] self.command.append_input_options(["bar"]) self.assertEqual(self.command.input_options, ["foo", "bar"]) # append ["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 method ShellCommand.prepend_input_options(). """ # input_options should be [] initially self.assertEqual(self.command.input_options, []) # prepend [] => [] self.command.prepend_input_options([]) self.assertEqual(self.command.input_options, []) # prepend ["foo"] => ["foo"] self.command.prepend_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) # prepend ["bar"] => ["bar", "foo"] self.command.prepend_input_options(["bar"]) self.assertEqual(self.command.input_options, ["bar", "foo"]) # prepend ["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 method ShellCommand.append_output_options(). """ # output_options should be [] initially self.assertEqual(self.command.output_options, []) # append [] => [] self.command.append_output_options([]) self.assertEqual(self.command.output_options, []) # append ["foo"] => ["foo"] self.command.append_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) # append ["bar"] => ["foo", "bar"] self.command.append_output_options(["bar"]) self.assertEqual(self.command.output_options, ["foo", "bar"]) # append ["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 method ShellCommand.prepend_output_options. """ # output_options should be [] initially self.assertEqual(self.command.output_options, []) # prepend [] => [] self.command.prepend_output_options([]) self.assertEqual(self.command.output_options, []) # prepend ["foo"] => ["foo"] self.command.prepend_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) # prepend ["bar"] => ["bar", "foo"] self.command.prepend_output_options(["bar"]) self.assertEqual(self.command.output_options, ["bar", "foo"]) # prepend ["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_executable_string(self): """Test method ShellCommand.executable_string(). """ # Always "" in the base class. self.assertEqual(self.command.executable_string(quote=False), "") self.assertEqual(self.command.executable_string(quote=True), "") def test_argument_string(self): """Test method ShellCommand.argument_string(). """ # Always "" in the base class. self.assertEqual(self.command.argument_string(quote=False), "") self.assertEqual(self.command.argument_string(quote=True), "") def test_argument_list(self): """Test method ShellCommand.argument_list(). """ # Always [] in the base class. self.assertEqual(self.command.argument_list(), []) def test_command_string(self): """Test method ShellCommand.command_string(). """ # Always " " in the base class. self.assertEqual(self.command.command_string(quote=False), " ") # Subtlety: command_string() passes the quote argument on to # executable_string() and argument_string(). Thus, the result # should be " " regardless of the value of quote. self.assertEqual(self.command.command_string(quote=True), " ") # Add an option that needs to be quoted. self.command.append_output_options(["argle bargle"]) self.assertEqual( self.command.command_string(quote=True), ' "argle bargle"') def test_process_pattern(self): """ Test method ShellCommand.process_pattern(). """ # True on EOF (0) self.assertTrue(self.command.process_pattern(0)) # False on anythingthing else self.assertFalse(self.command.process_pattern(1)) self.assertFalse(self.command.process_pattern(-1)) self.assertFalse(self.command.process_pattern(None)) # The following two will require mocking of pexpect? def test_run(self): """Test method ShellCommand.run(). """ pass def test_get_output(self): """Test method ShellCommand.get_output(). """ pass
import unittest from shell_command import ( ShellCommand, ConvertCommand, FFmpegConcatCommand, FFprobeCommand ) class TestShellCommand(unittest.TestCase): """Test the ShellCommand class. """ def setUp(self): """Initialisation. 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=[]) def tearDown(self): """Cleanup. """ self.command = None def test_shellquote(self): """Test static method ShellCommand.shellquote(). """ # None => None self.assertIsNone(ShellCommand.shellquote(None)) # (empty string) => (empty string) self.assertEqual(ShellCommand.shellquote(""), "") # (blank) => " " (one or more) self.assertEqual(ShellCommand.shellquote(" "), '" "') self.assertEqual(ShellCommand.shellquote(" "), '" "') # foobar => foobar self.assertEqual(ShellCommand.shellquote("foobar"), "foobar") # foo bar => "foo bar" self.assertEqual(ShellCommand.shellquote("foo bar"), '"foo bar"') # "foobar" => '"foobar"' self.assertEqual(ShellCommand.shellquote('"foobar"'), '\'"foobar"\'') # 'foobar' => 'foobar' self.assertEqual(ShellCommand.shellquote("'foobar'"), "'foobar'") # foo 'bar' => "foo 'bar'" self.assertEqual( ShellCommand.shellquote("foo 'bar'"), '"foo \'bar\'"') # foo"bar => 'foo"bar' self.assertEqual(ShellCommand.shellquote('foo"bar'), '\'foo"bar\'') # foo.bar => "foo.bar" self.assertEqual(ShellCommand.shellquote("foo.bar"), '"foo.bar"') # foo(bar) => "foo(bar)" self.assertEqual(ShellCommand.shellquote("foo(bar)"), '"foo(bar)"') # [foobar] => "[foobar]" self.assertEqual(ShellCommand.shellquote("[foobar]"), '"[foobar]"') # foo[bar => "foo[bar" self.assertEqual(ShellCommand.shellquote("foo[bar"), '"foo[bar"') # /foo/bar => /foo/bar self.assertEqual(ShellCommand.shellquote("/foo/bar"), "/foo/bar") # -f => -f self.assertEqual(ShellCommand.shellquote("-f"), "-f") # --foobar => --foobar self.assertEqual(ShellCommand.shellquote("--foobar"), "--foobar") # ( => \( self.assertEqual(ShellCommand.shellquote("("), r"\(") # ) => \) self.assertEqual(ShellCommand.shellquote(")"), r"\)") # ' => "'" self.assertEqual(ShellCommand.shellquote("'"), '"\'"') def test_append_input_options(self): """Test method ShellCommand.append_input_options(). """ # input_options should be [] initially self.assertEqual(self.command.input_options, []) # append [] => [] self.command.append_input_options([]) self.assertEqual(self.command.input_options, []) # append ["foo"] => ["foo"] self.command.append_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) # append ["bar"] => ["foo", "bar"] self.command.append_input_options(["bar"]) self.assertEqual(self.command.input_options, ["foo", "bar"]) # append ["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 method ShellCommand.prepend_input_options(). """ # input_options should be [] initially self.assertEqual(self.command.input_options, []) # prepend [] => [] self.command.prepend_input_options([]) self.assertEqual(self.command.input_options, []) # prepend ["foo"] => ["foo"] self.command.prepend_input_options(["foo"]) self.assertEqual(self.command.input_options, ["foo"]) # prepend ["bar"] => ["bar", "foo"] self.command.prepend_input_options(["bar"]) self.assertEqual(self.command.input_options, ["bar", "foo"]) # prepend ["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 method ShellCommand.append_output_options(). """ # output_options should be [] initially self.assertEqual(self.command.output_options, []) # append [] => [] self.command.append_output_options([]) self.assertEqual(self.command.output_options, []) # append ["foo"] => ["foo"] self.command.append_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) # append ["bar"] => ["foo", "bar"] self.command.append_output_options(["bar"]) self.assertEqual(self.command.output_options, ["foo", "bar"]) # append ["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 method ShellCommand.prepend_output_options. """ # output_options should be [] initially self.assertEqual(self.command.output_options, []) # prepend [] => [] self.command.prepend_output_options([]) self.assertEqual(self.command.output_options, []) # prepend ["foo"] => ["foo"] self.command.prepend_output_options(["foo"]) self.assertEqual(self.command.output_options, ["foo"]) # prepend ["bar"] => ["bar", "foo"] self.command.prepend_output_options(["bar"]) self.assertEqual(self.command.output_options, ["bar", "foo"]) # prepend ["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_executable_string(self): """Test method ShellCommand.executable_string(). """ # Always "" in the base class. self.assertEqual(self.command.executable_string(quote=False), "") self.assertEqual(self.command.executable_string(quote=True), "") def test_argument_string(self): """Test method ShellCommand.argument_string(). """ # Always "" in the base class. self.assertEqual(self.command.argument_string(quote=False), "") self.assertEqual(self.command.argument_string(quote=True), "") def test_argument_list(self): """Test method ShellCommand.argument_list(). """ # Always [] in the base class. self.assertEqual(self.command.argument_list(), []) def test_command_string(self): """Test method ShellCommand.command_string(). """ # Always " " in the base class. self.assertEqual(self.command.command_string(quote=False), " ") # Subtlety: command_string() passes the quote argument on to # executable_string() and argument_string(). Thus, the result # should be " " regardless of the value of quote. self.assertEqual(self.command.command_string(quote=True), " ") # Add an option that needs to be quoted. self.command.append_output_options(["argle bargle"]) self.assertEqual( self.command.command_string(quote=True), ' "argle bargle"') def test_process_pattern(self): """ Test method ShellCommand.process_pattern(). """ # True on EOF (0) self.assertTrue(self.command.process_pattern(0)) # False on anythingthing else self.assertFalse(self.command.process_pattern(1)) self.assertFalse(self.command.process_pattern(-1)) self.assertFalse(self.command.process_pattern(None)) # The following two will require mocking of pexpect? def test_run(self): """Test method ShellCommand.run(). """ pass def test_get_output(self): """Test method ShellCommand.get_output(). """ pass
Show line notes below