Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d46fa1e

Browse files
committed
Adjust the import tests to use only commonly available deps
1 parent 8bc458b commit d46fa1e

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

tests/conftest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ def pytest_configure(config):
6666

6767
import clr
6868
clr.AddReference("Python.Test")
69-
clr.AddReference("System")
70-
clr.AddReference("System.Collections")
71-
clr.AddReference("System.Data")
72-
clr.AddReference("System.Xml")
7369

7470

7571
def pytest_unconfigure(config):

tests/test_module.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_import_clr():
3030

3131
def test_version_clr():
3232
import clr
33-
assert clr.__version__ >= "2.2.0"
33+
assert clr.__version__ >= "3.0.0"
3434

3535

3636
def test_preload_var():
@@ -111,12 +111,13 @@ def test_dotted_name_import():
111111

112112
def test_multiple_dotted_name_import():
113113
"""Test an import bug with multiple dotted imports."""
114-
import System.Data
115-
assert is_clr_module(System.Data)
116-
assert System.Data.__name__ == 'System.Data'
117-
import System.Data
118-
assert is_clr_module(System.Data)
119-
assert System.Data.__name__ == 'System.Data'
114+
115+
import System.Reflection
116+
assert is_clr_module(System.Reflection)
117+
assert System.Reflection.__name__ == 'System.Reflection'
118+
import System.Reflection
119+
assert is_clr_module(System.Reflection)
120+
assert System.Reflection.__name__ == 'System.Reflection'
120121

121122

122123
def test_dotted_name_import_with_alias():
@@ -192,11 +193,11 @@ def test_dotted_name_import_from_with_alias():
192193

193194
def test_from_module_import_star():
194195
"""Test from module import * behavior."""
195-
clr.AddReference('System.Xml')
196-
196+
clr.AddReference("System")
197+
197198
count = len(locals().keys())
198-
m = __import__('System.Xml', globals(), locals(), ['*'])
199-
assert m.__name__ == 'System.Xml'
199+
m = __import__('System', globals(), locals(), ['*'])
200+
assert m.__name__ == 'System'
200201
assert is_clr_module(m)
201202
assert len(locals().keys()) > count + 1
202203

@@ -212,7 +213,11 @@ def test_implicit_assembly_load():
212213
import Microsoft.Build
213214

214215
with warnings.catch_warnings(record=True) as w:
215-
clr.AddReference("System.Windows.Forms")
216+
try:
217+
clr.AddReference("System.Windows.Forms")
218+
except Exception:
219+
pytest.skip()
220+
216221
import System.Windows.Forms as Forms
217222
assert is_clr_module(Forms)
218223
assert Forms.__name__ == 'System.Windows.Forms'
@@ -227,11 +232,11 @@ def test_explicit_assembly_load():
227232
from System.Reflection import Assembly
228233
import System, sys
229234

230-
assembly = Assembly.LoadWithPartialName('System.Data')
235+
assembly = Assembly.LoadWithPartialName('System.Runtime')
231236
assert assembly is not None
232237

233-
import System.Data
234-
assert 'System.Data' in sys.modules
238+
import System.Runtime
239+
assert 'System.Runtime' in sys.modules
235240

236241
assembly = Assembly.LoadWithPartialName('SpamSpamSpamSpamEggsAndSpam')
237242
assert assembly is None
@@ -275,12 +280,14 @@ def test_module_lookup_recursion():
275280

276281
def test_module_get_attr():
277282
"""Test module getattr behavior."""
283+
278284
import System
285+
import System.Runtime
279286

280287
int_type = System.Int32
281288
assert is_clr_class(int_type)
282289

283-
module = System.Xml
290+
module = System.Runtime
284291
assert is_clr_module(module)
285292

286293
with pytest.raises(AttributeError):
@@ -324,7 +331,6 @@ def test_clr_list_assemblies():
324331
from clr import ListAssemblies
325332
verbose = list(ListAssemblies(True))
326333
short = list(ListAssemblies(False))
327-
assert u'mscorlib' in short
328334
assert u'System' in short
329335
assert u'Culture=' in verbose[0]
330336
assert u'Version=' in verbose[0]
@@ -377,8 +383,11 @@ def test_assembly_load_thread_safety():
377383
_ = Dictionary[Guid, DateTime]()
378384
ModuleTest.JoinThreads()
379385

386+
@pytest.mark.skipif()
380387
def test_assembly_load_recursion_bug():
381388
"""Test fix for recursion bug documented in #627"""
382-
from System.Configuration import ConfigurationManager
383-
content = dir(ConfigurationManager)
389+
sys_config = pytest.importorskip(
390+
"System.Configuration", reason="System.Configuration can't be imported"
391+
)
392+
content = dir(sys_config.ConfigurationManager)
384393
assert len(content) > 5, content

0 commit comments

Comments
 (0)