diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2010-06-21 06:26:20 +0200 |
---|---|---|
committer | Michele Simionato <michele.simionato@gmail.com> | 2010-06-21 06:26:20 +0200 |
commit | 403cf64f6fc6b45012a4e468cae1ffdd9c88784b (patch) | |
tree | a5aead6b7ab04169f26fb64b5efbe3127855aaaa | |
parent | f0cd41b6cb6cd0118a733d98c95fc57387953b6c (diff) | |
download | micheles-403cf64f6fc6b45012a4e468cae1ffdd9c88784b.tar.gz |
Improved the doctest method to re-raise the original exception
-rw-r--r-- | plac/doc/plac_adv.html | 6 | ||||
-rw-r--r-- | plac/doc/plac_adv.pdf | 56 | ||||
-rw-r--r-- | plac/doc/plac_adv.txt | 6 | ||||
-rw-r--r-- | plac/plac_ext.py | 11 |
4 files changed, 41 insertions, 38 deletions
diff --git a/plac/doc/plac_adv.html b/plac/doc/plac_adv.html index 908445a..a78b820 100644 --- a/plac/doc/plac_adv.html +++ b/plac/doc/plac_adv.html @@ -680,7 +680,7 @@ to use to test the file.</p> $ python -c"import plac, ishelve plac.Interpreter(ishelve.main).doctest(open('ishelve.placet'), verbose=True)" </pre> -<p>Internally <tt class="docutils literal">Interpreter.doctests</tt> invokes <tt class="docutils literal">Interpreter.check</tt> +<p>Internally <tt class="docutils literal">Interpreter.doctests</tt> invokes something like <tt class="docutils literal">Interpreter.check</tt> multiple times inside the same context and compare the output with the expected output: if even a check fails, the whole test fail. The easy tests supported by <tt class="docutils literal">plac</tt> are <em>not</em> unittests: they should be @@ -704,8 +704,8 @@ strings corresponding to the lines of the file).</p> module, but the situation may change in the future (it would be nice if <a class="reference external" href="http://pypi.python.org/pypi/plac">plac</a> could reuse doctests directives like ELLIPSIS).</p> <p>It is straighforward to integrate your <tt class="docutils literal">.placet</tt> tests with standard -testing tools. For instance, you can integrate your doctests with nose -or py.test as follow:</p> +testing tools. For instance, you can integrate your doctests with <tt class="docutils literal">nose</tt> +or <tt class="docutils literal">py.test</tt> as follow:</p> <pre class="literal-block"> import os, shlex, plac diff --git a/plac/doc/plac_adv.pdf b/plac/doc/plac_adv.pdf index 1d509d0..90e968a 100644 --- a/plac/doc/plac_adv.pdf +++ b/plac/doc/plac_adv.pdf @@ -1652,7 +1652,7 @@ endobj % 'R100': class PDFInfo
100 0 obj
<< /Author (Michele Simionato)
- /CreationDate (D:20100620110025-01'00')
+ /CreationDate (D:20100621062523-01'00')
/Keywords ()
/Producer (ReportLab http://www.reportlab.com)
/Subject (\(unspecified\))
@@ -2623,7 +2623,7 @@ endobj % 'R119': class PDFStream
119 0 obj
% page stream
-<< /Length 5794 >>
+<< /Length 5874 >>
stream
1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET
q
@@ -2682,7 +2682,7 @@ Q q
1 0 0 1 62.69291 469.0393 cm
q
-BT 1 0 0 1 0 52.82 Tm 2.74122 Tw 12 TL /F1 10 Tf 0 0 0 rg (Internally ) Tj /F4 10 Tf (Interpreter.doctests ) Tj /F1 10 Tf (invokes ) Tj /F4 10 Tf (Interpreter.check ) Tj /F1 10 Tf (multiple times inside the same) Tj T* 0 Tw 1.091098 Tw (context and compare the output with the expected output: if even a check fails, the whole test fail. The) Tj T* 0 Tw .568221 Tw (easy tests supported by ) Tj /F4 10 Tf (plac ) Tj /F1 10 Tf (are ) Tj /F5 10 Tf (not ) Tj /F1 10 Tf (unittests: they should be used to model user interaction when the) Tj T* 0 Tw .000574 Tw (order of the operations matters. Since the single subtests in a ) Tj /F4 10 Tf (.placet ) Tj /F1 10 Tf (file are not independent, it makes) Tj T* 0 Tw (sense to exit immediately at the first failure.) Tj T* ET
+BT 1 0 0 1 0 52.82 Tm 4.007109 Tw 12 TL /F1 10 Tf 0 0 0 rg (Internally ) Tj /F4 10 Tf (Interpreter.doctests ) Tj /F1 10 Tf (invokes something like ) Tj /F4 10 Tf (Interpreter.check ) Tj /F1 10 Tf (multiple times) Tj T* 0 Tw .226654 Tw (inside the same context and compare the output with the expected output: if even a check fails, the whole) Tj T* 0 Tw 2.628221 Tw (test fail. The easy tests supported by ) Tj /F4 10 Tf (plac ) Tj /F1 10 Tf (are ) Tj /F5 10 Tf (not ) Tj /F1 10 Tf (unittests: they should be used to model user) Tj T* 0 Tw .491163 Tw (interaction when the order of the operations matters. Since the single subtests in a ) Tj /F4 10 Tf (.placet ) Tj /F1 10 Tf (file are not) Tj T* 0 Tw (independent, it makes sense to exit immediately at the first failure.) Tj T* ET
Q
Q
q
@@ -2706,7 +2706,7 @@ Q q
1 0 0 1 62.69291 289.0393 cm
q
-BT 1 0 0 1 0 16.82 Tm 1.447318 Tw 12 TL /F1 10 Tf 0 0 0 rg (It is straighforward to integrate your ) Tj /F4 10 Tf (.placet ) Tj /F1 10 Tf (tests with standard testing tools. For instance, you can) Tj T* 0 Tw (integrate your doctests with nose or py.test as follow:) Tj T* ET
+BT 1 0 0 1 0 16.82 Tm 1.447318 Tw 12 TL /F1 10 Tf 0 0 0 rg (It is straighforward to integrate your ) Tj /F4 10 Tf (.placet ) Tj /F1 10 Tf (tests with standard testing tools. For instance, you can) Tj T* 0 Tw (integrate your doctests with ) Tj /F4 10 Tf (nose ) Tj /F1 10 Tf (or ) Tj /F4 10 Tf (py.test ) Tj /F1 10 Tf (as follow:) Tj T* ET
Q
Q
q
@@ -4528,42 +4528,42 @@ xref 0000041701 00000 n
0000045945 00000 n
0000052177 00000 n
-0000058074 00000 n
-0000062825 00000 n
-0000066908 00000 n
-0000071395 00000 n
-0000076595 00000 n
-0000080901 00000 n
-0000086351 00000 n
-0000090348 00000 n
-0000096101 00000 n
-0000102323 00000 n
-0000107138 00000 n
-0000107623 00000 n
-0000107935 00000 n
-0000108014 00000 n
-0000108093 00000 n
-0000108172 00000 n
-0000108251 00000 n
-0000108330 00000 n
-0000108409 00000 n
-0000108488 00000 n
-0000108567 00000 n
-0000108646 00000 n
+0000058154 00000 n
+0000062905 00000 n
+0000066988 00000 n
+0000071475 00000 n
+0000076675 00000 n
+0000080981 00000 n
+0000086431 00000 n
+0000090428 00000 n
+0000096181 00000 n
+0000102403 00000 n
+0000107218 00000 n
+0000107703 00000 n
+0000108015 00000 n
+0000108094 00000 n
+0000108173 00000 n
+0000108252 00000 n
+0000108331 00000 n
+0000108410 00000 n
+0000108489 00000 n
+0000108568 00000 n
+0000108647 00000 n
0000108726 00000 n
0000108806 00000 n
0000108886 00000 n
0000108966 00000 n
0000109046 00000 n
0000109126 00000 n
+0000109206 00000 n
trailer
<< /ID
% ReportLab generated PDF document -- digest (http://www.reportlab.com)
- [(\356\212\223m\215cGtv\230\324LxP\321{) (\356\212\223m\215cGtv\230\324LxP\321{)]
+ [(\275o9\206\006\260\252\254St*\243\362\376\031\013) (\275o9\206\006\260\252\254St*\243\362\376\031\013)]
/Info 100 0 R
/Root 99 0 R
/Size 148 >>
startxref
-109175
+109255
%%EOF
diff --git a/plac/doc/plac_adv.txt b/plac/doc/plac_adv.txt index 5e1146a..2bb6754 100644 --- a/plac/doc/plac_adv.txt +++ b/plac/doc/plac_adv.txt @@ -195,7 +195,7 @@ You can test ``ishelve.placet`` file by calling the $ python -c"import plac, ishelve plac.Interpreter(ishelve.main).doctest(open('ishelve.placet'), verbose=True)" -Internally ``Interpreter.doctests`` invokes ``Interpreter.check`` +Internally ``Interpreter.doctests`` invokes something like ``Interpreter.check`` multiple times inside the same context and compare the output with the expected output: if even a check fails, the whole test fail. The easy tests supported by ``plac`` are *not* unittests: they should be @@ -223,8 +223,8 @@ module, but the situation may change in the future (it would be nice if plac_ could reuse doctests directives like ELLIPSIS). It is straighforward to integrate your ``.placet`` tests with standard -testing tools. For instance, you can integrate your doctests with nose -or py.test as follow:: +testing tools. For instance, you can integrate your doctests with ``nose`` +or ``py.test`` as follow:: import os, shlex, plac diff --git a/plac/plac_ext.py b/plac/plac_ext.py index 54fc851..84bf91a 100644 --- a/plac/plac_ext.py +++ b/plac/plac_ext.py @@ -104,15 +104,13 @@ class Interpreter(object): exit(*sys.exc_info()) raise - def check(self, given_input, expected_output, lineno=None): + def check(self, given_input, expected_output): "Make sure you get the expected_output from the given_input" output = str(self.send(given_input)) ok = output == expected_output if not ok: msg = 'input: %s\noutput: %s\nexpected: %s' % ( given_input, output, expected_output) - if lineno: - msg = 'line %d: %s' % (lineno + 1, msg) raise AssertionError(msg) def _parse_doctest(self, lineiter): @@ -138,7 +136,12 @@ class Interpreter(object): out.write('i> %s\n' % input) out.write('-> %s\n' % output) out.flush() - self.check(input, output, no) + out = self.send(input) + if not out.str == output: + msg = 'line %d: input: %s\noutput: %s\nexpected: %s\n' % ( + no + 1, input, out, output) + out.write(msg) + raise out.etype, out.exc, out.tb def execute(self, lineiter, out=sys.stdout, verbose=False): """ |