File: test_future.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (195 lines) | stat: -rw-r--r-- 5,608 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import py
from pypy.interpreter.pyparser import future, pytokenizer
from pypy.tool import stdlib___future__ as fut

def run(s, expected_last_future=(0, 0)):
    source_lines = s.splitlines(True)
    tokens = pytokenizer.generate_tokens(source_lines, 0)
    #
    flags, last_future_import = future.add_future_flags(
        future.futureFlags_3_5, tokens)
    assert last_future_import == expected_last_future
    return flags

def test_docstring():
    s = '"Docstring\\" "\nfrom  __future__ import division\n'
    f = run(s, (2, 24))
    assert f == 0

def test_comment():
    s = '# A comment about nothing ;\n'
    f = run(s)
    assert f == 0

def test_tripledocstring():
    s = '''""" This is a
docstring with line
breaks in it. It even has a \n"""
'''
    f = run(s)
    assert f == 0

def test_escapedquote_in_tripledocstring():
    s = '''""" This is a
docstring with line
breaks in it. \\"""It even has an escaped quote!"""
'''
    f = run(s)
    assert f == 0

def test_empty_line():
    s = ' \t   \f \n   \n'
    f = run(s)
    assert f == 0

def test_from():
    s = 'from  __future__ import division\n'
    f = run(s, (1, 24))
    assert f == 0

def test_froms():
    s = 'from  __future__ import division, generators, with_statement\n'
    f = run(s, (1, 24))
    assert f == 0

def test_from_as():
    s = 'from  __future__ import division as b\n'
    f = run(s, (1, 24))
    assert f == 0

def test_froms_as():
    s = 'from  __future__ import division as b, generators as c\n'
    f = run(s, (1, 24))
    assert f == 0

def test_from_paren():
    s = 'from  __future__ import (division)\n'
    f = run(s, (1, 25))
    assert f == 0

def test_froms_paren():
    s = 'from  __future__ import (division, generators)\n'
    f = run(s, (1, 25))
    assert f == 0

def test_froms_paren_as():
    s = 'from  __future__ import (division as b, generators,)\n'
    f = run(s, (1, 25))
    assert f == 0

def test_paren_with_newline():
    s = 'from __future__ import (division,\nabsolute_import)\n'
    f = run(s, (1, 24))
    assert f == 0

def test_paren_with_newline_2():
    s = 'from __future__ import (\ndivision,\nabsolute_import)\n'
    f = run(s, (2, 0))
    assert f == 0

def test_multiline():
    s = '"abc" #def\n  #ghi\nfrom  __future__ import (division as b, generators,)\nfrom __future__ import with_statement\n'
    f = run(s, (4, 23))
    assert f == 0

def test_windows_style_lineendings():
    s = '"abc" #def\r\n  #ghi\r\nfrom  __future__ import (division as b, generators,)\r\nfrom __future__ import with_statement\r\n'
    f = run(s, (4, 23))
    assert f == 0

def test_mac_style_lineendings():
    s = '"abc" #def\r  #ghi\rfrom  __future__ import (division as b, generators,)\rfrom __future__ import with_statement\r'
    f = run(s, (4, 23))
    assert f == 0

def test_semicolon():
    s = '"abc" #def\n  #ghi\nfrom  __future__ import (division as b, generators,);  from __future__ import with_statement\n'
    f = run(s, (3, 78))
    assert f == 0

def test_semicolon_2():
    s = 'from  __future__ import division; from foo import bar'
    f = run(s, expected_last_future=(1, 24))
    assert f == 0

def test_full_chain():
    s = '"abc" #def\n  #ghi\nfrom  __future__ import (division as b, generators,);  from __future__ import with_statement\n'
    f = run(s, (3, 78))
    assert f == 0

def test_intervening_code():
    s = 'from  __future__ import (division as b, generators,)\nfrom sys import modules\nfrom __future__ import with_statement\n'
    f = run(s, expected_last_future=(1, 25))
    assert f == 0

def test_nonexisting():
    s = 'from  __future__ import non_existing_feature\n'
    f = run(s, (1, 24))
    assert f == 0

def test_nonexisting_2():
    s = 'from  __future__ import non_existing_feature, with_statement\n'
    f = run(s, (1, 24))
    assert f == 0

def test_from_import_abs_import():
    s = 'from  __future__ import absolute_import\n'
    f = run(s, (1, 24))
    assert f == 0

def test_raw_doc():
    s = 'r"Doc"\nfrom __future__ import with_statement\n'
    f = run(s, (2, 23))
    assert f == 0

def test_unicode_doc():
    s = 'u"Doc"\nfrom __future__ import with_statement\n'
    f = run(s, (2, 23))
    assert f == 0

def test_raw_unicode_doc():
    s = 'ru"Doc"\nfrom __future__ import with_statement\n'
    f = run(s, (2, 23))
    assert f == 0

def test_continuation_line():
    s = "\\\nfrom __future__ import with_statement\n"
    f = run(s, (2, 23))
    assert f == 0

def test_continuation_lines():
    s = "\\\n  \t\\\nfrom __future__ import with_statement\n"
    f = run(s, (3, 23))
    assert f == 0

def test_lots_of_continuation_lines():
    s = "\\\n\\\n\\\n\\\n\\\n\\\n\nfrom __future__ import with_statement\n"
    f = run(s, (8, 23))
    assert f == 0

def test_continuation_lines_raise():
    s = "   \\\n  \t\\\nfrom __future__ import with_statement\n"
    f = run(s)
    assert f == 0     # because of the INDENT

def test_continuation_lines_in_docstring_single_quoted():
    s = '"\\\n\\\n\\\n\\\n\\\n\\\n"\nfrom  __future__ import division\n'
    f = run(s, (8, 24))
    assert f == 0

def test_continuation_lines_in_docstring_triple_quoted():
    s = '"""\\\n\\\n\\\n\\\n\\\n\\\n"""\nfrom  __future__ import division\n'
    f = run(s, (8, 24))
    assert f == 0

def test_blank_lines():
    s = ('\n\t\n\nfrom __future__ import with_statement'
         '  \n  \n  \nfrom __future__ import division')
    f = run(s, (7, 23))
    assert f == 0

def test_dummy_semicolons():
    s = ('from __future__ import division;\n'
         'from __future__ import with_statement;')
    f = run(s, (2, 23))
    assert f == 0