File: test_layers_plugin.py

package info (click to toggle)
qgis 2.18.28%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,007,948 kB
  • sloc: cpp: 671,774; python: 158,539; xml: 35,690; ansic: 8,346; sh: 1,766; perl: 1,669; sql: 999; yacc: 836; lex: 461; makefile: 292
file content (122 lines) | stat: -rw-r--r-- 4,521 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from nose2.tests._common import FunctionalTestCase


class TestLayers(FunctionalTestCase):

    def test_runs_layer_fixtures(self):
        proc = self.runIn(
            'scenario/layers',
            '-v',
            '--plugin=nose2.plugins.layers')
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
        self.assertEqual(proc.poll(), 0)

    def test_scenario_fails_without_plugin(self):
        proc = self.runIn(
            'scenario/layers',
            '-v')
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
        self.assertTestRunOutputMatches(proc, stderr=r'FAILED \(failures=7\)')
        self.assertEqual(proc.poll(), 1)

    def test_methods_run_once_per_class(self):
        proc = self.runIn(
            'scenario/layers_with_inheritance',
            '-v',
            '--plugin=nose2.plugins.layers')

        expected = ('^'
                    'L1 setUp\n'
                    'L2 setUp\n'

                    'L1 testSetUp\n'
                    'L2 testSetUp\n'
                    'Run test1\n'
                    'L2 testTearDown\n'
                    'L1 testTearDown\n'

                    'L1 testSetUp\n'
                    'L2 testSetUp\n'
                    'Run test2\n'
                    'L2 testTearDown\n'
                    'L1 testTearDown\n'

                    'L1 tearDown\n'
                    '$')
        self.assertTestRunOutputMatches(proc, stdout=expected)
        self.assertEqual(proc.poll(), 0)

    def test_layer_reporter_output(self):
        proc = self.runIn(
            'scenario/layers',
            '-v',
            '--plugin=nose2.plugins.layers',
            '--layer-reporter')
        expect = r"""test \(test_layers.NoLayer\) ... ok
Base
  test \(test_layers.Outer\) ... ok
  LayerD
    test \(test_layers.InnerD\) ... ok
  LayerA
    test \(test_layers.InnerA\) ... ok
  LayerB
    LayerB_1
      test \(test_layers.InnerB_1\) ... ok
    LayerC
      test \(test_layers.InnerC\) ... ok
      test2 \(test_layers.InnerC\) ... ok
    LayerA_1
      test \(test_layers.InnerA_1\) ... ok""".split("\n")
        self.assertTestRunOutputMatches(proc, stderr='Ran 8 tests')
        for line in expect:
            self.assertTestRunOutputMatches(proc, stderr=line)
        self.assertEqual(proc.poll(), 0)

    def test_layer_reporter_error_output(self):
        proc = self.runIn(
            'scenario/layers_with_errors',
            '--plugin=nose2.plugins.layers',
            '--layer-reporter')
        expect = [
            r'ERROR: fixture with a value test_err '
            '\(test_layers_with_errors.Test\)',
            'ERROR: A test scenario with errors should check for an attribute '
            'that does not exist and raise an error',
            r'FAIL: fixture with a value test_fail '
            '\(test_layers_with_errors.Test\)',
            'FAIL: A test scenario with errors should check that value == 2 '
            'and fail']
        for line in expect:
            self.assertTestRunOutputMatches(proc, stderr=line)
        self.assertEqual(proc.poll(), 1)

    def test_layers_and_attributes(self):
        proc = self.runIn(
            'scenario/layers_and_attributes',
            '-v',
            '--plugin=nose2.plugins.attrib',
            '--plugin=nose2.plugins.layers',
            '-A',
            'a=1')
        self.assertTestRunOutputMatches(proc, stderr='Ran 1 test')
        self.assertEqual(proc.poll(), 0)

    def test_teardown_fail(self):
        proc = self.runIn('scenario/layers_with_errors',
                          '--plugin=nose2.plugins.layers',
                          '-v',
                          'test_layer_teardown_fail')
        self.assertTestRunOutputMatches(proc, stderr='Ran 1 test in')
        self.assertTestRunOutputMatches(proc, stderr='ERROR: LayerSuite')
        self.assertTestRunOutputMatches(proc, stderr='FAIL')
        self.assertTestRunOutputMatches(proc, stderr='Bad Error in Layer testTearDown')

    def test_setup_fail(self):
        proc = self.runIn('scenario/layers_with_errors',
                          '--plugin=nose2.plugins.layers',
                          '-v',
                          'test_layer_setup_fail')
        self.assertTestRunOutputMatches(proc, stderr='Ran 0 tests in')
        self.assertTestRunOutputMatches(proc, stderr='ERROR: LayerSuite')
        self.assertTestRunOutputMatches(proc, stderr='FAIL')
        self.assertTestRunOutputMatches(proc, stderr='Bad Error in Layer setUp!')