| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1143,33 +1143,34 @@ def test_boxed_value_type_mutation_result(): | |||
| 1143 | 1143 | # to accidentally write code like the following which is not really | |
| 1144 | 1144 | # mutating value types in-place but changing boxed copies. | |
| 1145 | 1145 | ||
| 1146 | - from System.Drawing import Point | ||
| 1146 | + # Uses ValueType DictionaryEntry instead of Point | ||
| 1147 | + from System.Collections import DictionaryEntry | ||
| 1147 | 1148 | from System import Array | |
| 1148 | 1149 | ||
| 1149 | - items = Array.CreateInstance(Point, 5) | ||
| 1150 | + items = Array.CreateInstance(DictionaryEntry, 5) | ||
| 1150 | 1151 | ||
| 1151 | 1152 | for i in range(5): | |
| 1152 | - items[i] = Point(i, i) | ||
| 1153 | + items[i] = DictionaryEntry(i, i) | ||
| 1153 | 1154 | ||
| 1154 | 1155 | for i in range(5): | |
| 1155 | 1156 | # Boxed items, so set_attr will not change the array member. | |
| 1156 | - assert items[i].X == i | ||
| 1157 | - assert items[i].Y == i | ||
| 1158 | - items[i].X = i + 1 | ||
| 1159 | - items[i].Y = i + 1 | ||
| 1160 | - assert items[i].X == i | ||
| 1161 | - assert items[i].Y == i | ||
| 1157 | + assert items[i].Key == i | ||
| 1158 | + assert items[i].Value == i | ||
| 1159 | + items[i].Key = i + 1 | ||
| 1160 | + items[i].Value = i + 1 | ||
| 1161 | + assert items[i].Key == i | ||
| 1162 | + assert items[i].Value == i | ||
| 1162 | 1163 | ||
| 1163 | 1164 | for i in range(5): | |
| 1164 | 1165 | # Demonstrates the workaround that will change the members. | |
| 1165 | - assert items[i].X == i | ||
| 1166 | - assert items[i].Y == i | ||
| 1166 | + assert items[i].Key == i | ||
| 1167 | + assert items[i].Value == i | ||
| 1167 | 1168 | item = items[i] | |
| 1168 | - item.X = i + 1 | ||
| 1169 | - item.Y = i + 1 | ||
| 1169 | + item.Key = i + 1 | ||
| 1170 | + item.Value = i + 1 | ||
| 1170 | 1171 | items[i] = item | |
| 1171 | - assert items[i].X == i + 1 | ||
| 1172 | - assert items[i].Y == i + 1 | ||
| 1172 | + assert items[i].Key == i + 1 | ||
| 1173 | + assert items[i].Value == i + 1 | ||
| 1173 | 1174 | ||
| 1174 | 1175 | ||
| 1175 | 1176 | def test_special_array_creation(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,26 +61,28 @@ def test_non_public_class(): | |||
| 61 | 61 | ||
| 62 | 62 | def test_basic_subclass(): | |
| 63 | 63 | """Test basic subclass of a managed class.""" | |
| 64 | - from System.Collections import Hashtable | ||
| 64 | + # Uses ArrayList instead of Hashtable | ||
| 65 | + # As it's available from .Net Core 2.0 without an addref | ||
| 66 | + from System.Collections import ArrayList | ||
| 65 | 67 | ||
| 66 | - class MyTable(Hashtable): | ||
| 68 | + class MyArrayList(ArrayList): | ||
| 67 | 69 | def how_many(self): | |
| 68 | 70 | return self.Count | |
| 69 | 71 | ||
| 70 | - table = MyTable() | ||
| 72 | + array_list = MyArrayList() | ||
| 71 | 73 | ||
| 72 | - assert table.__class__.__name__.endswith('MyTable') | ||
| 73 | - assert type(table).__name__.endswith('MyTable') | ||
| 74 | - assert len(table.__class__.__bases__) == 1 | ||
| 75 | - assert table.__class__.__bases__[0] == Hashtable | ||
| 74 | + assert array_list.__class__.__name__.endswith('MyArrayList') | ||
| 75 | + assert type(array_list).__name__.endswith('MyArrayList') | ||
| 76 | + assert len(array_list.__class__.__bases__) == 1 | ||
| 77 | + assert array_list.__class__.__bases__[0] == ArrayList | ||
| 76 | 78 | ||
| 77 | - assert table.how_many() == 0 | ||
| 78 | - assert table.Count == 0 | ||
| 79 | + assert array_list.how_many() == 0 | ||
| 80 | + assert array_list.Count == 0 | ||
| 79 | 81 | ||
| 80 | - table.set_Item('one', 'one') | ||
| 82 | + array_list.Add('one') | ||
| 81 | 83 | ||
| 82 | - assert table.how_many() == 1 | ||
| 83 | - assert table.Count == 1 | ||
| 84 | + assert array_list.how_many() == 1 | ||
| 85 | + assert array_list.Count == 1 | ||
| 84 | 86 | ||
| 85 | 87 | ||
| 86 | 88 | def test_subclass_with_no_arg_constructor(): | |
@@ -118,21 +120,23 @@ def __init__(self, v): | |||
| 118 | 120 | ||
| 119 | 121 | def test_struct_construction(): | |
| 120 | 122 | """Test construction of structs.""" | |
| 121 | - from System.Drawing import Point | ||
| 123 | + # Uses DateTime instead of Point | ||
| 124 | + # As it's available from .Net Core 2.0 without an addref | ||
| 125 | + from System import DateTime | ||
| 122 | 126 | ||
| 123 | - p = Point() | ||
| 124 | - assert p.X == 0 | ||
| 125 | - assert p.Y == 0 | ||
| 127 | + dt1 = DateTime(2017, 2, 27) | ||
| 128 | + assert dt1.Day == 27 | ||
| 129 | + assert dt1.Month == 2 | ||
| 130 | + assert dt1.Year == 2017 | ||
| 126 | 131 | ||
| 127 | - p = Point(0, 0) | ||
| 128 | - assert p.X == 0 | ||
| 129 | - assert p.Y == 0 | ||
| 132 | + # Static method calls default constructor | ||
| 133 | + dt2 = DateTime.MinValue | ||
| 134 | + assert dt2.Day == 1 | ||
| 135 | + assert dt2.Month == 1 | ||
| 136 | + assert dt2.Year == 1 | ||
| 130 | 137 | ||
| 131 | - p.X = 10 | ||
| 132 | - p.Y = 10 | ||
| 133 | - | ||
| 134 | - assert p.X == 10 | ||
| 135 | - assert p.Y == 10 | ||
| 138 | + # mutation tests removed | ||
| 139 | + # structs are not typically mutable | ||
| 136 | 140 | ||
| 137 | 141 | # test strange __new__ interactions | |
| 138 | 142 | ||
@@ -169,44 +173,53 @@ def test_ienumerator_iteration(): | |||
| 169 | 173 | ||
| 170 | 174 | def test_override_get_item(): | |
| 171 | 175 | """Test managed subclass overriding __getitem__.""" | |
| 172 | - from System.Collections import Hashtable | ||
| 173 | - | ||
| 174 | - class MyTable(Hashtable): | ||
| 176 | + from System.Collections import ArrayList | ||
| 177 | + | ||
| 178 | + # Uses ArrayList instead of Hashtable | ||
| 179 | + # As it's available from .Net Core 2.0 without an addref | ||
| 180 | + class MyArrayList(ArrayList): | ||
| 175 | 181 | def __getitem__(self, key): | |
| 176 | - value = Hashtable.__getitem__(self, key) | ||
| 182 | + value = ArrayList.__getitem__(self, key) | ||
| 177 | 183 | return 'my ' + str(value) | |
| 178 | 184 | ||
| 179 | - table = MyTable() | ||
| 180 | - table['one'] = 'one' | ||
| 181 | - table['two'] = 'two' | ||
| 182 | - table['three'] = 'three' | ||
| 185 | + array_list = MyArrayList() | ||
| 186 | + array_list.Add('zero') | ||
| 187 | + array_list.Add('one') | ||
| 188 | + array_list.Add('two') | ||
| 183 | 189 | ||
| 184 | - assert table['one'] == 'my one' | ||
| 185 | - assert table['two'] == 'my two' | ||
| 186 | - assert table['three'] == 'my three' | ||
| 190 | + assert array_list[0] == 'my zero' | ||
| 191 | + assert array_list[1] == 'my one' | ||
| 192 | + assert array_list[2] == 'my two' | ||
| 187 | 193 | ||
| 188 | - assert table.Count == 3 | ||
| 194 | + assert array_list.Count == 3 | ||
| 189 | 195 | ||
| 190 | 196 | ||
| 191 | 197 | def test_override_set_item(): | |
| 192 | 198 | """Test managed subclass overriding __setitem__.""" | |
| 193 | - from System.Collections import Hashtable | ||
| 194 | - | ||
| 195 | - class MyTable(Hashtable): | ||
| 199 | + from System.Collections import ArrayList | ||
| 200 | + | ||
| 201 | + # Uses ArrayList instead of Hashtable | ||
| 202 | + # As it's available from .Net Core 2.0 without an addref | ||
| 203 | + class MyArrayList(ArrayList): | ||
| 196 | 204 | def __setitem__(self, key, value): | |
| 197 | - value = 'my ' + str(value) | ||
| 198 | - Hashtable.__setitem__(self, key, value) | ||
| 199 | - | ||
| 200 | - table = MyTable() | ||
| 201 | - table['one'] = 'one' | ||
| 202 | - table['two'] = 'two' | ||
| 203 | - table['three'] = 'three' | ||
| 204 | - | ||
| 205 | - assert table['one'] == 'my one' | ||
| 206 | - assert table['two'] == 'my two' | ||
| 207 | - assert table['three'] == 'my three' | ||
| 208 | - | ||
| 209 | - assert table.Count == 3 | ||
| 205 | + value = 'your ' + str(value) | ||
| 206 | + ArrayList.__setitem__(self, key, value) | ||
| 207 | + | ||
| 208 | + array_list = MyArrayList() | ||
| 209 | + # need to add three items first | ||
| 210 | + array_list.Add("a") | ||
| 211 | + array_list.Add("b") | ||
| 212 | + array_list.Add("c") | ||
| 213 | + | ||
| 214 | + array_list[0] = 'zero' | ||
| 215 | + array_list[1] = 'one' | ||
| 216 | + array_list[2] = 'two' | ||
| 217 | + | ||
| 218 | + assert array_list[0] == 'your zero' | ||
| 219 | + assert array_list[1] == 'your one' | ||
| 220 | + assert array_list[2] == 'your two' | ||
| 221 | + | ||
| 222 | + assert array_list.Count == 3 | ||
| 210 | 223 | ||
| 211 | 224 | ||
| 212 | 225 | def test_add_and_remove_class_attribute(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,13 +112,15 @@ def test_simple_import_from_with_alias(): | |||
| 112 | 112 | ||
| 113 | 113 | def test_dotted_name_import_from(): | |
| 114 | 114 | """Test dotted-name 'import from'.""" | |
| 115 | - from CLR.System import Xml | ||
| 116 | - assert is_clr_module(Xml) | ||
| 117 | - assert Xml.__name__ == 'System.Xml' | ||
| 115 | + # Uses IO instead of Xml | ||
| 116 | + # As it's available from .Net Core 2.0 without an addref | ||
| 117 | + from CLR.System import IO | ||
| 118 | + assert is_clr_module(IO) | ||
| 119 | + assert IO.__name__ == 'System.IO' | ||
| 118 | 120 | ||
| 119 | - from CLR.System.Xml import XmlDocument | ||
| 120 | - assert is_clr_class(XmlDocument) | ||
| 121 | - assert XmlDocument.__name__ == 'XmlDocument' | ||
| 121 | + from CLR.System.IO import Path | ||
| 122 | + assert is_clr_class(Path) | ||
| 123 | + assert Path.__name__ == 'Path' | ||
| 122 | 124 | ||
| 123 | 125 | from xml.dom import pulldom | |
| 124 | 126 | assert isinstance(pulldom, types.ModuleType) | |
@@ -131,13 +133,15 @@ def test_dotted_name_import_from(): | |||
| 131 | 133 | ||
| 132 | 134 | def test_dotted_name_import_from_with_alias(): | |
| 133 | 135 | """Test dotted-name 'import from' with aliasing.""" | |
| 134 | - from CLR.System import Xml as myXml | ||
| 135 | - assert is_clr_module(myXml) | ||
| 136 | - assert myXml.__name__ == 'System.Xml' | ||
| 136 | + # Uses IO instead of Xml | ||
| 137 | + # As it's available from .Net Core 2.0 without an addref | ||
| 138 | + from CLR.System import IO as myIO | ||
| 139 | + assert is_clr_module(myIO) | ||
| 140 | + assert myIO.__name__ == 'System.IO' | ||
| 137 | 141 | ||
| 138 | - from CLR.System.Xml import XmlDocument as myXmlDocument | ||
| 139 | - assert is_clr_class(myXmlDocument) | ||
| 140 | - assert myXmlDocument.__name__ == 'XmlDocument' | ||
| 142 | + from CLR.System.IO import Path as myPath | ||
| 143 | + assert is_clr_class(myPath) | ||
| 144 | + assert myPath.__name__ == 'Path' | ||
| 141 | 145 | ||
| 142 | 146 | from xml.dom import pulldom as myPulldom | |
| 143 | 147 | assert isinstance(myPulldom, types.ModuleType) | |
@@ -151,13 +155,15 @@ def test_dotted_name_import_from_with_alias(): | |||
| 151 | 155 | def test_from_module_import_star(): | |
| 152 | 156 | """Test from module import * behavior.""" | |
| 153 | 157 | count = len(locals().keys()) | |
| 154 | - m = __import__('CLR.System.Management', globals(), locals(), ['*']) | ||
| 155 | - assert m.__name__ == 'System.Management' | ||
| 158 | + # Uses IO instead of Xml | ||
| 159 | + # As it's available from .Net Core 2.0 without an addref | ||
| 160 | + m = __import__('CLR.System.IO', globals(), locals(), ['*']) | ||
| 161 | + assert m.__name__ == 'System.IO' | ||
| 156 | 162 | assert is_clr_module(m) | |
| 157 | 163 | assert len(locals().keys()) > count + 1 | |
| 158 | 164 | ||
| 159 | - m2 = __import__('System.Management', globals(), locals(), ['*']) | ||
| 160 | - assert m2.__name__ == 'System.Management' | ||
| 165 | + m2 = __import__('System.IO', globals(), locals(), ['*']) | ||
| 166 | + assert m2.__name__ == 'System.IO' | ||
| 161 | 167 | assert is_clr_module(m2) | |
| 162 | 168 | assert len(locals().keys()) > count + 1 | |
| 163 | 169 | ||
@@ -168,16 +174,22 @@ def test_explicit_assembly_load(): | |||
| 168 | 174 | """Test explicit assembly loading using standard CLR tools.""" | |
| 169 | 175 | from CLR.System.Reflection import Assembly | |
| 170 | 176 | from CLR import System | |
| 177 | + from CLR.System.IO import FileNotFoundException | ||
| 171 | 178 | import sys | |
| 172 | 179 | ||
| 173 | - assembly = Assembly.LoadWithPartialName('System.Data') | ||
| 180 | + assembly = Assembly.LoadWithPartialName('System.IO') | ||
| 174 | 181 | assert assembly is not None | |
| 182 | + # Uses IO instead of Data | ||
| 183 | + # As it's available from .Net Core 2.0 without an addref | ||
| 184 | + import CLR.System.IO | ||
| 185 | + assert 'System.IO' in sys.modules | ||
| 175 | 186 | ||
| 176 | - import CLR.System.Data | ||
| 177 | - assert 'System.Data' in sys.modules | ||
| 178 | - | ||
| 179 | - assembly = Assembly.LoadWithPartialName('SpamSpamSpamSpamEggsAndSpam') | ||
| 180 | - assert assembly is None | ||
| 187 | + # Assembly.LoadWithPartialName is obsolete, and delegates to Assembly.Load | ||
| 188 | + # in .Net Core (which then throws) | ||
| 189 | + # assembly = Assembly.LoadWithPartialName('SpamSpamSpamSpamEggsAndSpam') | ||
| 190 | + # assert assembly is None | ||
| 191 | + with pytest.raises(FileNotFoundException): | ||
| 192 | + assembly = Assembly.LoadFrom('SpamSpamSpamSpamEggsAndSpam') | ||
| 181 | 193 | ||
| 182 | 194 | ||
| 183 | 195 | def test_implicit_load_already_valid_namespace(): | |
@@ -224,8 +236,9 @@ def test_module_get_attr(): | |||
| 224 | 236 | ||
| 225 | 237 | int_type = System.Int32 | |
| 226 | 238 | assert is_clr_class(int_type) | |
| 227 | - | ||
| 228 | - module = System.Xml | ||
| 239 | + # Uses IO instead of Xml | ||
| 240 | + # As it's available from .Net Core 2.0 without an addref | ||
| 241 | + module = System.IO | ||
| 229 | 242 | assert is_clr_module(module) | |
| 230 | 243 | ||
| 231 | 244 | with pytest.raises(AttributeError): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,8 +141,9 @@ def test_interface_property(): | |||
| 141 | 141 | """Test properties of interfaces. Added after a bug report | |
| 142 | 142 | that an IsAbstract check was inappropriate and prevented | |
| 143 | 143 | use of properties when only the interface is known.""" | |
| 144 | - from System.Collections import Hashtable, ICollection | ||
| 145 | - | ||
| 146 | - mapping = Hashtable() | ||
| 147 | - coll = ICollection(mapping) | ||
| 148 | - assert coll.Count == 0 | ||
| 144 | + from System.Collections import ArrayList, IList | ||
| 145 | + # Uses ArrayList instead of Hashtable | ||
| 146 | + # As it's available from .Net Core 2.0 without an addref | ||
| 147 | + mapping = ArrayList() | ||
| 148 | + lst = IList(mapping) | ||
| 149 | + assert lst.Count == 0 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments