Пример #1
0
def test_enforce_sandbox(file_tree, error, tmp_path):
    write_file_tree(file_tree, tmp_path)
    if error is not None:
        with pytest.raises(ValidationError, match=error):
            _enforce_sandbox(tmp_path)
    else:
        _enforce_sandbox(tmp_path)
Пример #2
0
def assert_files_testdir(tmp_path):
    tree = {
        "present_file": "",
        "present_dir": {},
        "sub": {
            "present_file": "",
            "present_dir": {},
            "can_black_stop_collapsing_dicts_that_I_want_to_keep_multiline_please": "",
        },
    }
    write_file_tree(tree, tmp_path)
    return tmp_path
Пример #3
0
def test_vendor_changed(subpath, vendor_before, vendor_changes, expected_change, fake_repo, caplog):
    repo_dir, _ = fake_repo
    repo = git.Repo(repo_dir)

    app_dir = os.path.join(repo_dir, subpath)
    os.makedirs(app_dir, exist_ok=True)

    write_file_tree(vendor_before, app_dir)
    repo.index.add(os.path.join(app_dir, path) for path in vendor_before)
    repo.index.commit("before vendoring")

    write_file_tree(vendor_changes, app_dir, exist_ok=True)

    assert gomod._vendor_changed(repo_dir, app_dir) == bool(expected_change)
    if expected_change:
        assert expected_change.format(subpath=subpath) in caplog.text

    # The _vendor_changed function should reset the `git add` => added files should not be tracked
    assert not repo.git.diff("--diff-filter", "A")
Пример #4
0
def test_merge_bundle_dirs(mock_merge_files, tree_1, tree_2, result_tree, merge_file_executions):
    with tempDir() as dir_1, tempDir() as dir_2, tempDir() as dir_3:
        write_file_tree(tree_1, dir_1)
        write_file_tree(tree_2, dir_2)
        write_file_tree(result_tree, dir_3)
        _merge_bundle_dirs(dir_1, dir_2)
        assert_directories_equal(dir_2, dir_3)
    assert mock_merge_files.call_count == merge_file_executions
Пример #5
0
def test_merge_files(file_1_content, file_2_content, result_file_content):
    with tempDir() as dir_1, tempDir() as dir_2, tempDir() as dir_3:
        write_file_tree({"list": file_1_content}, dir_1)
        write_file_tree({"list": file_2_content}, dir_2)
        write_file_tree({"list": result_file_content}, dir_3)
        _merge_files("{}/list".format(dir_1), "{}/list".format(dir_2))
        with open("{}/list".format(dir_2), "r") as f:
            print(f.read())
        with open("{}/list".format(dir_3), "r") as f:
            print(f.read())
        assert_directories_equal(dir_2, dir_3)