[bug] bzr commit with nothing changed fails with the wrong exception

John Arbash Meinel john at arbash-meinel.com
Mon Jun 26 16:34:55 BST 2006


Aaron Bentley wrote:
> John Arbash Meinel wrote:
>>> I'm not sure if trapping the output of run_bzr is the best thing, but we
>>> should start writing some interface tests that measure what the user is
>>> actually seeing, so that we know our errors are being helpful.
> 
> I think we should trap the output of run_bzr, but I think we should add
> infrastructure to make it easy to check that the error matches a given
> regex.  (And yes, I think it's okay to require that the blackbox tests
> be run in English.)
> 
> e.g.
> 
> def run_bzr_error(self, error, *args, **kwargs):
>     stderr = self.run_bzr(retcode=3, *args, **kwargs)[1]
>     self.assertContainsRe(error, stderr)
>>> ------------------------------------------------------------------------
>>>
>>> # Bazaar revision bundle v0.8
>>> #
> 
> Err...
> 
> Aaron


This is what I wrote for a project of mine.

It might be a little bit too 'magical' for bzr, but basically it lets
you supply a 'stdout=' which ensures the exact text, or a out_regex=[]
which is a list of regexes which must match.
By having a list of regexes, you can match multiple lines, rather than
requiring that the person figures out a regex which checks everything at
one time.

It also defaults such that if you don't supply 'stdout/stderr' that
nothing is written there. (Though if you use err_regex=[] it will ignore
that case).

I'm not 100% happy with it, but I'm about 90%.

John
=:->


def run_main_expected(self, *args, **kwargs):
    """call run_main, and assert the output is what we expect

    Optional args:
        stdout  A string indicating expected output. If not supplied
                defaults to the empty string.
        stderr  Expected error output. Defaults to empty string.
        out_regex   A list of regexes to expect on the input.
                    This will override stdout
        err_regex   Same as out_regex, only for stderr
    """
    stdout = kwargs.pop('stdout', '')
    stderr = kwargs.pop('stderr', '')
    out_regex = kwargs.pop('out_regex', None)
    err_regex = kwargs.pop('err_regex', None)

    out, err = self.run_main(*args, **kwargs)

    if stdout or out_regex is None:
        self.assertEqualDiff(stdout, out)
    if stderr or err_regex is None:
        self.assertEqualDiff(stderr, err)

    if out_regex is not None:
        for regex in out_regex:
            self.assertContainsRe(regex, out)
    if err_regex is not None:
        for regex in err_regex:
            self.assertContainsRe(regex, err)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060626/94037835/attachment.pgp 


More information about the bazaar mailing list