def test_heritage(self): self.assertEqual( list(RelativePath("a", "b", "c", "d").heritage()), [ RelativePath("a"), RelativePath("a", "b"), RelativePath("a", "b", "c"), RelativePath("a", "b", "c", "d"), ], )
def test_realpath_relative(self): fs = self.FS() tempdir = fs.temporary_directory() self.addCleanup(fs.remove, tempdir) tempdir = fs.realpath(tempdir) source, to = RelativePath("source", "dir"), tempdir.descendant("to") fs.link(source=source, to=to) self.assertEqual( fs.realpath(to), to.sibling("source").descendant("dir"), )
def test_relative_to(self): self.assertEqual( RelativePath("a", "b", "c").relative_to(Path("d", "e")), Path("d", "e", "a", "b", "c"), )
def test_str(self): self.assertEqual(str(RelativePath("a", "b", "c")), "a/b/c")
def test_from_string_relative_repeated_separator(self): self.assertEqual( Path.from_string("a" + os.sep * 3 + "b" + os.sep * 2 + "c"), RelativePath("a", "", "", "b", "", "c"), )
def test_from_string_parent(self): self.assertEqual( Path.from_string((os.pardir + os.sep + "a" + os.sep + "b" + os.sep + os.pardir + os.sep + "b"), ), RelativePath(os.pardir, "a", "b", os.pardir, "b"), )
def test_is_pathlike(self): self.assertEqual( os.fspath(RelativePath("a", "b", "c")), os.path.join("a", "b", "c"), )
def test_from_string_relative(self): self.assertEqual( Path.from_string(os.sep.join("abc")), RelativePath("a", "b", "c"), )
def test_sibling(self): self.assertEqual( RelativePath("a", "b").sibling("c"), RelativePath("a", "c"), )
def test_multi_descendant(self): self.assertEqual( RelativePath("a").descendant("b", "c"), RelativePath("a", "b", "c"), )
def test_parent(self): self.assertEqual(RelativePath("a", "b").parent(), RelativePath("a"))
def test_div(self): self.assertEqual( RelativePath("a") / "b" / "c", RelativePath("a", "b", "c"), )
def test_dirname(self): self.assertEqual( RelativePath("a", "b", "c").dirname(), os.path.join("a", "b"), )
def test_basename(self): self.assertEqual(RelativePath("a", "b").basename(), "b")
def test_repr(self): self.assertEqual(repr(RelativePath("a", "b", "c")), "<Path a/b/c>")
def test_str(self): self.assertEqual( str(RelativePath("a", "b", "c")), os.path.join("a", "b", "c"), )
def test_div_nonsense(self): with self.assertRaises(TypeError): RelativePath("a") / object()