11
11
12
12
glob = 42
13
13
some_var = 12
14
+ some_non_assigned_global_var = 11
15
+ some_assigned_global_var = 11
14
16
15
17
class Mine:
16
18
instance_var = 24
@@ -19,6 +21,8 @@ def a_method(p1, p2):
19
21
20
22
def spam(a, b, *var, **kw):
21
23
global bar
24
+ global some_assigned_global_var
25
+ some_assigned_global_var = 12
22
26
bar = 47
23
27
some_var = 10
24
28
x = 23
@@ -90,7 +94,7 @@ def test_children(self):
90
94
91
95
def test_lineno (self ):
92
96
self .assertEqual (self .top .get_lineno (), 0 )
93
- self .assertEqual (self .spam .get_lineno (), 12 )
97
+ self .assertEqual (self .spam .get_lineno (), 14 )
94
98
95
99
# TODO: RUSTPYTHON
96
100
@unittest .expectedFailure
@@ -99,7 +103,7 @@ def test_function_info(self):
99
103
self .assertEqual (sorted (func .get_parameters ()), ["a" , "b" , "kw" , "var" ])
100
104
expected = ['a' , 'b' , 'internal' , 'kw' , 'other_internal' , 'some_var' , 'var' , 'x' ]
101
105
self .assertEqual (sorted (func .get_locals ()), expected )
102
- self .assertEqual (sorted (func .get_globals ()), ["bar" , "glob" ])
106
+ self .assertEqual (sorted (func .get_globals ()), ["bar" , "glob" , "some_assigned_global_var" ])
103
107
self .assertEqual (self .internal .get_frees (), ("x" ,))
104
108
105
109
# TODO: RUSTPYTHON
@@ -112,6 +116,9 @@ def test_globals(self):
112
116
self .assertFalse (self .internal .lookup ("x" ).is_global ())
113
117
self .assertFalse (self .Mine .lookup ("instance_var" ).is_global ())
114
118
self .assertTrue (self .spam .lookup ("bar" ).is_global ())
119
+ # Module-scope globals are both global and local
120
+ self .assertTrue (self .top .lookup ("some_non_assigned_global_var" ).is_global ())
121
+ self .assertTrue (self .top .lookup ("some_assigned_global_var" ).is_global ())
115
122
116
123
# TODO: RUSTPYTHON
117
124
@unittest .expectedFailure
@@ -126,6 +133,9 @@ def test_nonlocal(self):
126
133
def test_local (self ):
127
134
self .assertTrue (self .spam .lookup ("x" ).is_local ())
128
135
self .assertFalse (self .spam .lookup ("bar" ).is_local ())
136
+ # Module-scope globals are both global and local
137
+ self .assertTrue (self .top .lookup ("some_non_assigned_global_var" ).is_local ())
138
+ self .assertTrue (self .top .lookup ("some_assigned_global_var" ).is_local ())
129
139
130
140
def test_free (self ):
131
141
self .assertTrue (self .internal .lookup ("x" ).is_free ())
@@ -146,6 +156,8 @@ def test_symbol_lookup(self):
146
156
147
157
self .assertRaises (KeyError , self .top .lookup , "not_here" )
148
158
159
+ # TODO: RUSTPYTHON
160
+ @unittest .expectedFailure
149
161
def test_namespaces (self ):
150
162
self .assertTrue (self .top .lookup ("Mine" ).is_namespace ())
151
163
self .assertTrue (self .Mine .lookup ("a_method" ).is_namespace ())
@@ -154,8 +166,7 @@ def test_namespaces(self):
154
166
self .assertTrue (self .top .lookup ("namespace_test" ).is_namespace ())
155
167
self .assertFalse (self .spam .lookup ("x" ).is_namespace ())
156
168
157
- # TODO(RUSTPYTHON): lookup should return same pythonref
158
- # self.assertTrue(self.top.lookup("spam").get_namespace() is self.spam)
169
+ self .assertTrue (self .top .lookup ("spam" ).get_namespace () is self .spam )
159
170
ns_test = self .top .lookup ("namespace_test" )
160
171
self .assertEqual (len (ns_test .get_namespaces ()), 2 )
161
172
self .assertRaises (ValueError , ns_test .get_namespace )
@@ -220,7 +231,6 @@ def checkfilename(brokencode, offset):
220
231
self .assertEqual (e .offset , offset )
221
232
else :
222
233
self .fail ("no SyntaxError for %r" % (brokencode ,))
223
- # TODO: RUSTPYTHON, now offset get 15
224
234
checkfilename ("def f(x): foo)(" , 14 ) # parse-time
225
235
checkfilename ("def f(x): global x" , 11 ) # symtable-build-time
226
236
symtable .symtable ("pass" , b"spam" , "exec" )
@@ -252,6 +262,12 @@ def test_bytes(self):
252
262
top = symtable .symtable (code , "?" , "exec" )
253
263
self .assertIsNotNone (find_block (top , "\u017d " ))
254
264
265
+ # TODO: RUSTPYTHON
266
+ @unittest .expectedFailure
267
+ def test_symtable_repr (self ):
268
+ self .assertEqual (str (self .top ), "<SymbolTable for module ?>" )
269
+ self .assertEqual (str (self .spam ), "<Function SymbolTable for spam in ?>" )
270
+
255
271
256
272
if __name__ == '__main__' :
257
- unittest .main ()
273
+ unittest .main ()
0 commit comments