Merge lp:~nmb/bzr/662509-ignore-blanks into lp:bzr

Proposed by Neil Martinsen-Burrell
Status: Merged
Merged at revision: 5532
Proposed branch: lp:~nmb/bzr/662509-ignore-blanks
Merge into: lp:bzr
Diff against target: 156 lines (+53/-12)
4 files modified
bzrlib/tests/script.py (+22/-7)
bzrlib/tests/test_script.py (+8/-0)
doc/developers/testing.txt (+19/-5)
doc/en/release-notes/bzr-2.3.txt (+4/-0)
To merge this branch: bzr merge lp:~nmb/bzr/662509-ignore-blanks
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Martin Pool Pending
Poolie Pending
Review via email: mp+38889@code.launchpad.net

Commit message

Add 'ignore_output' parameter to run_script.

Description of the change

This change provides and ignore_blanks argument to run_script to allow for the previous default behavior of unspecified output not being matched.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

s/ignore_blanks/ignore_output/ is almost my only comment.

This is exactly how I wanted to implement it.

When we add keywords arguments, we try to also use them as such so:

38 + def run_script(self, script, ignore_blanks=False):
39 + return self.script_runner.run_script(self, script, ignore_blanks)

ignore_output=ignore_output

The idea is that if we add more mandatory arguments the above (erroneous) call *may* fail later, whereas using the keyword form ensures that it fails right there, at the call.

49 + def run_script(self, script, ignore_blanks=False):
50 + return self.script_runner.run_script(self, script, ignore_blanks)

60 + return ScriptRunner().run_script(test_case, script_string, ignore_blanks)

idem

74 +If output occurs and no output is expected, the execution stops and the
75 +test fails. If unexpected output occurs on the standard error, then
76 +execution stops.

Good catch !

So ignore_output=False can even be check_output=True

 +irrelevant, the run_script() method may be passed the keyword argument
101 +``ignore_blanks=True``. For example::
102 +
103 + def test_ignoring_blank_output(self):

Don't forget to rename here too.

I let poolie be the second reviewer here but my 'NeedsFixing' vote is really bb:tweak.

review: Needs Fixing
Revision history for this message
Vincent Ladeuil (vila) wrote :

For the record: I reviewed here *before* reading the bug report and its comments.

Not that it matters that much, I still like this proposal :)

Revision history for this message
Vincent Ladeuil (vila) wrote :

No more comments except: well done :)

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Martin Pool (mbp) wrote :

Thanks for adding this.

btw my lp userid is 'mbp' not poolie; it's a bit of a usability bug
you could make that error.

To me 'ignore_output' means "don't pay attention to the output at
all", which is not I think what you're doing here. We want something
that says that blank expected output matches anything. Maybe
'blank_output_matches_anything'?

The number of places that need to be updated in script.py suggests
there may be too much repetition there already.

>
> -When no output is specified, any ouput from the command is accepted
> -and execution continue.
> +If output occurs and no output is expected, the execution stops and the
> +test fails.  If unexpected output occurs on the standard error, then
> +execution stops.

Thanks for fixing the typo. I'm not sure if you're specifically
trying to draw a distinction between unexpected text on stdout and
stderr, and if so whether it's true. Are you saying that unexpected
stderr makes execution stop but the test doesn't fail?

>
>  If an error occurs and no expected error is specified, the execution stops.
>
> @@ -447,11 +448,11 @@
>     def test_unshelve_keep(self):
>         # some setup here
>         script.run_script(self, '''
> -            $ bzr add file
> -            $ bzr shelve --all -m Foo
> +            $ bzr add -q file
> +            $ bzr shelve -q --all -m Foo
>             $ bzr shelve --list
>             1: Foo
> -            $ bzr unshelve --keep
> +            $ bzr unshelve -q --keep
>             $ bzr shelve --list
>             1: Foo
>             $ cat file
> @@ -471,6 +472,19 @@
>             yes
>             """)
>
> +To avoid having to specify "-q" for all commands whose output is
> +irrelevant, the run_script() method may be passed the keyword argument
> +``ignore_blanks=True``.  For example::
> +
> +    def test_ignoring_blank_output(self):
> +        self.run_script("""
> +            $ bzr init
> +            $ bzr ci -m 'first revision' --unchanged
> +            $ bzr log --line
> +            1: ...
> +            """
> +
> +

but you don't seem to actually pass this option?

Can you also just make clear if how this handles stderr output?

It seems like we should doctest testing.txt, but doing so may take
some larger changes.

>  Import tariff tests
>  -------------------
>
>
> === modified file 'doc/en/release-notes/bzr-2.3.txt'
> --- doc/en/release-notes/bzr-2.3.txt    2010-10-18 21:34:05 +0000
> +++ doc/en/release-notes/bzr-2.3.txt    2010-10-19 20:54:48 +0000
> @@ -99,6 +99,10 @@
>   Instead, use '...' as a wildcard if you don't care about the output.
>   (Martin Pool, #637830)
>
> +* Add an ignore_blanks keyword argument with default False to
> +  bzrlib.tests.script.ScriptRunner.run_script to specify if missing
> +  output does not need to be matched.  (Neil Martinsen-Burrell, #662509)
> +
>  * ``bzr test-script script`` is a new command that runs a shell-like script
>   from an the ``script`` file. (Vincent Ladeuil)
>
>
>
>

--
Martin

Revision history for this message
Vincent Ladeuil (vila) wrote :

Messages crossed on the wire, this has already landed.

I should add support for the option to the 'run_script' command anyway, so I will take your remarks into account there until nmb beats me to it.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Meh, s/until/unless/...

Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

Shall I submit a follow-on patch re-naming the option? I would also like to clarify the stderr situation (because it does make the test fail) and the documentation should just come out and say that.

I'm not clear about the interaction between PQM and launchpad: can I use this mp to make those changes or should I start a new one once this lands in PQM?

Revision history for this message
Martin Pool (mbp) wrote :

On 26 October 2010 09:41:16 UTC-4, Neil Martinsen-Burrell
<email address hidden> wrote:
> Shall I submit a follow-on patch re-naming the option?  I would also like to
> clarify the stderr situation (because it does make the test fail) and the
> documentation should just come out and say that.

That would be good.

> I'm not clear about the interaction between PQM and launchpad: can I use
> this mp to make those changes or should I start a new one once this lands in
> PQM?

You could reuse this one but I think it would be clearer to start a
new mp. It can come from the same branch.
--
Martin

Revision history for this message
John A Meinel (jameinel) wrote :

If you make the changes and push, then it will show up here. Just make sure to make a comment so we know it is ready for review. (Just setting it back to "Needs Review" also works)

Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

I've changed the option name and mentioned that it also ignores unspecified output on standard errror.

Revision history for this message
Martin Pool (mbp) wrote :

+1, that looks reasonable to me.

--
Martin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/tests/script.py'
--- bzrlib/tests/script.py 2010-10-28 00:06:59 +0000
+++ bzrlib/tests/script.py 2010-11-05 03:06:51 +0000
@@ -196,7 +196,8 @@
196 self.output_checker = doctest.OutputChecker()196 self.output_checker = doctest.OutputChecker()
197 self.check_options = doctest.ELLIPSIS197 self.check_options = doctest.ELLIPSIS
198198
199 def run_script(self, test_case, text):199 def run_script(self, test_case, text,
200 blank_output_matches_anything=False):
200 """Run a shell-like script as a test.201 """Run a shell-like script as a test.
201202
202 :param test_case: A TestCase instance that should provide the fail(),203 :param test_case: A TestCase instance that should provide the fail(),
@@ -204,7 +205,12 @@
204 attribute used as a jail root.205 attribute used as a jail root.
205206
206 :param text: A shell-like script (see _script_to_commands for syntax).207 :param text: A shell-like script (see _script_to_commands for syntax).
208
209 :param blank_output_matches_anything: For commands with no specified
210 output, ignore any output that does happen, including output on
211 standard error.
207 """212 """
213 self.blank_output_matches_anything = blank_output_matches_anything
208 for cmd, input, output, error in _script_to_commands(text):214 for cmd, input, output, error in _script_to_commands(text):
209 self.run_command(test_case, cmd, input, output, error)215 self.run_command(test_case, cmd, input, output, error)
210216
@@ -245,6 +251,12 @@
245 else:251 else:
246 test_case.fail('expected output: %r, but found nothing'252 test_case.fail('expected output: %r, but found nothing'
247 % (expected,))253 % (expected,))
254
255 blank_output_matches_anything = getattr(self,
256 'blank_output_matches_anything', False)
257 if blank_output_matches_anything and expected is None:
258 return
259
248 expected = expected or ''260 expected = expected or ''
249 matching = self.output_checker.check_output(261 matching = self.output_checker.check_output(
250 expected, actual, self.check_options)262 expected, actual, self.check_options)
@@ -473,8 +485,9 @@
473 super(TestCaseWithMemoryTransportAndScript, self).setUp()485 super(TestCaseWithMemoryTransportAndScript, self).setUp()
474 self.script_runner = ScriptRunner()486 self.script_runner = ScriptRunner()
475487
476 def run_script(self, script):488 def run_script(self, script, blank_output_matches_anything=False):
477 return self.script_runner.run_script(self, script)489 return self.script_runner.run_script(self, script,
490 blank_output_matches_anything=blank_output_matches_anything)
478491
479 def run_command(self, cmd, input, output, error):492 def run_command(self, cmd, input, output, error):
480 return self.script_runner.run_command(self, cmd, input, output, error)493 return self.script_runner.run_command(self, cmd, input, output, error)
@@ -502,14 +515,16 @@
502 super(TestCaseWithTransportAndScript, self).setUp()515 super(TestCaseWithTransportAndScript, self).setUp()
503 self.script_runner = ScriptRunner()516 self.script_runner = ScriptRunner()
504517
505 def run_script(self, script):518 def run_script(self, script, blank_output_matches_anything=False):
506 return self.script_runner.run_script(self, script)519 return self.script_runner.run_script(self, script,
520 blank_output_matches_anything=blank_output_matches_anything)
507521
508 def run_command(self, cmd, input, output, error):522 def run_command(self, cmd, input, output, error):
509 return self.script_runner.run_command(self, cmd, input, output, error)523 return self.script_runner.run_command(self, cmd, input, output, error)
510524
511525
512def run_script(test_case, script_string):526def run_script(test_case, script_string, blank_output_matches_anything=False):
513 """Run the given script within a testcase"""527 """Run the given script within a testcase"""
514 return ScriptRunner().run_script(test_case, script_string)528 return ScriptRunner().run_script(test_case, script_string,
529 blank_output_matches_anything=blank_output_matches_anything)
515530
516531
=== modified file 'bzrlib/tests/test_script.py'
--- bzrlib/tests/test_script.py 2010-10-27 23:27:41 +0000
+++ bzrlib/tests/test_script.py 2010-11-05 03:06:51 +0000
@@ -186,6 +186,14 @@
186 $ echo foo186 $ echo foo
187 """)187 """)
188188
189 def test_blank_output_matches_option(self):
190 """If you want blank output to be a wild card, you can pass
191 blank_output_matches_anything to run_script"""
192 self.run_script(
193 """
194 $ echo foo
195 """, blank_output_matches_anything=True)
196
189 def test_ellipsis_everything(self):197 def test_ellipsis_everything(self):
190 """A simple ellipsis matches everything."""198 """A simple ellipsis matches everything."""
191 self.run_script("""199 self.run_script("""
192200
=== modified file 'doc/developers/testing.txt'
--- doc/developers/testing.txt 2010-10-13 07:55:13 +0000
+++ doc/developers/testing.txt 2010-11-05 03:06:51 +0000
@@ -367,8 +367,9 @@
367The execution stops as soon as an expected output or an expected error is not367The execution stops as soon as an expected output or an expected error is not
368matched.368matched.
369369
370When no output is specified, any ouput from the command is accepted370If output occurs and no output is expected, the execution stops and the
371and execution continue.371test fails. If unexpected output occurs on the standard error, then
372execution stops and the test fails.
372373
373If an error occurs and no expected error is specified, the execution stops.374If an error occurs and no expected error is specified, the execution stops.
374375
@@ -447,11 +448,11 @@
447 def test_unshelve_keep(self):448 def test_unshelve_keep(self):
448 # some setup here449 # some setup here
449 script.run_script(self, '''450 script.run_script(self, '''
450 $ bzr add file451 $ bzr add -q file
451 $ bzr shelve --all -m Foo452 $ bzr shelve -q --all -m Foo
452 $ bzr shelve --list453 $ bzr shelve --list
453 1: Foo454 1: Foo
454 $ bzr unshelve --keep455 $ bzr unshelve -q --keep
455 $ bzr shelve --list456 $ bzr shelve --list
456 1: Foo457 1: Foo
457 $ cat file458 $ cat file
@@ -471,6 +472,19 @@
471 yes472 yes
472 """)473 """)
473474
475To avoid having to specify "-q" for all commands whose output is
476irrelevant, the run_script() method may be passed the keyword argument
477``blank_output_matches_anything=True``. For example::
478
479 def test_ignoring_blank_output(self):
480 self.run_script("""
481 $ bzr init
482 $ bzr ci -m 'first revision' --unchanged
483 $ bzr log --line
484 1: ...
485 """, blank_output_matches_anything=True)
486
487
474Import tariff tests488Import tariff tests
475-------------------489-------------------
476490
477491
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- doc/en/release-notes/bzr-2.3.txt 2010-11-02 22:23:40 +0000
+++ doc/en/release-notes/bzr-2.3.txt 2010-11-05 03:06:51 +0000
@@ -109,6 +109,10 @@
109 Instead, use '...' as a wildcard if you don't care about the output.109 Instead, use '...' as a wildcard if you don't care about the output.
110 (Martin Pool, #637830)110 (Martin Pool, #637830)
111111
112* Add a blank_output_matches_anything keyword argument with default False to
113 bzrlib.tests.script.ScriptRunner.run_script to specify if missing
114 output does not need to be matched. (Neil Martinsen-Burrell, #662509)
115
112* ``bzr test-script script`` is a new command that runs a shell-like script116* ``bzr test-script script`` is a new command that runs a shell-like script
113 from an the ``script`` file. (Vincent Ladeuil)117 from an the ``script`` file. (Vincent Ladeuil)
114118