示例#1
0
    def test_delete_file(self, source, destination):
        sys.argv = [source, destination, "--verbose", "--init"]
        self.assertFalse(os.path.isdir(os.path.join(source, "new_file.txt")))
        self.assertFalse(os.path.isfile(os.path.join(destination, "new_file.txt")))

        with open(
            os.path.join(source, "new_file.txt"), "w", encoding="UTF-8"
        ) as new_file:
            new_file.write("test integrazione 3")

        path, handler = setup_var_from_args(sys.argv)

        self.assertEqual(source, path)
        self.assertEqual(source, handler.path)
        self.assertEqual(destination, handler.dst)
        self.assertFalse(handler.dryrun)
        self.assertTrue(handler.verbose)

        self.assertTrue(os.path.isfile(os.path.join(source, "new_file.txt")))
        self.assertTrue(os.path.isfile(os.path.join(destination, "new_file.txt")))

        observer = Observer()
        observer.schedule(handler, path, recursive=True)
        observer.start()

        os.remove(os.path.join(source, "new_file.txt"))
        time.sleep(5)

        observer.stop()
        observer.join()

        self.assertFalse(os.path.isfile(os.path.join(source, "new_file.txt")))
        self.assertFalse(os.path.isfile(os.path.join(destination, "new_file.txt")))
示例#2
0
    def test_create_sub_dir(self, source, destination):
        sys.argv = [source, destination, "--verbose"]
        self.assertFalse(os.path.isdir(os.path.join(source, "new_dir/")))
        self.assertFalse(os.path.isdir(os.path.join(destination, "new_dir/")))

        path, handler = setup_var_from_args(sys.argv)

        self.assertEqual(source, path)
        self.assertEqual(source, handler.path)
        self.assertEqual(destination, handler.dst)
        self.assertFalse(handler.dryrun)
        self.assertTrue(handler.verbose)

        observer = Observer()
        observer.schedule(handler, path, recursive=True)
        observer.start()

        os.mkdir(os.path.join(source, "new_dir/"))

        time.sleep(5)

        observer.stop()
        observer.join()

        self.assertTrue(os.path.isdir(os.path.join(source, "new_dir/")))
        self.assertTrue(os.path.isdir(os.path.join(destination, "new_dir/")))
示例#3
0
 def test_dryrun_verbose(self, source, destination):
     sys.argv = [source, destination, "--dryrun", "--verbose"]
     path, handler = setup_var_from_args(sys.argv)
     self.assertEqual(source, path)
     self.assertEqual(source, handler.path)
     self.assertEqual(destination, handler.dst)
     self.assertTrue(handler.dryrun)
     self.assertTrue(handler.verbose)
示例#4
0
 def test_just_dirs(self, source, destination):
     sys.argv = [source, destination]
     path, handler = setup_var_from_args(sys.argv)
     self.assertEqual(source, path)
     self.assertEqual(source, handler.path)
     self.assertEqual(destination, handler.dst)
     self.assertFalse(handler.dryrun)
     self.assertFalse(handler.verbose)
示例#5
0
    def test_init_one_file(self, source, destination):
        sys.argv = [source, destination, "--init"]

        with open(os.path.join(source, "test.txt"), "w", encoding="UTF-8") as o_file:
            o_file.write("test di integrazione 1")
        self.assertTrue(os.path.isfile(os.path.join(source, "test.txt")))
        self.assertFalse(os.path.isfile(os.path.join(destination, "test.txt")))

        path, handler = setup_var_from_args(sys.argv)
        self.assertEqual(source, path)
        self.assertEqual(source, handler.path)
        self.assertEqual(destination, handler.dst)
        self.assertFalse(handler.dryrun)
        self.assertFalse(handler.verbose)

        self.assertTrue(os.path.isfile(os.path.join(destination, "test.txt")))
        with open(
            os.path.join(destination, "test.txt"), "r", encoding="UTF-8"
        ) as i_file:
            self.assertEqual(i_file.read(), "test di integrazione 1")