garybernhardt / mote

A very experimental spec runner for Python. Beware: it is incomplete and changes often!

Clone this repository (size: 152.9 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/garybernhardt/mote/
commit 111: 1a6fba8232b9
parent 110: bb14ce54a121
branch: default
Re-added reporting of import errors when using non-machine-out output
Gary Bernhardt
8 months ago

Changed (Δ1.6 KB):

raw changeset »

mote/__init__.py (6 lines added, 0 lines removed)

tests/system/test_mote.py (18 lines added, 0 lines removed)

tests/unit/test_quiet_printer.py (17 lines added, 0 lines removed)

tests/unit/test_spec_output_printer.py (17 lines added, 0 lines removed)

Up to file-list mote/__init__.py:

@@ -223,12 +223,18 @@ class SpecOutputPrinter:
223
223
            else:
224
224
                self._print_case(context)
225
225
226
    def handle_import_failure(self, exc_info):
227
        raise
228
226
229
227
230
class QuietPrinter:
228
231
    def print_suite(self, suite):
229
232
        message = 'OK' if suite.success else 'Specs failed'
230
233
        stdout.write('%s\n' % message)
231
234
235
    def handle_import_failure(self, exc_info):
236
        raise
237
232
238
233
239
class MachineOutputPrinter:
234
240
    def print_suite(self, suite):

Up to file-list tests/system/test_mote.py:

@@ -29,6 +29,9 @@ class SystemTest(object):
29
29
                'Expected output:\n---\n%s\n---\nbut got:\n---\n%s\n---\n' %
30
30
                (expected_output, output))
31
31
32
    def _assert_output_contains(self, expected_output, args=None):
33
        assert dedent(expected_output) in self._output(args=args)
34
32
35
    def _assert_succeeds(self):
33
36
        self._assert_output_equals('OK\n', args=['--quiet'])
34
37
@@ -362,3 +365,18 @@ class WhenMultipleTestFilesAreGivenAsArg
362
365
            ''',
363
366
            test_paths=self.paths)
364
367
368
369
class WhenASpecFileFailsToImport(SystemTest):
370
    def setup(self):
371
        super(WhenASpecFileFailsToImport, self).setup()
372
        self._write_test_file('raise Exception')
373
374
    def should_print_traceback(self):
375
        self._assert_output_contains(
376
            'line 1, in <module>\n    raise Exception')
377
378
    def should_print_traceback_when_running_quietly(self):
379
        self._assert_output_contains(
380
            'line 1, in <module>\n    raise Exception',
381
            args=['-q'])
382

Up to file-list tests/unit/test_quiet_printer.py:

1
1
import sys
2
2
3
from nose.tools import assert_raises
3
4
from dingus import Dingus, DingusTestCase
5
4
6
import mote
5
7
from mote import QuietPrinter
6
8
from tests.unit.patchedstdout import PatchedStdoutMixin
@@ -29,3 +31,18 @@ class WhenCasesFail(BaseFixture):
29
31
    def should_print_failure_message(self):
30
32
        assert self._printed_lines() == ['Specs failed\n']
31
33
34
35
class WhenHandlingImportErrors(BaseFixture):
36
    class FakeError(Exception):
37
        pass
38
39
    def should_reraise_errors(self):
40
        assert_raises(self.FakeError, self._handle_error)
41
42
    def _handle_error(self):
43
        printer = QuietPrinter()
44
        try:
45
            raise self.FakeError
46
        except self.FakeError:
47
            printer.handle_import_failure(sys.exc_info())
48

Up to file-list tests/unit/test_spec_output_printer.py:

1
1
import sys
2
2
3
from nose.tools import assert_raises
3
4
from dingus import Dingus, DingusTestCase
5
4
6
import mote
5
7
from mote import SpecOutputPrinter
6
8
from tests.unit.patchedstdout import PatchedStdoutMixin
@@ -92,3 +94,18 @@ class WhenCasesAreInNestedContexts(WithP
92
94
                                         '  - case\n',
93
95
                                         'OK\n']
94
96
97
98
class WhenHandlingImportErrors(WithPatchedStdOut):
99
    class FakeError(Exception):
100
        pass
101
102
    def should_reraise_errors(self):
103
        assert_raises(self.FakeError, self._handle_error)
104
105
    def _handle_error(self):
106
        printer = SpecOutputPrinter()
107
        try:
108
            raise self.FakeError
109
        except self.FakeError:
110
            printer.handle_import_failure(sys.exc_info())
111