MCPcopy Create free account
hub / github.com/python/cpython / setUp

Method setUp

Lib/test/test_import/__init__.py:1748–1769  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1746 tagged = package_name + '-tagged'
1747
1748 def setUp(self):
1749 os_helper.rmtree(self.tagged)
1750 os_helper.rmtree(self.package_name)
1751 self.orig_sys_path = sys.path[:]
1752
1753 # create a sample package; imagine you have a package with a tag and
1754 # you want to symbolically link it from its untagged name.
1755 os.mkdir(self.tagged)
1756 self.addCleanup(os_helper.rmtree, self.tagged)
1757 init_file = os.path.join(self.tagged, '__init__.py')
1758 os_helper.create_empty_file(init_file)
1759 assert os.path.exists(init_file)
1760
1761 # now create a symlink to the tagged package
1762 # sample -> sample-tagged
1763 os.symlink(self.tagged, self.package_name, target_is_directory=True)
1764 self.addCleanup(os_helper.unlink, self.package_name)
1765 importlib.invalidate_caches()
1766
1767 self.assertEqual(os.path.isdir(self.package_name), True)
1768
1769 assert os.path.isfile(os.path.join(self.package_name, '__init__.py'))
1770
1771 def tearDown(self):
1772 sys.path[:] = self.orig_sys_path

Callers

nothing calls this directly

Calls 8

addCleanupMethod · 0.80
mkdirMethod · 0.45
joinMethod · 0.45
existsMethod · 0.45
invalidate_cachesMethod · 0.45
assertEqualMethod · 0.45
isdirMethod · 0.45
isfileMethod · 0.45

Tested by

no test coverage detected