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
1=== modified file 'bzrlib/tests/script.py'
2--- bzrlib/tests/script.py 2010-10-28 00:06:59 +0000
3+++ bzrlib/tests/script.py 2010-11-05 03:06:51 +0000
4@@ -196,7 +196,8 @@
5 self.output_checker = doctest.OutputChecker()
6 self.check_options = doctest.ELLIPSIS
7
8- def run_script(self, test_case, text):
9+ def run_script(self, test_case, text,
10+ blank_output_matches_anything=False):
11 """Run a shell-like script as a test.
12
13 :param test_case: A TestCase instance that should provide the fail(),
14@@ -204,7 +205,12 @@
15 attribute used as a jail root.
16
17 :param text: A shell-like script (see _script_to_commands for syntax).
18+
19+ :param blank_output_matches_anything: For commands with no specified
20+ output, ignore any output that does happen, including output on
21+ standard error.
22 """
23+ self.blank_output_matches_anything = blank_output_matches_anything
24 for cmd, input, output, error in _script_to_commands(text):
25 self.run_command(test_case, cmd, input, output, error)
26
27@@ -245,6 +251,12 @@
28 else:
29 test_case.fail('expected output: %r, but found nothing'
30 % (expected,))
31+
32+ blank_output_matches_anything = getattr(self,
33+ 'blank_output_matches_anything', False)
34+ if blank_output_matches_anything and expected is None:
35+ return
36+
37 expected = expected or ''
38 matching = self.output_checker.check_output(
39 expected, actual, self.check_options)
40@@ -473,8 +485,9 @@
41 super(TestCaseWithMemoryTransportAndScript, self).setUp()
42 self.script_runner = ScriptRunner()
43
44- def run_script(self, script):
45- return self.script_runner.run_script(self, script)
46+ def run_script(self, script, blank_output_matches_anything=False):
47+ return self.script_runner.run_script(self, script,
48+ blank_output_matches_anything=blank_output_matches_anything)
49
50 def run_command(self, cmd, input, output, error):
51 return self.script_runner.run_command(self, cmd, input, output, error)
52@@ -502,14 +515,16 @@
53 super(TestCaseWithTransportAndScript, self).setUp()
54 self.script_runner = ScriptRunner()
55
56- def run_script(self, script):
57- return self.script_runner.run_script(self, script)
58+ def run_script(self, script, blank_output_matches_anything=False):
59+ return self.script_runner.run_script(self, script,
60+ blank_output_matches_anything=blank_output_matches_anything)
61
62 def run_command(self, cmd, input, output, error):
63 return self.script_runner.run_command(self, cmd, input, output, error)
64
65
66-def run_script(test_case, script_string):
67+def run_script(test_case, script_string, blank_output_matches_anything=False):
68 """Run the given script within a testcase"""
69- return ScriptRunner().run_script(test_case, script_string)
70+ return ScriptRunner().run_script(test_case, script_string,
71+ blank_output_matches_anything=blank_output_matches_anything)
72
73
74=== modified file 'bzrlib/tests/test_script.py'
75--- bzrlib/tests/test_script.py 2010-10-27 23:27:41 +0000
76+++ bzrlib/tests/test_script.py 2010-11-05 03:06:51 +0000
77@@ -186,6 +186,14 @@
78 $ echo foo
79 """)
80
81+ def test_blank_output_matches_option(self):
82+ """If you want blank output to be a wild card, you can pass
83+ blank_output_matches_anything to run_script"""
84+ self.run_script(
85+ """
86+ $ echo foo
87+ """, blank_output_matches_anything=True)
88+
89 def test_ellipsis_everything(self):
90 """A simple ellipsis matches everything."""
91 self.run_script("""
92
93=== modified file 'doc/developers/testing.txt'
94--- doc/developers/testing.txt 2010-10-13 07:55:13 +0000
95+++ doc/developers/testing.txt 2010-11-05 03:06:51 +0000
96@@ -367,8 +367,9 @@
97 The execution stops as soon as an expected output or an expected error is not
98 matched.
99
100-When no output is specified, any ouput from the command is accepted
101-and execution continue.
102+If output occurs and no output is expected, the execution stops and the
103+test fails. If unexpected output occurs on the standard error, then
104+execution stops and the test fails.
105
106 If an error occurs and no expected error is specified, the execution stops.
107
108@@ -447,11 +448,11 @@
109 def test_unshelve_keep(self):
110 # some setup here
111 script.run_script(self, '''
112- $ bzr add file
113- $ bzr shelve --all -m Foo
114+ $ bzr add -q file
115+ $ bzr shelve -q --all -m Foo
116 $ bzr shelve --list
117 1: Foo
118- $ bzr unshelve --keep
119+ $ bzr unshelve -q --keep
120 $ bzr shelve --list
121 1: Foo
122 $ cat file
123@@ -471,6 +472,19 @@
124 yes
125 """)
126
127+To avoid having to specify "-q" for all commands whose output is
128+irrelevant, the run_script() method may be passed the keyword argument
129+``blank_output_matches_anything=True``. For example::
130+
131+ def test_ignoring_blank_output(self):
132+ self.run_script("""
133+ $ bzr init
134+ $ bzr ci -m 'first revision' --unchanged
135+ $ bzr log --line
136+ 1: ...
137+ """, blank_output_matches_anything=True)
138+
139+
140 Import tariff tests
141 -------------------
142
143
144=== modified file 'doc/en/release-notes/bzr-2.3.txt'
145--- doc/en/release-notes/bzr-2.3.txt 2010-11-02 22:23:40 +0000
146+++ doc/en/release-notes/bzr-2.3.txt 2010-11-05 03:06:51 +0000
147@@ -109,6 +109,10 @@
148 Instead, use '...' as a wildcard if you don't care about the output.
149 (Martin Pool, #637830)
150
151+* Add a blank_output_matches_anything keyword argument with default False to
152+ bzrlib.tests.script.ScriptRunner.run_script to specify if missing
153+ output does not need to be matched. (Neil Martinsen-Burrell, #662509)
154+
155 * ``bzr test-script script`` is a new command that runs a shell-like script
156 from an the ``script`` file. (Vincent Ladeuil)
157