def test_reload_loader_replaced(self): with support.CleanImport('types'): import types types.__loader__ = None self.init.invalidate_caches() reloaded = self.init.reload(types) self.assertIsNot(reloaded.__loader__, None) self.assertIs(reloaded, types) self.assertIs(sys.modules['types'], types)
def test_reload_missing_loader(self): with support.CleanImport('types'): import types loader = types.__loader__ del types.__loader__ reloaded = self.init.reload(types) self.assertIs(reloaded, types) self.assertIs(sys.modules['types'], types) self.assertEqual(reloaded.__loader__.path, loader.path)
def test_reload_missing_loader(self): with support.CleanImport('types'): import types loader = types.__loader__ del types.__loader__ reloaded = self.init.reload(types) self.assertIs(reloaded, types) self.assertIs(sys.modules['types'], types) # Truffle change: we freeze types, so may not have a path self.assertEqual(getattr(reloaded.__loader__, "path", None), getattr(loader, "path", None))
def test_default_encoding_issues(self): # SF bug #1115989: wrong decoding in '_stringify' utf8 = """<?xml version='1.0' encoding='iso-8859-1'?> <params> <param><value> <string>abc \x95</string> </value></param> <param><value> <struct> <member> <name>def \x96</name> <value><string>ghi \x97</string></value> </member> </struct> </value></param> </params> """ # sys.setdefaultencoding() normally doesn't exist after site.py is # loaded. Import a temporary fresh copy to get access to it # but then restore the original copy to avoid messing with # other potentially modified sys module attributes old_encoding = sys.getdefaultencoding() with support.CleanImport('sys'): import sys as temp_sys temp_sys.setdefaultencoding("iso-8859-1") try: (s, d), m = xmlrpc.client.loads(utf8) finally: temp_sys.setdefaultencoding(old_encoding) items = list(d.items()) if have_unicode: self.assertEqual(s, "abc \x95") self.assertIsInstance(s, str) self.assertEqual(items, [("def \x96", "ghi \x97")]) self.assertIsInstance(items[0][0], str) self.assertIsInstance(items[0][1], str) else: self.assertEqual(s, "abc \xc2\x95") self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")])
def test_reload_modules(self): for mod in ('tokenize', 'time', 'marshal'): with self.subTest(module=mod): with support.CleanImport(mod): module = self.init.import_module(mod) self.init.reload(module)
def test_multiple_features(self): with support.CleanImport("test.test_future5"): from test import test_future5
def test_future3(self): with support.CleanImport('test_future3'): from test import test_future3
def test_future2(self): with support.CleanImport('future_test2'): from test import future_test2 self.assertEqual(future_test2.result, 6)
def test_CleanImport(self): import importlib with support.CleanImport("asyncore"): importlib.import_module("asyncore")
def test_builtin(self): with support.CleanImport('marshal'): import marshal imp.reload(marshal)
def test_extension(self): with support.CleanImport('time'): import time imp.reload(time)
def test_goodstrict(self): with support.CleanImport('goodsyntax_strict'): from test import goodsyntax_strict self.assertEqual(goodsyntax_strict.result, True)