def test_modules_string(self): sock = __import__('socket') assert resolve('socket') is sock assert resolve('getfqdn', 'socket') is sock.getfqdn assert resolve('iterators', 'pockets') is pockets.iterators assert resolve('iterpeek', 'pockets.iterators') is \ pockets.iterators.iterpeek assert resolve('iterators.iterpeek', 'pockets') is \ pockets.iterators.iterpeek
def test_modules_string(self): dt = __import__("datetime") self.assertTrue(resolve("datetime") is dt) self.assertTrue(resolve("datetime", "datetime") is dt.datetime) self.assertTrue(resolve("iterators", "pockets") is pockets.iterators) self.assertTrue(resolve("peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue(resolve("iterators.peek_iter", "pockets") is pockets.iterators.peek_iter)
def test_modules_string(self): dt = __import__("datetime") self.assertTrue(resolve("datetime") is dt) self.assertTrue(resolve("datetime", "datetime") is dt.datetime) self.assertTrue(resolve("iterators", "pockets") is pockets.iterators) self.assertTrue( resolve("peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue( resolve("iterators.peek_iter", "pockets") is pockets.iterators.peek_iter)
def test_modules_none(self): self.assertTrue(resolve("pockets") is pockets) self.assertTrue(resolve("pockets.iterators") is pockets.iterators) self.assertTrue(resolve("pockets.iterators.peek_iter") is pockets.iterators.peek_iter)
def test_local_module(self): self.assertTrue(resolve("TestResolve") is self.__class__) self.assertTrue(resolve("TestResolve", "tests.test_inspect") is self.__class__) self.assertRaises(ValueError, resolve, "TestResolve", "pockets")
def test_object(self): x = object() self.assertTrue(resolve(x) is x) self.assertTrue(resolve(x, "pockets") is x) self.assertTrue(resolve(x, ["pockets"]) is x) self.assertTrue(resolve(x, ["pockets", "re"]) is x)
def test_none(self): self.assertTrue(resolve(None) is None)
def test_relative_import(self): dt = __import__("datetime") self.assertTrue(resolve(".datetime") is dt) self.assertTrue(resolve("..datetime") is dt) self.assertTrue(resolve(".datetime", "datetime") is dt.datetime) self.assertTrue(resolve("..datetime", "datetime") is dt.datetime) self.assertTrue(resolve(".iterators", "pockets") is pockets.iterators) self.assertTrue(resolve("..iterators", "pockets") is pockets.iterators) self.assertTrue( resolve(".peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue( resolve("..peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue( resolve(".iterators.peek_iter", "pockets") is pockets.iterators.peek_iter) self.assertTrue( resolve("..iterators.peek_iter", "pockets") is pockets.iterators.peek_iter) mod = sys.modules["tests.test_inspect"] mod.MOD_ATTR = "asdf" self.assertEqual(resolve("MOD_ATTR"), "asdf") self.assertEqual(resolve(".MOD_ATTR"), "asdf") # Seems odd that this would raise an error, seeing as it worked # fine two lines above. However, resolve uses the *calling* function's # module as the search path, which in this case is unittest self.assertRaises(ValueError, resolve, "MOD_ATTR") self.assertRaises(ValueError, resolve, ".MOD_ATTR") re_mod = __import__("re") mod.re = "zxcv" self.assertTrue(resolve("re") is re_mod) self.assertEqual(resolve(".re"), "zxcv") self.assertTrue(resolve("..re") is re_mod) self.assertTrue(resolve("...re") is re_mod) self.assertEqual(resolve("re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve(".re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve("..re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve("test_inspect.re", "tests"), "zxcv") self.assertEqual(resolve(".test_inspect.re", "tests"), "zxcv") self.assertEqual(resolve("..test_inspect.re", "tests"), "zxcv")
def test_object(self): x = object() assert resolve(x) is x assert resolve(x, 'pockets') is x assert resolve(x, ['pockets']) is x assert resolve(x, ['pockets', 're']) is x
def test_local_module(self): self.assertTrue(resolve("TestResolve") is self.__class__) self.assertTrue( resolve("TestResolve", "tests.test_inspect") is self.__class__) self.assertRaises(ValueError, resolve, "TestResolve", "pockets")
def test_relative_import(self): sock = __import__('socket') assert resolve('.socket') is sock assert resolve('..socket') is sock assert resolve('.getfqdn', 'socket') is sock.getfqdn assert resolve('..getfqdn', 'socket') is sock.getfqdn assert resolve('.iterators', 'pockets') is pockets.iterators assert resolve('..iterators', 'pockets') is pockets.iterators assert resolve('.iterpeek', 'pockets.iterators') is \ pockets.iterators.iterpeek assert resolve('..iterpeek', 'pockets.iterators') is \ pockets.iterators.iterpeek assert resolve('.iterators.iterpeek', 'pockets') is \ pockets.iterators.iterpeek assert resolve('..iterators.iterpeek', 'pockets') is \ pockets.iterators.iterpeek mod = sys.modules['tests.test_inspect'] mod.MOD_ATTR = 'asdf' assert resolve('MOD_ATTR') == 'asdf' assert resolve('.MOD_ATTR') == 'asdf' # Seems odd that this would raise an error, seeing as it worked # fine two lines above. However, resolve uses the *calling* function's # module as the search path, which in this case is pytest pytest.raises(ValueError, resolve, 'MOD_ATTR') pytest.raises(ValueError, resolve, '.MOD_ATTR') re_mod = __import__('re') mod.re = 'zxcv' assert resolve('re') is re_mod assert resolve('.re') == 'zxcv' assert resolve('..re') is re_mod assert resolve('...re') is re_mod assert resolve('re', 'tests.test_inspect') == 'zxcv' assert resolve('.re', 'tests.test_inspect') == 'zxcv' assert resolve('..re', 'tests.test_inspect') == 'zxcv' assert resolve('test_inspect.re', 'tests') == 'zxcv' assert resolve('.test_inspect.re', 'tests') == 'zxcv' assert resolve('..test_inspect.re', 'tests') == 'zxcv'
def test_modules_none(self): assert resolve('pockets') is pockets assert resolve('pockets.iterators') is pockets.iterators assert resolve('pockets.iterators.iterpeek') is \ pockets.iterators.iterpeek
def test_local_module(self): assert resolve('TestResolve') is self.__class__ assert resolve('TestResolve', 'tests.test_inspect') is self.__class__ pytest.raises(ValueError, resolve, 'TestResolve', 'pockets')
def test_modules_none(self): self.assertTrue(resolve("pockets") is pockets) self.assertTrue(resolve("pockets.iterators") is pockets.iterators) self.assertTrue( resolve("pockets.iterators.peek_iter") is pockets.iterators.peek_iter)
def test_relative_import(self): dt = __import__("datetime") self.assertTrue(resolve(".datetime") is dt) self.assertTrue(resolve("..datetime") is dt) self.assertTrue(resolve(".datetime", "datetime") is dt.datetime) self.assertTrue(resolve("..datetime", "datetime") is dt.datetime) self.assertTrue(resolve(".iterators", "pockets") is pockets.iterators) self.assertTrue(resolve("..iterators", "pockets") is pockets.iterators) self.assertTrue(resolve(".peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue(resolve("..peek_iter", "pockets.iterators") is pockets.iterators.peek_iter) self.assertTrue(resolve(".iterators.peek_iter", "pockets") is pockets.iterators.peek_iter) self.assertTrue(resolve("..iterators.peek_iter", "pockets") is pockets.iterators.peek_iter) mod = sys.modules["tests.test_inspect"] mod.MOD_ATTR = "asdf" self.assertEqual(resolve("MOD_ATTR"), "asdf") self.assertEqual(resolve(".MOD_ATTR"), "asdf") # Seems odd that this would raise an error, seeing as it worked # fine two lines above. However, resolve uses the *calling* function's # module as the search path, which in this case is unittest self.assertRaises(ValueError, resolve, "MOD_ATTR") self.assertRaises(ValueError, resolve, ".MOD_ATTR") re_mod = __import__("re") mod.re = "zxcv" self.assertTrue(resolve("re") is re_mod) self.assertEqual(resolve(".re"), "zxcv") self.assertTrue(resolve("..re") is re_mod) self.assertTrue(resolve("...re") is re_mod) self.assertEqual(resolve("re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve(".re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve("..re", "tests.test_inspect"), "zxcv") self.assertEqual(resolve("test_inspect.re", "tests"), "zxcv") self.assertEqual(resolve(".test_inspect.re", "tests"), "zxcv") self.assertEqual(resolve("..test_inspect.re", "tests"), "zxcv")
def test_none(self): assert resolve(None) is None