Пример #1
0
def test_error_no_repo(submit_environment, stdout_checker):
    settings = copy.deepcopy(submit_environment.settings)
    if settings.Vcs.type == "git":
        settings.ProjectDirectory.project_root = "non_existing_repo"
        __main__.run(settings)
        stdout_checker.assert_has_calls_with_param("No such directory")
    else:
        settings.PerforceSubmitVcs.client = "non_existing_client"
        __main__.run(settings)
        stdout_checker.assert_has_calls_with_param("Workspace 'non_existing_client' doesn't exist!")
Пример #2
0
def test_unicode(vcs, test_type, perforce_workspace, git_client, unicode_dir):
    if vcs == "git":
        # change git client root dir to unicode path
        work_dir = unicode_dir.mkdir("client")
        git_client.repo = git.Repo.clone_from(git_client.server.url, work_dir)
        git_client.root_directory = work_dir

        env = git_utils.GitEnvironment(git_client,
                                       unicode_dir,
                                       test_type=test_type)
    elif vcs == "p4":
        # change workspace root dir to unicode path
        root = unicode_dir.mkdir("workspace")
        client = perforce_workspace.p4.fetch_client(
            perforce_workspace.client_name)
        client["Root"] = str(root)
        perforce_workspace.root_directory = root
        perforce_workspace.p4.save_client(client)
        perforce_workspace.p4.run_sync("-f", "//depot/...")

        env = perforce_utils.P4Environment(perforce_workspace,
                                           unicode_dir,
                                           test_type=test_type)
    else:
        assert False, "Unsupported vcs type"

    if test_type == "submit":
        temp_file = env.vcs_cooking_dir.join(
            utils.randomize_name("new_file") + ".txt")
        temp_file.write("This is a new file" + "\n")
        env.settings.Submit.reconcile_list = [str(temp_file)]

    res = __main__.run(env.settings)
    assert res == 0
Пример #3
0
def test_code_report_extended_arg_search(tmpdir, stdout_checker):
    env = utils.TestEnvironment(tmpdir, "main")
    env.settings.Vcs.type = "none"
    env.settings.LocalMainVcs.source_dir = str(tmpdir)

    tmpdir.join("source_file.py").write(source_code + '\n')

    config = """
from universum.configuration_support import Variations

configs = Variations([dict(name="Run static pylint", code_report=True, artifacts="${{CODE_REPORT_FILE}}", command=[
    'bash', '-c',
    'cd \"{0}\" && python3.7 -m universum.analyzers.pylint --result-file=\"${{CODE_REPORT_FILE}}\" --python-version=3 \
--files {1}/source_file.py'
])])"""

    env.configs_file.write(config.format(os.getcwd(), str(tmpdir)))

    res = __main__.run(env.settings)

    assert res == 0
    stdout_checker.assert_has_calls_with_param(log_fail, is_regexp=True)
    assert os.path.exists(
        os.path.join(env.settings.ArtifactCollector.artifact_dir,
                     "Run_static_pylint.json"))
def test_p4_forbidden_local_revert(perforce_environment, stdout_checker):
    p4 = perforce_environment.p4
    p4_file = perforce_environment.repo_file

    config = """
from universum.configuration_support import Variations

configs = Variations([dict(name="Restrict changes", command=["chmod", "-R", "555", "."]),
                      dict(name="Check", command=["ls", "-la"])])
"""
    p4.run_edit(perforce_environment.depot)
    p4_file.write(config)
    change = p4.fetch_change()
    change["Description"] = "CL for shelving"
    shelve_cl = p4.save_change(change)[0].split()[1]
    p4.run_shelve("-fc", shelve_cl)

    settings = perforce_environment.settings
    settings.PerforceMainVcs.shelve_cls = [shelve_cl]
    settings.Launcher.config_path = p4_file.basename

    result = __main__.run(settings)
    # Clean up the directory at once to make sure it doesn't remain non-writable even if some assert fails
    perforce_environment.temp_dir.chmod(0o0777, rec=1)
    perforce_environment.temp_dir.remove(rec=1)

    assert result == 0

    stdout_checker.assert_has_calls_with_param("[Errno 13] Permission denied")

    # make sure there are no pending CLs in the workspace
    assert not p4.run_changes("-c", perforce_environment.client_name, "-s",
                              "pending")
    # make sure there are no pending changes in default CL
    assert not p4.run_opened("-C", perforce_environment.client_name)
Пример #5
0
def test_clean_sources_exceptions(tmpdir):
    env = utils.TestEnvironment(tmpdir, "main")
    env.settings.Vcs.type = "none"
    env.settings.LocalMainVcs.source_dir = str(tmpdir / 'nonexisting_dir')

    # Check failure with non-existing temp dir
    __main__.run(env.settings)
    # the log output is automatically checked by the 'detect_fails' fixture

    # Check failure with temp dir deleted by the launched project
    env.settings.LocalMainVcs.source_dir = str(tmpdir)
    env.configs_file.write("""
from universum.configuration_support import Variations

configs = Variations([dict(name="Test configuration", command=["bash", "-c", "rm -rf {}"])])
""".format(env.settings.ProjectDirectory.project_root))

    __main__.run(env.settings)
Пример #6
0
    def submit_path_list(self, path_list, **kwargs):
        settings = copy.deepcopy(self.submit_settings)
        setattr(settings.Submit, "reconcile_list", path_list)

        if kwargs:
            for key in kwargs:
                setattr(settings.Submit, key, kwargs[key])

        return __main__.run(settings)
Пример #7
0
def test_unicode_main_local_vcs(unicode_dir):
    work_dir = unicode_dir.mkdir("local_sources")
    work_dir.join("source_file").write("Source file contents")

    env = utils.TestEnvironment(unicode_dir, "main")
    env.settings.Vcs.type = "none"
    env.settings.LocalMainVcs.source_dir = str(work_dir)

    res = __main__.run(env.settings)
    assert res == 0
Пример #8
0
def test_p4_multiple_spaces_in_mappings(perforce_workspace, tmpdir):
    environment = utils.TestEnvironment(tmpdir, "main")
    environment.settings.Vcs.type = "p4"
    environment.settings.PerforceVcs.port = perforce_workspace.p4.port
    environment.settings.PerforceVcs.user = perforce_workspace.p4.user
    environment.settings.PerforceVcs.password = perforce_workspace.p4.password
    environment.settings.PerforceMainVcs.client = "regression_disposable_workspace"
    environment.settings.PerforceMainVcs.force_clean = True
    environment.settings.PerforceWithMappings.mappings = [
        f"{perforce_workspace.depot}   /..."
    ]
    assert not __main__.run(environment.settings)
Пример #9
0
def test_p4_error_forbidden_branch(p4_submit_environment, branch):
    protected_dir = p4_submit_environment.vcs_cooking_dir.mkdir(branch)
    file_to_add = protected_dir.join(utils.randomize_name("new_file") + ".txt")
    text = "This is a new line in the file"
    file_to_add.write(text + "\n")

    settings = copy.deepcopy(p4_submit_environment.settings)
    setattr(settings.Submit, "reconcile_list", [str(file_to_add)])

    assert __main__.run(settings)

    p4 = p4_submit_environment.p4
    # make sure submitter didn't leave any pending CLs in the workspace
    assert not p4.run_changes("-c", p4_submit_environment.client_name, "-s", "pending")
    # make sure submitter didn't leave any pending changes in default CL
    assert not p4.run_opened("-C", p4_submit_environment.client_name)
Пример #10
0
def test_p4_success_files_in_default(p4_submit_environment):
    # This file should not be submitted, it should remain unchanged in default CL
    p4 = p4_submit_environment.p4
    p4_file = p4_submit_environment.repo_file
    p4.run_edit(str(p4_file))
    text = "This text should be in file"
    p4_file.write(text + "\n")

    # This file should be successfully submitted
    file_name = utils.randomize_name("new_file") + ".txt"
    new_file = p4_submit_environment.vcs_cooking_dir.join(file_name)
    new_file.write("This is a new file" + "\n")

    settings = copy.deepcopy(p4_submit_environment.settings)
    setattr(settings.Submit, "reconcile_list", [str(new_file)])

    assert not __main__.run(settings)
    assert text in p4_file.read()
Пример #11
0
def test_error_one_change(poll_parameters, poll_environment):
    parameters = poll_parameters(poll_environment)

    # initialize working directory with initial data
    parameters.http_check.assert_success_and_collect(__main__.run,
                                                     parameters.poll_settings)

    # make change in workspace
    change = parameters.make_a_change()

    # run poll again and fail triggering url because there is no server
    assert __main__.run(parameters.poll_settings) != 0

    parameters.stdout_checker.assert_has_calls_with_param(
        "==> Detected commit " + change)

    # there is no listening server
    parameters.log_exception_checker.assert_has_calls_with_param(
        "[Errno 111] Connection refused")
Пример #12
0
def test_p4_error_files_in_default_and_reverted(p4_submit_environment):
    # This file should not be submitted, it should remain unchanged in default CL
    p4 = p4_submit_environment.p4
    p4_file = p4_submit_environment.repo_file
    p4.run_edit(str(p4_file))
    text_default = "This text should be in file"
    p4_file.write(text_default + "\n")

    # This file must fail submit and remain unchanged while not checked out any more
    protected_dir = p4_submit_environment.vcs_cooking_dir.mkdir("write-protected")
    new_file = protected_dir.join(utils.randomize_name("new_file") + ".txt")
    text_new = "This is a new line in the file"
    new_file.write(text_new + "\n")

    settings = copy.deepcopy(p4_submit_environment.settings)
    setattr(settings.Submit, "reconcile_list", [str(new_file)])

    assert __main__.run(settings)
    assert text_default in p4_file.read()
    assert text_new in new_file.read()
def test_p4_print_exception_before_run(perforce_environment, stdout_checker):
    p4 = perforce_environment.p4
    client = p4.fetch_client(perforce_environment.client_name)
    client[
        "Options"] = "noallwrite noclobber nocompress locked nomodtime normdir"
    p4.save_client(client)

    settings = perforce_environment.settings
    result = __main__.run(settings)

    # Update client at once to make sure it doesn't remain locked even if some assert fails
    client = p4.fetch_client(perforce_environment.client_name)
    client[
        "Options"] = "noallwrite noclobber nocompress unlocked nomodtime normdir"
    p4.save_client(client)

    assert result != 0
    stdout_checker.assert_has_calls_with_param(
        "Errors during command execution( \"p4 client -d {}\" )".format(
            perforce_environment.client_name))
def test_p4_print_exception_in_finalize(perforce_environment, stdout_checker,
                                        capsys):
    p4 = perforce_environment.p4
    client = p4.fetch_client(perforce_environment.client_name)
    client[
        "Options"] = "noallwrite noclobber nocompress locked nomodtime normdir"
    p4.save_client(client)

    settings = perforce_environment.settings
    settings.Main.finalize_only = True
    result = __main__.run(settings)

    # Update client at once to make sure it doesn't remain locked even if some assert fails
    client = p4.fetch_client(perforce_environment.client_name)
    client[
        "Options"] = "noallwrite noclobber nocompress unlocked nomodtime normdir"
    p4.save_client(client)

    assert result != 0
    stdout_checker.assert_has_calls_with_param(
        "Errors during command execution( \"p4 client -d {}\" )".format(
            perforce_environment.client_name))
    assert "CiException: [Errno 2] No such file or directory" in capsys.readouterr(
    ).err
Пример #15
0
def assert_incorrect_parameter(settings, match):
    with pytest.raises(IncorrectParameterError, match=match):
        __main__.run(settings)