Rev 4672: Simplify output/errors handling. in file:///home/vila/src/bzr/experimental/shell-like-tests/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Sep 1 15:44:16 BST 2009
At file:///home/vila/src/bzr/experimental/shell-like-tests/
------------------------------------------------------------
revno: 4672
revision-id: v.ladeuil+lp at free.fr-20090901144416-eooxqi89bxsxli60
parent: v.ladeuil+lp at free.fr-20090901124610-22vnmwr647x8f3jz
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: shell-like-tests
timestamp: Tue 2009-09-01 16:44:16 +0200
message:
Simplify output/errors handling.
* bzrlib/tests/test_script.py:
Update tests expecting output/errors.
* bzrlib/tests/script.py:
(_script_to_commands.add_command): Factor out and reformat
output/error as simple strings.
-------------- next part --------------
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py 2009-09-01 12:46:10 +0000
+++ b/bzrlib/tests/script.py 2009-09-01 14:44:16 +0000
@@ -51,7 +51,19 @@
Output lines start with '>'.
Error lines start with '2>'.
"""
+
commands = []
+
+ def add_command(cmd, input, output, error):
+ if cmd is not None:
+ if input is not None:
+ input = ''.join(input)
+ if output is not None:
+ output = ''.join(output)
+ if error is not None:
+ error = ''.join(error)
+ commands.append((cmd, input, output, error))
+
cmd_cur = None
cmd_line = 1
lineno = 0
@@ -94,15 +106,13 @@
continue
else:
# Time to output the current command
- if cmd_cur is not None:
- commands.append((cmd_cur, input, output, error))
+ add_command(cmd_cur, input, output, error)
# And start a new one
cmd_cur = list(split(line))
cmd_line = lineno
input, output, error = None, None, None
# Add the last seen command
- if cmd_cur is not None:
- commands.append((cmd_cur, input, output, error))
+ add_command(cmd_cur, input, output, error)
return commands
@@ -120,8 +130,7 @@
if expected is None:
# Specifying None means: any output is accepted
return
- str_expected = ''.join(expected)
- self.assertEquals(str_expected, actual)
+ self.assertEquals(expected, actual)
def run_command(self, cmd, input, output, error):
mname = 'do_' + cmd[0]
=== modified file 'bzrlib/tests/test_script.py'
--- a/bzrlib/tests/test_script.py 2009-09-01 12:46:10 +0000
+++ b/bzrlib/tests/test_script.py 2009-09-01 14:44:16 +0000
@@ -47,15 +47,17 @@
script._script_to_commands(story))
def test_command_with_input(self):
- self.assertEquals([(['cat', '>file'], ['content\n'], None, None)],
+ self.assertEquals([(['cat', '>file'], 'content\n', None, None)],
script._script_to_commands('cat >file\n<content\n'))
def test_command_with_output(self):
story = """
bzr add
>adding file
+>adding file2
"""
- self.assertEquals([(['bzr', 'add'], None, ['adding file\n'], None)],
+ self.assertEquals([(['bzr', 'add'], None,
+ 'adding file\nadding file2\n', None)],
script._script_to_commands(story))
def test_command_with_error(self):
@@ -64,7 +66,7 @@
2>bzr: ERROR: Not a branch: "foo"
"""
self.assertEquals([(['bzr', 'branch', 'foo'],
- None, None, ['bzr: ERROR: Not a branch: "foo"\n'])],
+ None, None, 'bzr: ERROR: Not a branch: "foo"\n')],
script._script_to_commands(story))
def test_input_without_command(self):
self.assertRaises(SyntaxError, script._script_to_commands, '<input')
@@ -101,14 +103,14 @@
self.assertRaises(SyntaxError, self.run_script, 'cat foo bar baz')
def test_cat_input_to_output(self):
- out, err = self.run_command(['cat'], ['content\n'], ['content\n'], None)
+ out, err = self.run_command(['cat'], 'content\n', 'content\n', None)
def test_cat_file_to_output(self):
self.build_tree_contents([('file', 'content\n')])
- out, err = self.run_command(['cat', 'file'], None, ['content\n'], None)
+ out, err = self.run_command(['cat', 'file'], None, 'content\n', None)
def test_cat_input_to_file(self):
- out, err = self.run_command(['cat', '>file'], ['content\n'], None, None)
+ out, err = self.run_command(['cat', '>file'], 'content\n', None, None)
self.assertFileEqual('content\n', 'file')
def test_cat_file_to_file(self):
More information about the bazaar-commits
mailing list