コード例 #1
0
    def test_move_file_from_src_dir_when_multi_in_src(self):
        """当src有多个文件时"""
        import os
        from zzpy import write_file
        from zzpy import get_file_path_list_from_dir
        from zzpy import move_file_from_src_dir
        from zzpy import create_dir

        write_file("1", os.path.join(self.root_dir, "src", "1.txt"))
        write_file("2", os.path.join(self.root_dir, "src", "2.txt"))
        write_file("2", os.path.join(self.root_dir, "dst", "3.txt"))
        move_file_from_src_dir(dst_file_path=os.path.join(
            self.root_dir, "dst", "0.txt"),
                               src_dir_path=os.path.join(self.root_dir, "src"))
        src_pathes = get_file_path_list_from_dir(
            os.path.join(self.root_dir, "src"))
        self.assertEqual(len(src_pathes), 1)
        self.assertIn(src_pathes[0],
                      (os.path.join(self.root_dir, "src", "1.txt"),
                       os.path.join(self.root_dir, "src", "2.txt")))
        dst_pathes = get_file_path_list_from_dir(
            os.path.join(self.root_dir, "dst"))
        self.assertEqual(len(dst_pathes), 2)
        self.assertListEqual(dst_pathes, [
            os.path.join(self.root_dir, "dst", "0.txt"),
            os.path.join(self.root_dir, "dst", "3.txt")
        ])
コード例 #2
0
    def test_move_file_from_src_dir_when_no_file_in_src(self):
        """当src没有文件时"""
        import os
        from zzpy import write_file
        from zzpy import get_file_path_list_from_dir
        from zzpy import move_file_from_src_dir

        move_file_from_src_dir(dst_file_path=os.path.join(
            self.root_dir, "dst", "1.txt"),
                               src_dir_path=os.path.join(self.root_dir, "src"))
        self.assertListEqual(
            get_file_path_list_from_dir(os.path.join(self.root_dir, "src")),
            [])
        self.assertListEqual(
            get_file_path_list_from_dir(os.path.join(self.root_dir, "dst")),
            [])
コード例 #3
0
    def test_move_file_from_src_dir_when_single_in_src_and_dst_not_exist(self):
        """当src只有一个文件,dst不存在时"""
        import os
        from zzpy import write_file
        from zzpy import get_file_path_list_from_dir
        from zzpy import move_file_from_src_dir

        write_file("1", os.path.join(self.root_dir, "src", "1.txt"))
        move_file_from_src_dir(dst_file_path=os.path.join(
            self.root_dir, "dst", "1.txt"),
                               src_dir_path=os.path.join(self.root_dir, "src"))
        self.assertListEqual(
            get_file_path_list_from_dir(os.path.join(self.root_dir, "src")),
            [])
        self.assertListEqual(
            get_file_path_list_from_dir(os.path.join(self.root_dir, "dst")),
            [os.path.join(self.root_dir, "dst", "1.txt")])
コード例 #4
0
    def test_move_file_from_src_dir_when_src_and_dst_have_same_file(self):
        """当src有多个文件时"""
        import os
        from zzpy import write_file
        from zzpy import get_file_path_list_from_dir
        from zzpy import move_file_from_src_dir
        from zzpy import read_file

        write_file("1", os.path.join(self.root_dir, "src", "1.txt"))
        write_file("2", os.path.join(self.root_dir, "dst", "1.txt"))
        move_file_from_src_dir(dst_file_path=os.path.join(
            self.root_dir, "dst", "1.txt"),
                               src_dir_path=os.path.join(self.root_dir, "src"))
        src_pathes = get_file_path_list_from_dir(
            os.path.join(self.root_dir, "src"))
        self.assertEqual(len(src_pathes), 0)

        dst_pathes = get_file_path_list_from_dir(
            os.path.join(self.root_dir, "dst"))
        self.assertEqual(len(dst_pathes), 1)
        dst_path = dst_pathes[0]
        self.assertEqual(dst_path, os.path.join(self.root_dir, "dst", "1.txt"))
        self.assertEqual(read_file(dst_path), "1")