Beispiel #1
0
 def test_equals_by_path(self):
     cfile1 = CFile('a', 2, 3)
     cfile2 = CFile('a', 4, 6)
     # NOT Equal
     self.assertFalse(cfile1.equals(cfile2))
     # But equal by path
     self.assertTrue(cfile1.equals_by_path_only(cfile2))
Beispiel #2
0
 def test_to_dict(self):
     cfile1 = CFile('a', 2, 3)
     self.assertEqual(
         {
             'type': 'FILE',
             'names': ('a', ),
             'path': 'a',
             'mtime': 2,
             'size': 3
         }, cfile1.to_dict())
Beispiel #3
0
 def test_is_ancestor(self):
     # root dir root cannot play ancestor
     self.assertFalse(CPathUtils.is_ancestor(CDir(""), CDir("")))
     # ancestor must be dir
     self.assertRaises(CFSException, lambda: CPathUtils.is_ancestor(
         CPath("a"), CPath("a/b/c/d")))  # TODO: create proper exception
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_ancestor(CFile("a", 1, 2), CPath("a/b/c/d")))
     # a dir is ancestor
     self.assertTrue(CPathUtils.is_ancestor(CPath("a/"), CPath("a/b/c/d")))
     # parent is also an ancestor
     self.assertTrue(
         CPathUtils.is_ancestor(CPath("a/b/c/"), CPath("a/b/c/d")))
     # not ancestor
     self.assertFalse(
         CPathUtils.is_ancestor(CDir("a/b"), CFile("x/y", 1, 1)))
Beispiel #4
0
 def test_is_parent(self):
     # root dir root cannot play parent child
     self.assertFalse(CPathUtils.is_parent(CDir(""), CDir("")))
     # parent must be dir
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_parent(CPath("a"), CPath("a/b")))
     self.assertRaises(
         CFSException,
         lambda: CPathUtils.is_parent(CFile("a", 1, 2), CPath("a/b/")))
     # a dir is parent
     self.assertTrue(CPathUtils.is_parent(CPath("a/"), CPath("a/b")))
     self.assertTrue(CPathUtils.is_parent(CPath("a/b/"),
                                          CPath("a/b/c.txt")))
     # not parent
     self.assertFalse(
         CPathUtils.is_ancestor(CDir("a/b"), CFile("x/y", 1, 1)))
Beispiel #5
0
    def setUp(self) -> None:
        root_tree1 = CDirTree()
        root_tree1.add(CFile("d1/a.txt", 1, 2))
        root_tree1.add(CDir("d2/"))
        root_tree1.add(CDir("d3/p/q/r"))
        root_tree1.add(CFile("d3/p/x.txt", 1, 5))

        root_tree2 = CDirTree()
        root_tree2.add(CFile("d1/a.txt", 1, 2))
        # root_tree2.add(CDir("dir2/"))  - deleted
        root_tree2.add(CDir("d3/p/q/r"))
        root_tree2.add(CFile("d3/p/x.txt", 1, 5))
        root_tree2.add(CFile("d3/p/y.txt", 1, 5))  # new

        # TODO: test in real file system too, with hash

        self.root_tree1 = root_tree1
        self.root_tree2 = root_tree2

        self.diff = self.root_tree1.diff(root_tree2)
    def test_exists__path_type_independence(self):
        cpath1 = CPath(f"{self.this_test_dir_name}/subdir/afile")
        cfile1 = CFile(f"{self.this_test_dir_name}/subdir/afile", 1, 1)

        cpath2 = CPath(f"{self.this_test_dir_name}/subdir")
        cdir2 = CDir(f"{self.this_test_dir_name}/subdir")

        self.assertTrue(self.real_fs.exists(cpath1))
        self.assertTrue(self.real_fs.exists(cfile1))

        self.assertTrue(self.real_fs.exists(cpath2))
        self.assertTrue(self.real_fs.exists(cdir2))
Beispiel #7
0
 def test_init_empty_file_path(self):
     cfile_creation = lambda: CFile("", 1, 1)
     self.assertRaises(CFSExceptionInvalidPathName, cfile_creation)
Beispiel #8
0
 def test_equals_by_size_timestamp(self):
     cfile1 = CFile('a', 2, 3)
     cfile2 = CFile('a', 2, 3)
     self.assertTrue(cfile1.equals_with_size_timestamp(cfile2))
Beispiel #9
0
 def test_equals(self):
     cfile1 = CFile('a', 2, 3)
     cfile2 = CFile('a', 2, 3)
     self.assertTrue(cfile1.equals(cfile2))
Beispiel #10
0
 def test_is_dir(self):
     cpath = CPath('/a/')
     cfile = CFile('/a', 1, 1)
     self.assertNotEqual(cpath.is_dir(), cfile.is_dir())
Beispiel #11
0
 def test_is_file(self):
     cpath = CPath('/a')
     cfile = CFile('/a', 1, 1)
     self.assertEqual(cpath.is_file(), cfile.is_file())
Beispiel #12
0
 def test_get_type(self):
     cpath = CPath("a/v")
     self.assertEqual(cpath.get_type(), CPathType.FILE)
     cfile = CFile("a/v", 1, 1)
     self.assertEqual(cfile.get_type(), CPathType.FILE)
Beispiel #13
0
 def test_init_without_size_mtime(self):
     self.assertRaises(TypeError, lambda: CFile("a.txt"))
Beispiel #14
0
 def test_path_with_slash_at_the_end(self):
     self.assertRaises(CFSExceptionInvalidPathName,
                       lambda: CFile("a/v/", 1, 1))
Beispiel #15
0
 def test_init_by_cdir(self):
     cdir = CDir("a")
     self.assertRaises(CFSExceptionInvalidPathName,
                       lambda: CFile(cdir, 1, 1))
Beispiel #16
0
 def test_init_by_cfile(self):
     cfile = CFile("a", 1, 2)
     self.assertRaises(CFSExceptionInvalidPathName, lambda: CDir(cfile))