Skip to content

Commit 906d46d

Browse files
authored
Enable some tests (#1036)
* Enable some tests * Disable test_system_timers
1 parent 4646e5b commit 906d46d

9 files changed

Lines changed: 64 additions & 61 deletions

File tree

Src/IronPython/Compiler/Ast/PythonNameBinder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,15 @@ public override bool Walk(GlobalStatement node) {
676676
foreach (string n in node.Names) {
677677
PythonVariable conflict;
678678
// Check current scope for conflicting variable
679+
bool assignedGlobal = false;
679680
if (_currentScope.TryGetVariable(n, out conflict)) {
680681
// conflict?
681682
switch (conflict.Kind) {
682683
case VariableKind.Global:
683684
break;
684685

685686
case VariableKind.Local:
687+
assignedGlobal = true;
686688
ReportSyntaxError($"name '{n}' is assigned to before global declaration", node);
687689
break;
688690

@@ -693,7 +695,7 @@ public override bool Walk(GlobalStatement node) {
693695
}
694696

695697
// Check for the name being referenced previously
696-
if (_currentScope.IsReferenced(n)) {
698+
if (_currentScope.IsReferenced(n) && !assignedGlobal) {
697699
ReportSyntaxError($"name '{n}' is used prior to global declaration", node);
698700
}
699701

Src/IronPython/Compiler/Tokenizer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ public override TokenInfo ReadToken() {
233233
break;
234234

235235
case TokenKind.Constant:
236-
category = (token.Value is string) ? TokenCategory.StringLiteral : TokenCategory.NumericLiteral;
236+
category = token.Value switch {
237+
string => TokenCategory.StringLiteral,
238+
bool or null => TokenCategory.Keyword,
239+
_ => TokenCategory.NumericLiteral,
240+
};
237241
break;
238242

239243
case TokenKind.LeftParenthesis:

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ IsolationLevel=PROCESS # for some reason this may fail without the IsolationLeve
131131

132132
[IronPython.test_system_timers]
133133
Ignore=true
134-
Reason=Unstable
134+
Reason=Unstable - https://github.com/IronLanguages/ironpython3/issues/1037
135135

136136
[IronPython.test_tcf]
137137
Ignore=true
@@ -150,21 +150,9 @@ RunCondition=NOT $(IS_MONO) # weakref failures
150150
RunCondition=NOT $(IS_MONO) # Mono codepage 852 encoding incorrecly decodes 0xAA to '?' instead of '¬'
151151
IsolationLevel=PROCESS # reset reporting of warnings
152152

153-
[IronPython.hosting.editor_svcs.test_errorlistener]
154-
Ignore=true
155-
156-
[IronPython.hosting.editor_svcs.test_tokencategorizer]
157-
Ignore=true
158-
159153
[IronPython.interop.net.derivation.test_property_override]
160154
IsolationLevel=PROCESS # causes a failure in IronPython.test_statics
161155

162-
[IronPython.interop.net.field.test_field_misc]
163-
Ignore=true
164-
165-
[IronPython.interop.net.test_accessibility]
166-
Ignore=true
167-
168156
[IronPython.interop.net.test_loadorder]
169157
Ignore=true
170158

Tests/hosting/editor_svcs/test_errorlistener.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def compile_source(self, source):
5959
errorlistener = ErrorListenerTest.MyErrorListener()
6060
try:
6161
source.Compile(errorlistener)
62-
except System.Exception, e:
62+
except System.Exception as e:
6363
pass
6464
return errorlistener.errors
6565

@@ -76,18 +76,18 @@ def test_empty(self):
7676

7777
def test_unexpected_token(self):
7878
expected = [
79-
("unexpected token 'foo'", "foo", 16, self.FatalError)
79+
("invalid syntax", "foo", 16, self.FatalError)
8080
]
8181
actual = self.compile_expression("1.foo")
8282
self.assertEqual(expected, actual)
8383

8484
def test_multiple_errors(self):
8585
expected = [
86-
("unexpected token 'print'", "print", 16, self.FatalError),
87-
("EOL while scanning single-quoted string", '"hello', 16, self.FatalError),
88-
("unexpected token 'print'", "print", 16, self.FatalError),
86+
("invalid syntax", "assert", 16, self.FatalError),
87+
("EOL while scanning string literal", '"hello', 16, self.FatalError),
88+
("invalid syntax", "assert", 16, self.FatalError),
8989
]
90-
actual = self.compile_expression("""print "hello""")
90+
actual = self.compile_expression("""assert "hello""")
9191
self.assertEqual(expected, actual)
9292

9393
def test_not_indented_class(self):
@@ -120,15 +120,15 @@ def test_non_fatal_error(self):
120120

121121
def test_assignment_to_none(self):
122122
expected = [
123-
("cannot assign to None", "None", 80, self.FatalError),
123+
("can't assign to keyword", "None", 80, self.FatalError),
124124
]
125125
actual = self.compile_file("None = 42")
126126
self.assertEqual(expected, actual)
127127

128128
def test_multiple_erroneous_statements(self):
129129
expected = [
130-
("cannot assign to None", "None", 80, self.FatalError),
131-
("cannot assign to None", "None", 80, self.FatalError),
130+
("can't assign to keyword", "None", 80, self.FatalError),
131+
("can't assign to keyword", "None", 80, self.FatalError),
132132
]
133133
code = """\
134134
None = 2
@@ -137,7 +137,7 @@ def test_multiple_erroneous_statements(self):
137137

138138
def test_warning(self):
139139
expected = [
140-
("name 'a' is assigned to before global declaration", "global a", -1, self.Warning),
140+
("name 'a' is assigned to before global declaration", "global a", -1, self.FatalError), # reports as error since 3.6
141141
]
142142
code = """\
143143
def foo():
@@ -164,7 +164,7 @@ def bar():
164164
def test_should_report_both_errors_and_warnings_negative(self):
165165
"Bug #17541, http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=17541"
166166
expected = [
167-
("cannot assign to None", "None", -1, self.Error),
167+
("can't assign to keyword", "None", -1, self.Error),
168168
("Variable a assigned before global declaration", "global a", -1, self.Warning),
169169
]
170170
code = """\
@@ -176,7 +176,7 @@ def foo():
176176

177177
def test_all_together(self):
178178
expected = [
179-
('cannot assign to None', 'None', 80, self.FatalError),
179+
("can't assign to keyword", "None", 80, self.FatalError),
180180
]
181181
code = """\
182182
None = 2

Tests/hosting/editor_svcs/test_tokencategorizer.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import unittest
66

7-
87
from iptest import IronPythonTestCase, run_test, skipUnlessIronPython
98

109
# from System import Enum
@@ -14,13 +13,14 @@
1413

1514
def pt(tokens):
1615
from Microsoft.Scripting import TokenTriggers
16+
TokenTriggersNone = getattr(TokenTriggers, "None")
1717
for token in tokens:
18-
print "t.%s(From(%d,%d,%d), To(%d,%d,%d)%s)," % \
18+
print("t.%s(From(%d,%d,%d), To(%d,%d,%d)%s)," % \
1919
(token.Category.ToString(), token.SourceSpan.Start.Index,
2020
token.SourceSpan.Start.Line, token.SourceSpan.Start.Column,
2121
token.SourceSpan.End.Index, token.SourceSpan.End.Line,
2222
token.SourceSpan.End.Column,
23-
"" if token.Trigger == TokenTriggers.None else token.Trigger)
23+
"" if token.Trigger == TokenTriggersNone else token.Trigger))
2424

2525
def get_tokens(engine, src, charcount = -1):
2626
from Microsoft.Scripting import SourceLocation
@@ -36,10 +36,12 @@ class TokenBuilder(object):
3636
def __getattr__(self, name):
3737
def callable(*args):
3838
from Microsoft.Scripting import SourceSpan, TokenCategory, TokenInfo, TokenTriggers
39+
TokenTriggersNone = getattr(TokenTriggers, "None")
40+
TokenCategoryNone = getattr(TokenCategory, "None")
3941
from System import Enum
40-
triggers = args[2] if len(args)>2 else TokenTriggers.None
42+
triggers = args[2] if len(args)>2 else TokenTriggersNone
4143
return TokenInfo(SourceSpan(args[0], args[1]),
42-
Enum.Parse(TokenCategory.None.GetType(), name), triggers)
44+
Enum.Parse(TokenCategoryNone.GetType(), name), triggers)
4345
return callable
4446

4547
@skipUnlessIronPython()
@@ -56,7 +58,7 @@ def setUp(self):
5658

5759
def test_categorizer_print(self):
5860
expected = [
59-
self.t.Keyword(self.From(0,1,1), self.To(5,1,6)),
61+
self.t.Identifier(self.From(0,1,1), self.To(5,1,6)),
6062
self.t.StringLiteral(self.From(6,1,7), self.To(11,1,12)),
6163
self.t.Comment(self.From(12,1,13), self.To(20,1,21)),
6264
]
@@ -78,7 +80,7 @@ def test_categorizer_for_loop(self):
7880
self.t.Delimiter(self.From(27,1,28), self.To(28,1,29)),
7981
self.t.WhiteSpace(self.From(28,1,29), self.To(33,2,5)),
8082
self.t.Operator(self.From(28,1,29), self.To(33,2,5)),
81-
self.t.Keyword(self.From(33,2,5), self.To(38,2,10)),
83+
self.t.Identifier(self.From(33,2,5), self.To(38,2,10)),
8284
self.t.Identifier(self.From(39,2,11), self.To(43,2,15)),
8385
self.t.Delimiter(self.From(43,2,15), self.To(44,2,16), TokenTriggers.ParameterNext)
8486
]
@@ -166,7 +168,7 @@ def test_categorizer_dict(self):
166168
def test_categorizer_if_else(self):
167169
expected = [
168170
self.t.Keyword(self.From(0,1,1), self.To(2,1,3)),
169-
self.t.Identifier(self.From(3,1,4), self.To(7,1,8)),
171+
self.t.Keyword(self.From(3,1,4), self.To(7,1,8)),
170172
self.t.Delimiter(self.From(7,1,8), self.To(8,1,9)),
171173
self.t.WhiteSpace(self.From(8,1,9), self.To(13,2,5)),
172174
self.t.Operator(self.From(8,1,9), self.To(13,2,5)),

Tests/interop/net/field/test_field_misc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Licensed to the .NET Foundation under one or more agreements.
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
4+
45
'''
56
Operations on enum type and its' members
67
'''
@@ -21,14 +22,18 @@ def test_accessibility(self):
2122
o = Misc()
2223
o.Set()
2324
self.assertEqual(o.PublicField, 100)
24-
self.assertTrue(not hasattr(o, 'ProtectedField'))
25-
self.assertRaisesRegex(AttributeError, "'Misc' object has no attribute 'PrivateField'", lambda: o.PrivateField)
25+
self.assertIn('ProtectedField', dir(o))
26+
with self.assertRaises(TypeError):
27+
hasattr(o, 'ProtectedField')
28+
self.assertRaisesRegexp(AttributeError, "'Misc' object has no attribute 'PrivateField'", lambda: o.PrivateField)
2629
self.assertEqual(o.InterfaceField.PublicStaticField, 500)
2730

2831
o = DerivedMisc()
2932
o.Set()
3033
self.assertEqual(o.PublicField, 400)
31-
self.assertTrue(not hasattr(o, 'ProtectedField'))
34+
self.assertIn('ProtectedField', dir(o))
35+
with self.assertRaises(TypeError):
36+
hasattr(o, 'ProtectedField')
3237

3338
run_test(__name__)
3439

Tests/interop/net/test_accessibility.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Licensed to the .NET Foundation under one or more agreements.
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
4+
45
'''
56
NOTES:
67
- needs to be rewritten
@@ -19,8 +20,8 @@ def setUp(self):
1920
def pass_for_read_protected(self, x):
2021
x.protected_static_field
2122
x.protected_static_method
22-
#x.protected_static_property # bug 370438
23-
#x.protected_static_event # bug 370432
23+
x.protected_static_property # bug 370438
24+
x.protected_static_event # bug 370432
2425
if str(x).startswith("<C1 object") or str(x).startswith("<C2 object"):
2526
print("Skipping (https://github.com/IronLanguages/main/issues/721)...")
2627
else:
@@ -39,8 +40,8 @@ def all_read(self, x):
3940
self.assertRaises(AttributeError, lambda: x.internal_static_nestedclass)
4041
x.protected_static_field
4142
x.protected_static_method
42-
#x.protected_static_property # bug 370438
43-
#x.protected_static_event # bug 370432
43+
x.protected_static_property # bug 370438
44+
x.protected_static_event # bug 370432
4445
self.assertTrue(not hasattr('x', 'protected_static_nestedclass')) # not supported
4546
x.public_static_field
4647
x.public_static_method
@@ -61,7 +62,7 @@ def all_read(self, x):
6162
x.protected_instance_field
6263
x.protected_instance_method
6364
x.protected_instance_property
64-
#x.protected_instance_event # bug 370432
65+
x.protected_instance_event # bug 370432
6566
self.assertTrue(not hasattr('x', 'protected_instance_nestedclass')) # not supported
6667
x.public_instance_field
6768
x.public_instance_method
@@ -166,7 +167,8 @@ def test_reflected_type(self):
166167
self.assertTrue('protected_static_field' in dir(C))
167168

168169
x = C()
169-
self.assertTrue(not hasattr(x, 'protected_instance_field'))
170+
with self.assertRaises(TypeError):
171+
hasattr(x, 'protected_instance_field')
170172
self.assertTrue('protected_instance_field' in dir(C))
171173
self.assertTrue('protected_instance_field' in dir(x))
172174
self.assertRaises(TypeError, lambda : x.protected_instance_field)

Tests/test_system_timers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def timer_helper(self, num_handlers=1, sleep_time=5, event_handlers=[], aTimer=N
4444

4545
try:
4646
#create and run the timer
47-
if aTimer==None:
47+
if aTimer is None:
4848
aTimer = System.Timers.Timer()
4949

5050
for i in range(num_handlers): aTimer.Elapsed += System.Timers.ElapsedEventHandler(onTimedEvent)
@@ -89,8 +89,6 @@ def test_multiple_events_one_timer(self):
8989
'''
9090
Multiple event handlers hooked up to a single Timer object
9191
'''
92-
global COUNT
93-
COUNT=0
9492
self.timer_helper(num_handlers=5)
9593
self.timer_helper(num_handlers=500)
9694

0 commit comments

Comments
 (0)