Ejemplo n.º 1
0
def test__dont_overwrite():
    with tempfile.TemporaryDirectory() as dira, tempfile.TemporaryDirectory(
    ) as dirb:
        Path(dira).joinpath("README.md").write_text("README")
        Path(dira).joinpath("code.py").write_text("# code.py")
        Path(dira).joinpath("BUILD").write_text("bazel")

        Path(dirb).joinpath("README.md").write_text("chickens")
        Path(dirb).joinpath("code.py").write_text("# chickens")

        cwd = os.getcwd()
        os.chdir(dirb)
        try:
            _tracked_paths.add(dira)
            transforms.move([Path(dira).joinpath("*")],
                            merge=transforms.dont_overwrite(["*.md"]))
        finally:
            os.chdir(cwd)

        # Should not have been overwritten.
        assert "chickens" == Path(dirb).joinpath("README.md").read_text()
        # Should have been overwritten.
        assert "# code.py" == Path(dirb).joinpath("code.py").read_text()
        # Should have been written.
        assert "bazel" == Path(dirb).joinpath("BUILD").read_text()
Ejemplo n.º 2
0
def test__file_copy_mode(executable_fixtures):
    executable = "exec.sh"
    destination = executable_fixtures / "exec_copy.sh"

    transforms.move([executable], destination)

    # Check if destination file has execute permission for USER
    assert destination.stat().mode & stat.S_IXUSR
Ejemplo n.º 3
0
def test__move_to_dest_subdir(expand_path_fixtures):
    tmp_path = Path(str(expand_path_fixtures))
    _tracked_paths.add(expand_path_fixtures)
    dest = Path(str(expand_path_fixtures / normpath("dest/dira")))

    # Move to a different dir to make sure that move doesn't depend on the cwd
    os.chdir(tempfile.gettempdir())
    transforms.move(tmp_path / "dira", dest, excludes=["f.py"])

    os.chdir(str(tmp_path))
    files = sorted(
        [str(x) for x in transforms._expand_paths("**/*", root="dest")])

    # Assert destination does not contain dira/f.py (excluded)
    assert files == [normpath("dest/dira"), normpath("dest/dira/e.txt")]
Ejemplo n.º 4
0
def test_excluded_file_not_removed(source_tree,
                                   preserve_track_obsolete_file_flag):
    metadata.set_track_obsolete_files(True)
    _tracked_paths.add(source_tree.tmpdir / "build")

    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir /
                                           "synth.metadata"):
        source_tree.write("code/b")
        source_tree.write("code/c")

    metadata.reset()
    # Create a second source tree and copy it into the first.
    with metadata.MetadataTrackerAndWriter(source_tree.tmpdir /
                                           "synth.metadata"):
        # exclude code/c from being copied should mean it doesn't get deleted.
        transforms.move(source_tree.tmpdir / "build", excludes=["code/c"])

    # Confirm remove_obsolete_files deletes b but not c.
    assert not os.path.exists("code/b")
    assert os.path.exists("code/c")
Ejemplo n.º 5
0
def test__move_to_dest(expand_path_fixtures):
    tmp_path = Path(str(expand_path_fixtures))
    _tracked_paths.add(expand_path_fixtures)
    dest = Path(str(expand_path_fixtures / "dest"))

    transforms.move(tmp_path, dest, excludes=["dira/f.py"])

    files = sorted([str(x) for x in transforms._expand_paths("**/*", root="dest")])

    # Assert destination does not contain dira/e.py (excluded)
    assert files == [
        "dest/a.txt",
        "dest/b.py",
        "dest/c.md",
        "dest/dira",
        "dest/dira/e.txt",
        "dest/dirb",
        "dest/dirb/suba",
        "dest/dirb/suba/g.py",
    ]
Ejemplo n.º 6
0
def test_copy_with_merge_file_permissions(expand_path_fixtures):
    destination_file = expand_path_fixtures / "executable_file.sh"
    template_directory = Path(__file__).parent / "fixtures"
    _tracked_paths.add(template_directory)
    template = template_directory / "executable_file.sh"

    # ensure that the destination existing file already has incorrect correct
    # file permissions
    assert os.path.exists(destination_file)
    assert os.stat(destination_file).st_mode != os.stat(template).st_mode

    # Move to a different dir to make sure that move doesn't depend on the cwd
    with util.chdir(tempfile.gettempdir()):
        transforms.move(
            sources=template_directory / "executable_file.sh",
            destination=expand_path_fixtures / "executable_file.sh",
            merge=_noop_merge,
            required=True,
        )

        # ensure that the destination existing file now has the correct file permissions
        assert os.stat(destination_file).st_mode == os.stat(template).st_mode
Ejemplo n.º 7
0
def test_required_move_not_found():
    try:
        transforms.move(["non-existent"], required=True)
        assert False, "should have thrown error"
    except transforms.MissingSourceError:
        assert True