我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用unicodedata.__file__()。
def test_getfile(self): self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
def test_getmodule_recursion(self): from types import ModuleType name = '__inspect_dummy' m = sys.modules[name] = ModuleType(name) m.__file__ = "<string>" # hopefully not a real filename... m.__loader__ = "dummy" # pretend the filename is understood by a loader exec("def x(): pass", m.__dict__) self.assertEqual(inspect.getsourcefile(m.x.__code__), '<string>') del sys.modules[name] inspect.getmodule(compile('a=10','','single'))
def test_no_dict_no_slots_instance_member(self): # returns descriptor with open(__file__) as handle: self.assertEqual(inspect.getattr_static(handle, 'name'), type(handle).name)
def test_getmodule_recursion(self): from types import ModuleType name = '__inspect_dummy' m = sys.modules[name] = ModuleType(name) m.__file__ = "<string>" # hopefully not a real filename... m.__loader__ = "dummy" # pretend the filename is understood by a loader exec "def x(): pass" in m.__dict__ self.assertEqual(inspect.getsourcefile(m.x.func_code), '<string>') del sys.modules[name] inspect.getmodule(compile('a=10','','single'))
def test_details(self): module = importlib.import_module('unittest') rc, out, err = assert_python_ok('-m', 'inspect', 'unittest', '--details') output = out.decode() # Just a quick sanity check on the output self.assertIn(module.__name__, output) self.assertIn(module.__file__, output) if not sys.flags.optimize: self.assertIn(module.__cached__, output) self.assertEqual(err, b'')