File: test_nesting_tokeniser.py

package info (click to toggle)
python-noseofyeti 2.4.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: python: 2,581; sh: 31; makefile: 12
file content (125 lines) | stat: -rw-r--r-- 3,309 bytes parent folder | download
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
123
124
125
import pytest


class Examples:
    small_example = [
        """
    describe "This":
        describe "That":

            describe "Meh":pass
        describe "Blah":pass
    describe "Another":pass """,
        """
    class TestThis :pass
    class TestThis_That (TestThis ):pass
    class TestThis_That_Meh (TestThis_That ):pass
    class TestThis_Blah (TestThis ):pass
    class TestAnother :pass
    """,
    ]

    ###   SMALL EXAMPLE (WITH PATH FOR BW COMPAT)

    small_example_with_pass = [
        """
    describe "This":pass
        describe "That":pass
            describe "Meh":pass
        describe "Blah":pass
    describe "Another":pass """,
        """
    class TestThis :pass
    class TestThis_That (TestThis ):pass
    class TestThis_That_Meh (TestThis_That ):pass
    class TestThis_Blah (TestThis ):pass
    class TestAnother :pass
    """,
    ]

    big_example = [
        """
    describe "This":
        it 'should':
            if x:
                pass
            else:
                x += 9
        describe "That":
            describe "Meh":
                it 'should':
                    if y:
                        pass
                    else:
                        pass
        describe "Blah":pass
    describe "Another":
        it 'should':
            if z:
                if u:
                    print "hello \
                        there"
                else:
                    print "no"
            else:
                pass
    """,
        """
    class TestThis :
        def test_should (self )$RET:
            if x :
                pass
            else :
                x +=9
    class TestThis_That (TestThis ):pass
    class TestThis_That_Meh (TestThis_That ):
        def test_should (self )$RET:
            if y :
                pass
            else :
                pass
    class TestThis_Blah (TestThis ):pass
    class TestAnother :
        def test_should (self )$RET:
            if z :
                if u :
                    print "hello \
                        there"
                else :
                    print "no"
            else :
                pass
    """,
    ]


def assert_example(example, convert_to_tabs=False):
    __tracebackhide__ = True
    pytest.helpers.assert_example(
        example, convert_to_tabs=convert_to_tabs, with_describe_attrs=False
    )


class Test_Tokeniser_Nesting:
    def test_works_with_space(self):
        assert_example(Examples.small_example)

    def test_works_with_tabs(self):
        assert_example(Examples.small_example, convert_to_tabs=True)

    def test_works_with_space_and_inline_pass(self):
        assert_example(Examples.small_example_with_pass)

    def test_works_with_tabs_and_inline_pass(self):
        assert_example(Examples.small_example_with_pass, convert_to_tabs=True)

    def test_keeps_good_indentation_in_body_with_spaces(self):
        assert_example(Examples.big_example)

    def test_keeps_good_indentation_in_body_with_tabs(self):
        assert_example(Examples.big_example, convert_to_tabs=True)

    def test_names_nested_describes_with_part_of_parents_name(self):
        original = 'describe "a":\n\tdescribe "b":'
        desired = "class TestA :pass\nclass TestA_B (TestA ):"
        assert_example([original, desired])