[merge] cleanup remerge tests

John Arbash Meinel john at arbash-meinel.com
Fri Jun 30 14:37:19 BST 2006

Hash: SHA1

Martin Pool wrote:
> On 29 Jun 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
>> Hash: SHA1
>> The attached bundle has one small bugfix, and a bunch of test cleanup.
>> While trying to fix win32, I found that the remerge test was failing.
>> While looking deeper, I found out that the part that was succeeding was
>> actually an accident. We were getting retcode=3 because of the wrong reason.
>> So I went ahead and updated the remerge tests, moving them into their
>> own file, and writing run_bzr_error to make it nicer to verify we are
>> getting the error we expect.
>> I haven't fixed anything to actually work on win32 yet, but I figured
>> this cleanup is good enough to be merged by itself.
>> I also found one small bug with an error message that was missing a space.
> That looks good; just one comment
>> === modified file bzrlib/tests/__init__.py
>> --- bzrlib/tests/__init__.py
>> +++ bzrlib/tests/__init__.py
>> @@ -739,6 +739,12 @@
>>              encoding = bzrlib.user_encoding
>>          return self.run_bzr(*args, **kwargs)[0].decode(encoding)
>> +    def run_bzr_error(self, error_regexes, *args, **kwargs):
>> +        """Run bzr, and check that stderr contains the supplied regexes"""
>> +        out, err = self.run_bzr(*args, **kwargs)
>> +        for regex in error_regexes:
>> +            self.assertContainsRe(err, regex)
>> +
> Maybe the docstring could be expanded a bit because the varargs are
> somewhat unclear:
>   :param error_regexes: Sequence of regular expressions which must 
>       each individually be found in the output.  The relative ordering
>       of them is not enforced.
>   :param args: List of command line arguments for bzr.
>   :param retcode: May be given as a keyword argument to set the expected
>       return code; the default is 0.
> Or perhaps people should just grep for examples?

This is what I changed it to:
"""Run bzr, and check that stderr contains the supplied regexes

:param error_regexes: Sequence of regular expressions which
    must each be found in the error output. The relative ordering
    is not enforced.
:param args: command-line arguments for bzr
:param kwargs: Keyword arguments which are interpreted by run_bzr
    This function changes the default value of retcode to be 3,
    since in most cases this is run when you expect bzr to fail.
:return: (out, err) The actual output of running the command (in case
         you want to do more inspection)

Examples of use:
    # Make sure that commit is failing because there is nothing to do
    self.run_bzr_error(['no changes to commit'],
                       'commit', '-m', 'my commit comment')
    # Make sure --strict is handling an unknown file, rather than
    # giving us the 'nothing to do' error
    self.run_bzr_error(['Commit refused because there are unknown'],
                       'commit', '--strict', '-m', 'my commit comment')

I hope the example makes it clear how to use it in the common case.

I've thought about just adding all of things as keyword arguments to the
regular 'run_bzr' command. Then you could do:

self.run_bzr('command', 'foo',
	     stderr_regexes=['a', 'b'],

That is how I use it in my personal work. At that point, run_bzr just
starts inspecting the kwargs to see if any special parameters are set.
And it can do the assertion that nothing is printed to stdout, etc.

Do you prefer this form? We already have 3 kwargs arguments: encoding,
retcode, and stdin. It is simple to add a few more, and have them
perform the associated assertions.

I personally prefer it, but we had already discussed and approved the
run_bzr_error() function.


Version: GnuPG v1.4.1 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the bazaar mailing list