~allenap/maas/neighbours-service-live

« back to all changes in this revision

Viewing changes to src/maastesting/tests/test_runtest.py

  • Committer: Gavin Panella
  • Date: 2015-10-14 19:48:39 UTC
  • mfrom: (3852.1.524 maas)
  • Revision ID: gavin.panella@canonical.com-20151014194839-xgjmom6qzxyj71pn
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for `maastesting.runtest`."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = []
 
16
 
 
17
from maastesting.matchers import DocTestMatches
 
18
from maastesting.runtest import (
 
19
    MAASRunTest,
 
20
    MAASTwistedRunTest,
 
21
)
 
22
from maastesting.testcase import MAASTestCase
 
23
from testtools import TestCase
 
24
from testtools.matchers import (
 
25
    HasLength,
 
26
    Is,
 
27
    MatchesListwise,
 
28
)
 
29
 
 
30
 
 
31
class TestExecutors(MAASTestCase):
 
32
    """Tests for `MAASRunTest` and `MAASTwistedRunTest`."""
 
33
 
 
34
    scenarios = (
 
35
        ("MAASRunTest", {"executor": MAASRunTest}),
 
36
        ("MAASTwistedRunTest", {"executor": MAASTwistedRunTest}),
 
37
    )
 
38
 
 
39
    def test_catches_generator_tests(self):
 
40
 
 
41
        class BrokenTests(TestCase):
 
42
 
 
43
            run_tests_with = self.executor
 
44
 
 
45
            def test(self):
 
46
                yield None
 
47
 
 
48
        test = BrokenTests("test")
 
49
        result = test.run()
 
50
 
 
51
        self.assertThat(result.errors, HasLength(1))
 
52
        self.assertThat(result.errors[0], MatchesListwise((
 
53
            Is(test),
 
54
            DocTestMatches(
 
55
                """...
 
56
                InvalidTest:
 
57
                    Test returned a generator. Should it be
 
58
                    decorated with inlineCallbacks?
 
59
                """
 
60
            ),
 
61
        )))