def repository_path(): """ :return: The nearest ``FilePath`` in parents of this module that have a ``flocker/__init__.py`` file that matches what will be imported as ``flocker``. """ current_module_path = FilePath(__file__) for parent in current_module_path.parents(): flocker_init = parent.descendant(['flocker', '__init__.py']) if flocker_init.exists(): nearest_flocker_path = flocker_init.parent() nearest_flocker_repository = parent break else: raise ImportError( "Could not find ``flocker.__init__.py`` " "in any parent directories: " "{!r}".format(current_module_path.parents()) ) import flocker imported_flocker_path = FilePath(flocker.__file__).parent() if imported_flocker_path != nearest_flocker_path: raise ImportError( "Imported flocker modules are not from this repository. " "Imported: {!r}," "Repository: {!r}".format( imported_flocker_path, nearest_flocker_path ) ) return nearest_flocker_repository
def addDirectory(self, path): """Include `path` in test discovery. This scans all child directories of `path` and also all `parents`; `wantDirectory()` can then do an exact match. """ start = FilePath(path) self.dirs = self.dirs.union( (fp.path for fp in start.parents()), (fp.path for fp in start.walk() if fp.isdir()), )
def test__configure_scans_directories(self): directory = self.make_dir() segments = factory.make_name("child"), factory.make_name("grandchild") makedirs(join(directory, *segments)) select = Select() parser = OptionParser() select.add_options(parser=parser, env={}) options, rest = parser.parse_args( ["--with-select", "--select-dir", directory]) select.configure(options, sentinel.conf) leaf = FilePath(directory).descendant(segments) expected_dirs = {leaf} expected_dirs.update(leaf.parents()) self.assertThat(select.dirs, Equals(set(fp.path for fp in expected_dirs)))