def test_find_relative_module_missing_package(self): name = 'spam' subname = 'ham' with util.temp_module(name, pkg=True) as pkg_dir: fullname, _ = util.submodule(name, subname, pkg_dir) relname = '.' + subname with self.assertRaises(ValueError): self.util.find_spec(relname) self.assertNotIn(name, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules))
def test_find_submodule(self): name = 'spam' subname = 'ham' with util.temp_module(name, pkg=True) as pkg_dir: fullname, _ = util.submodule(name, subname, pkg_dir) spec = self.util.find_spec(fullname) self.assertIsNot(spec, None) self.assertIn(name, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules)) spec_again = self.util.find_spec(fullname) self.assertEqual(spec_again, spec)
def test_find_submodule(self): name = 'spam' subname = 'ham' with util.temp_module(name, pkg=True) as pkg_dir: fullname, _ = util.submodule(name, subname, pkg_dir) spec = self.util.find_spec(fullname) self.assertIsNot(spec, None) self.assertIn(name, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules)) # Ensure successive calls behave the same. spec_again = self.util.find_spec(fullname) self.assertEqual(spec_again, spec)
def test_find_relative_module(self): name = 'spam' subname = 'ham' with util.temp_module(name, pkg=True) as pkg_dir: fullname, _ = util.submodule(name, subname, pkg_dir) relname = '.' + subname spec = self.util.find_spec(relname, name) self.assertIsNot(spec, None) self.assertIn(name, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules)) # Ensure successive calls behave the same. spec_again = self.util.find_spec(fullname) self.assertEqual(spec_again, spec)
def test_find_submodule_parent_already_imported(self): name = 'spam' subname = 'ham' with util.temp_module(name, pkg=True) as pkg_dir: self.init.import_module(name) fullname, _ = util.submodule(name, subname, pkg_dir) spec = self.util.find_spec(fullname) self.assertIsNot(spec, None) self.assertIn(name, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules)) # Ensure successive calls behave the same. spec_again = self.util.find_spec(fullname) self.assertEqual(spec_again, spec)