def test_insideSet(self): l1 = [VirtualPath("/foo/bar"), VirtualPath("/foo/baz")] l2 = l1 + [VirtualPath("/foo/bar")] # l2 has a duplicate element # Sets allow one to ignore duplicate elements when comparing self.assertEqual(set(l1), set(l2)) self.assertEqual(frozenset(l1), frozenset(l2))
def test_inPlacePathConcatenation(self): p = VirtualPath("/foo/bar/baz/quux/zoot") q = MutableVirtualPath("/foo") q /= "bar" q /= "baz/quux/zoot" self.assertTrue(p.samePath(q))
def test_withSuffix(self): p = self.cls("/foo/bar/baz.tar.gz") self.assertEqual(p.withSuffix(".bz2"), VirtualPath("/foo/bar/baz.tar.bz2")) p = self.cls("/foo/bar/baz") self.assertEqual(p.withSuffix(".tar.xz"), VirtualPath("/foo/bar/baz.tar.xz")) # The self.cls object has no 'name' (referring to the 'name' property) with self.assertRaises(ValueError): self.cls("/foo/bar/baz.tar.gz").withSuffix("no-leading-dot") with self.assertRaises(ValueError): # The root virtual path ('/') can't be used for this self.cls("/").withSuffix(".foobar")
def test_withName(self): p = self.cls("/foo/bar/baz/quux/zoot") self.assertEqual(p.withName(""), VirtualPath("/foo/bar/baz/quux")) self.assertEqual(p.withName("pouet"), VirtualPath("/foo/bar/baz/quux/pouet")) self.assertEqual(p.withName("pouet/zdong"), VirtualPath("/foo/bar/baz/quux/pouet/zdong")) # The self.cls object has no 'name' (referring to the 'name' property) with self.assertRaises(ValueError): self.cls("").withName("foobar") with self.assertRaises(ValueError): self.cls("/").withName("foobar")
def test_constructor(self): d = DirIndex(testData("good", "sample_dirindex_1")) self.assertEqual(d.version, 1) self.assertEqual(d.path, VirtualPath("some/path")) self.assertEqual(d.directories, directories_in_sample_dirindex_1) self.assertEqual(d.files, files_in_sample_dirindex_1) self.assertEqual(d.tarballs, tarballs_in_sample_dirindex_1) stems = ( "path_starts_with_slash", "path_contains_a_backslash", "dotdot_in_path", "slash_in_directory_name", "slash_in_file_name", "slash_in_tarball_name", "backslash_in_directory_name", "backslash_in_file_name", "backslash_in_tarball_name", "directory_name_is_double_colon", "file_name_is_double_colon", "tarball_name_is_double_colon", ) for stem in stems: with self.assertRaises(InvalidDirIndexFile): DirIndex(testData("bad", "bad_dirindex_" + stem)) with self.assertRaises(UnicodeDecodeError): d = DirIndex(testData("bad", "bad_dirindex_encoding"))
def test_mixedComparisons(self): self.assertTrue( VirtualPath("/abc/def").samePath(MutableVirtualPath("/abc/def"))) self.assertTrue( VirtualPath("/abc//def").samePath(MutableVirtualPath("/abc/def"))) self.assertTrue( VirtualPath("/abc/def/").samePath(MutableVirtualPath("/abc/def"))) self.assertTrue( MutableVirtualPath("/abc/def").samePath(VirtualPath("/abc/def"))) self.assertTrue( MutableVirtualPath("/abc//def").samePath(VirtualPath("/abc/def"))) self.assertTrue( MutableVirtualPath("/abc/def/").samePath(VirtualPath("/abc/def")))
def test_isHashableType(self): p = VirtualPath("/foo") self.assertTrue(isinstance(p, collections.abc.Hashable))