shell-like test impressions

Martin Pool mbp at canonical.com
Fri Dec 11 05:52:09 GMT 2009


I thought I'd write the 'unshelve --keep' patch using shell-like
tests. <https://code.edge.launchpad.net/~mbp/bzr/492091-unshelve-keep>

Some impressions:

The shell-prompt must be flush left or you get a mysterious error
(which my patch makes a bit less mysterious).  Especially because the
docstring seems to say you can do this.  We should probably ignore
leading whitespace(?) or at least consistent leading whitespace.

Similarly, if the closing quote is one line too low, the ScriptRunner
complains about the extra blank line, and it should be a bit more
reasonable somehow.

When the output does not match you get
^^^^[log from bzrlib.tests.blackbox.test_shelve.TestShelveList.test_unshelve_keep]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mbp/bzr/492091-shelve-show/bzrlib/tests/blackbox/test_shelve.py",
line 83, in test_unshelve_keep
    ''')
  File "/home/mbp/bzr/492091-shelve-show/bzrlib/tests/script.py", line
194, in run_script
    self.run_command(test_case, cmd, input, output, error)
  File "/home/mbp/bzr/492091-shelve-show/bzrlib/tests/script.py", line
210, in run_command
    self._check_output(output, actual_output, test_case)
  File "/home/mbp/bzr/492091-shelve-show/bzrlib/tests/script.py", line
233, in _check_output
    test_case.assertEqualDiff(expected, actual)
AssertionError: texts not equal:
-   1: Foo

and it would be nice if it said what the command was etc.

I could turn these into bugs, but... they're kind of small, and better
perhaps to fix them in passing next time.

I'd say the actual test worked quite well, and is something I can
imagine new contributors being quite comfortable writing.  I haven't
written a test for shelf before and it's easier to work from the cli
you know than to learn about the api.  Against that it has to be said
that this is probably going to be somewhat slower than using the api
directly, in that we'll be reopening the tree every time.  However it
does seem feasible that we could map some of these into faster paths
when they're not specifically under test: ScriptRunner provides
builtins for things like 'cat' and you could potentially have a
builtin that makes a tree with some history.

    def test_unshelve_keep(self):
        # https://bugs.edge.launchpad.net/bzr/+bug/492091
        tree = self.make_branch_and_tree('.')
        # shelve apparently unhappy working with a tree with no root yet
        tree.commit('make root')
        self.build_tree(['file'])

        sr = ScriptRunner()
        sr.run_script(self, '''
$ bzr add file
$ bzr shelve --all -m Foo
$ bzr shelve --list
  1: Foo
$ bzr unshelve --keep
$ bzr shelve --list
  1: Foo
$ cat file
contents of file
''')

-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list