예제 #1
0
    def test_must_copy_files_recursively(self):
        file(self.source, "a", "file.txt")
        file(self.source, "a", "b", "file.txt")
        file(self.source, "a", "c", "file.txt")

        copytree(self.source, self.dest)
        self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "file.txt")))
        self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "b", "file.txt")))
        self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "c", "file.txt")))
예제 #2
0
    def execute(self):
        deps_manager = DependencyManager(self.source_dir, self.artifact_dir,
                                         self.dest_dir)

        for dependencies_source, new_destination in deps_manager.yield_source_dest(
        ):
            if os.path.isdir(dependencies_source):
                copytree(dependencies_source, new_destination)
            else:
                os.makedirs(os.path.dirname(new_destination), exist_ok=True)
                shutil.copy2(dependencies_source, new_destination)
예제 #3
0
    def test_must_respect_excludes_list(self):
        file(self.source, ".git", "file.txt")
        file(self.source, "nested", ".aws-sam", "file.txt")
        file(self.source, "main.pyc")
        file(self.source, "a", "c", "file.txt")

        excludes = [".git", ".aws-sam", "*.pyc"]

        copytree(self.source, self.dest, ignore=shutil.ignore_patterns(*excludes))
        self.assertEquals(set(os.listdir(self.dest)), {"nested", "a"})
        self.assertEquals(set(os.listdir(os.path.join(self.dest, "nested"))), set())
        self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"})
        self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"})
예제 #4
0
    def test_must_respect_include_function(self):
        file(self.source, "nested", "folder", "file.txt")
        file(self.source, "main.pyc")
        file(self.source, "file.txt")

        def _include_check(file_name):
            return file_name.endswith(".txt")

        copytree(self.source, self.dest, include=_include_check)
        self.assertTrue(
            os.path.exists(
                os.path.join(self.dest, "nested", "folder", "file.txt")))
        self.assertTrue(os.path.exists(os.path.join(self.dest, "file.txt")))
        self.assertFalse(os.path.exists(os.path.join(self.dest, "main.pyc")))
예제 #5
0
    def test_move_dependencies_action(self, source_folder):
        curr_dir = Path(__file__).resolve().parent
        test_folder = os.path.join(curr_dir, "testdata", source_folder)
        with tempfile.TemporaryDirectory() as tmpdir:
            test_source = os.path.join(tmpdir, "test_source")
            empty_source = os.path.join(tmpdir, "empty_source")
            target = os.path.join(tmpdir, "target")

            os.mkdir(test_source)
            os.mkdir(empty_source)

            copytree(test_folder, test_source)

            move_dependencies_action = MoveDependenciesAction(empty_source, test_source, target)
            move_dependencies_action.execute()

            self.assertEqual(os.listdir(test_folder), os.listdir(target))
 def execute(self):
     copytree(self.source_dir,
              self.dest_dir,
              ignore=shutil.ignore_patterns(*self.excludes))
예제 #7
0
 def copytree(self, source, destination, ignore=None, include=None):
     copytree(source, destination, ignore=ignore, include=include)
예제 #8
0
 def test_must_skip_if_source_folder_does_not_exist(self):
     copytree(os.path.join(self.source, "some-random-file"), self.dest)
     self.assertEqual(set(os.listdir(self.dest)), set())