~ubuntu-branches/ubuntu/wily/nose2/wily

« back to all changes in this revision

Viewing changes to nose2/tests/functional/test_layers_plugin.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2013-09-09 22:14:45 UTC
  • Revision ID: package-import@ubuntu.com-20130909221445-zdvvvebxfucvavw5
Tags: upstream-0.4.7
ImportĀ upstreamĀ versionĀ 0.4.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from nose2.tests._common import FunctionalTestCase
 
2
 
 
3
 
 
4
class TestLayers(FunctionalTestCase):
 
5
 
 
6
    def test_runs_layer_fixtures(self):
 
7
        proc = self.runIn(
 
8
            'scenario/layers',
 
9
            '-v',
 
10
            '--plugin=nose2.plugins.layers')
 
11
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
 
12
        self.assertEqual(proc.poll(), 0)
 
13
 
 
14
    def test_scenario_fails_without_plugin(self):
 
15
        proc = self.runIn(
 
16
            'scenario/layers',
 
17
            '-v')
 
18
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
 
19
        self.assertTestRunOutputMatches(proc, stderr=r'FAILED \(failures=7\)')
 
20
        self.assertEqual(proc.poll(), 1)
 
21
 
 
22
    def test_methods_run_once_per_class(self):
 
23
        proc = self.runIn(
 
24
            'scenario/layers_with_inheritance',
 
25
            '-v',
 
26
            '--plugin=nose2.plugins.layers')
 
27
 
 
28
        expected = ('^'
 
29
                    'L1 setUp\n'
 
30
                    'L2 setUp\n'
 
31
 
 
32
                    'L1 testSetUp\n'
 
33
                    'L2 testSetUp\n'
 
34
                    'Run test1\n'
 
35
                    'L2 testTearDown\n'
 
36
                    'L1 testTearDown\n'
 
37
 
 
38
                    'L1 testSetUp\n'
 
39
                    'L2 testSetUp\n'
 
40
                    'Run test2\n'
 
41
                    'L2 testTearDown\n'
 
42
                    'L1 testTearDown\n'
 
43
 
 
44
                    'L1 tearDown\n'
 
45
                    '$')
 
46
        self.assertTestRunOutputMatches(proc, stdout=expected)
 
47
        self.assertEqual(proc.poll(), 0)
 
48
 
 
49
    def test_layer_reporter_output(self):
 
50
        proc = self.runIn(
 
51
            'scenario/layers',
 
52
            '-v',
 
53
            '--plugin=nose2.plugins.layers',
 
54
            '--layer-reporter')
 
55
        expect = r"""test \(test_layers.NoLayer\) ... ok
 
56
Base
 
57
  test \(test_layers.Outer\) ... ok
 
58
  LayerD
 
59
    test \(test_layers.InnerD\) ... ok
 
60
  LayerA
 
61
    test \(test_layers.InnerA\) ... ok
 
62
  LayerB
 
63
    LayerB_1
 
64
      test \(test_layers.InnerB_1\) ... ok
 
65
    LayerC
 
66
      test \(test_layers.InnerC\) ... ok
 
67
      test2 \(test_layers.InnerC\) ... ok
 
68
    LayerA_1
 
69
      test \(test_layers.InnerA_1\) ... ok""".split("\n")
 
70
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
 
71
        for line in expect:
 
72
            self.assertTestRunOutputMatches(proc, stderr=line)
 
73
        self.assertEqual(proc.poll(), 0)
 
74
 
 
75
    def test_layer_reporter_error_output(self):
 
76
        proc = self.runIn(
 
77
            'scenario/layers_with_errors',
 
78
            '--plugin=nose2.plugins.layers',
 
79
            '--layer-reporter')
 
80
        expect = [
 
81
            r'ERROR: fixture with a value test_err '
 
82
            '\(test_layers_with_errors.Test\)',
 
83
            'ERROR: A test scenario with errors should check for an attribute '
 
84
            'that does not exist and raise an error',
 
85
            r'FAIL: fixture with a value test_fail '
 
86
            '\(test_layers_with_errors.Test\)',
 
87
            'FAIL: A test scenario with errors should check that value == 2 '
 
88
            'and fail']
 
89
        for line in expect:
 
90
            self.assertTestRunOutputMatches(proc, stderr=line)
 
91
        self.assertEqual(proc.poll(), 1)
 
92
 
 
93
    def test_layers_and_attributes(self):
 
94
        proc = self.runIn(
 
95
            'scenario/layers_and_attributes',
 
96
            '-v',
 
97
            '--plugin=nose2.plugins.attrib',
 
98
            '--plugin=nose2.plugins.layers',
 
99
            '-A',
 
100
            'a=1')
 
101
        self.assertTestRunOutputMatches(proc, stderr='Ran 1 test')
 
102
        self.assertEqual(proc.poll(), 0)