def __exit__(self, type, value, tb): pkg_resources.working_set = self._original_working_set sys.path.remove(self.root_path) modules_to_remove = filter(lambda name: name.startswith(self.name), sys.modules) modules_to_remove += (set(sys.modules.keys()) & set(parent_namespaces(self.name))) for name in modules_to_remove: del sys.modules[name]
def _create_namespaces(self): for dottedname in parent_namespaces(self.name): path = self.path.joinpath(*dottedname.split('.')) create(Builder('namespace package').at_path(path))
def test_returns_a_list_of_parent_namespaces_in_order(self): self.assertEqual( ['one', 'one.two', 'one.two.three'], parent_namespaces('one.two.three.four'))
def _create_setup(self): self.with_root_file('setup.py', SETUP_PY_TEMPLATE.format( name=self.name, version=self.version, namespaces=parent_namespaces(self.name)))
def test_returns_empty_list_for_first_level_dottednames(self): self.assertEqual( [], parent_namespaces('one'))