Repository navigation
Expand file tree
/
Copy pathtest_attrinjector.py
More file actions
79 lines (61 loc) · 2.68 KB
/
Copy pathtest_attrinjector.py
File metadata and controls
79 lines (61 loc) · 2.68 KB
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
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.
import sys
import unittest
from iptest import IronPythonTestCase, is_cli, run_test
@unittest.skipUnless(is_cli, 'IronPython specific test')
class AttrInjectorTestCase(IronPythonTestCase):
def setUp(self):
super(AttrInjectorTestCase, self).setUp()
self.load_iron_python_test()
def test_attributes_injector(self):
from IronPythonTest import AttrInjectorTest
# load XML Dom
x = AttrInjectorTest.LoadXml('<root><foo>foo text</foo><bar><baz>baz text</baz></bar></root>')
# access injected attributes
self.assertEqual(x.GetType().Name, 'XmlElement')
self.assertEqual(x.foo.GetType().Name, 'String')
self.assertEqual(x.foo, 'foo text')
self.assertEqual(x.GetType().Name, 'XmlElement')
self.assertEqual(x.bar.GetType().Name, 'XmlElement')
self.assertEqual(x.bar.baz.GetType().Name, 'String')
self.assertEqual(x.bar.baz, 'baz text')
def operator_test(self, a):
self.assertEqual(a.doesnotexist, 42)
# GetBoundMember shouldn't be called for pre-existing attributes, and we verify the name we got before.
self.assertEqual(a.Name, 'doesnotexist')
# SetMember should be called for sets
a.somethingelse = 123
self.assertEqual(a.Name, 'somethingelse')
self.assertEqual(a.Value, 123)
def test_get_set_extended(self):
from IronPythonTest import ExtendedClass
self.operator_test(ExtendedClass())
def test_get_set_instance(self):
from IronPythonTest import OperatorTest
self.operator_test(OperatorTest())
#
# test_overload_*
# http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=26277
#
def test_overload_0_GetCustomMember(self):
from IronPythonTest import MemberOverloadTest
x = MemberOverloadTest()
self.assertEqual(x.Prop, 0)
def test_overload_1_GetBoundMember(self):
from IronPythonTest import MemberOverloadTest
x = MemberOverloadTest()
self.assertRaises(AttributeError, getattr, x, "Prop_Nonexistent")
def test_overload_2_SetMember(self):
from IronPythonTest import MemberOverloadTest
x = MemberOverloadTest()
x.Prop = 5
self.assertEqual(x.Prop, 5)
def test_overload_3_DeleteMember(self):
from IronPythonTest import MemberOverloadTest
x = MemberOverloadTest()
def f():
del x.Prop
self.assertRaises(AttributeError, f)
run_test(__name__)