def test_heritage(self): self.assertEqual( list(Path("a", "b", "c", "d").heritage()), [ Path("a"), Path("a", "b"), Path("a", "b", "c"), Path("a", "b", "c", "d"), ], )
def test_find_existing_by_dir_succeeds_for_existing_virtualenvs(self): self.filesystem.create_directory(self.locator.root / "bla") path = Path("foo", "bla") stdout, stderr = self.run_cli( ["find", "--existing-only", "directory", str(path)], ) self.assertEqual( (stdout, stderr), (str(self.locator.for_directory(path).path) + "\n", ""), )
def setUp(self): super(CLIMixin, self).setUp() self.stdin = NativeStringIO() self.stdout = NativeStringIO() self.stderr = NativeStringIO() self.filesystem = filesystems.memory.FS() self.root_dir = Path("virtualenvs") self.filesystem.create_directory(self.root_dir) self.link_dir = Path("bin") self.filesystem.create_directory(self.link_dir) self.locator = Locator( root=self.root_dir, make_virtualenv=lambda **kwargs: VirtualEnv( create=self.fake_create, install=self.fake_install, **kwargs), )
def temporary_directory(self): # TODO: Maybe this isn't good enough. directory = Path(uuid4().hex) self.create_directory(path=directory, with_parents=False) return directory
def test_descendant(self): self.assertEqual(Path("a", "b").descendant("c"), Path("a", "b", "c"))
def test_relative_to(self): self.assertEqual( RelativePath("a", "b", "c").relative_to(Path("d", "e")), Path("d", "e", "a", "b", "c"), )
def test_root_dirname(self): self.assertEqual(Path().dirname(), "/")
def test_dirname(self): self.assertEqual(Path("a", "b", "c").dirname(), "/a/b")
def test_root_basename(self): self.assertEqual(Path().basename(), "")
def test_instances_are_independent(self): fs = self.FS() fs.touch(Path("file")) self.assertTrue(fs.exists(Path("file"))) self.assertFalse(self.FS().exists(Path("file")))
def test_root(self): self.assertEqual(Path.root(), Path())
def test_from_string(self): self.assertEqual(Path.from_string("/a/b/c"), Path("a", "b", "c"))
def test_sibling(self): self.assertEqual(Path("a", "b").sibling("c"), Path("a", "c"))
def test_parent(self): self.assertEqual(Path("a", "b").parent(), Path("a"))
def test_basename(self): self.assertEqual(Path("a", "b").basename(), "b")
def test_prepended_override(self): command = Command("foo", "bar", cwd=Path("tmp", "foo")) self.assertThat( command.prepended("baz", cwd=Path("tmp", "bar")), Equals(Command("baz", "foo", "bar", cwd=Path("tmp", "bar"))), )
def test_children_of_nonempty_root(self): fs = self.FS() fs.touch(Path("file")) self.assertEqual(fs.children(Path.root()), s(Path("file")))