Example #1
0
def run(venv, options, set_tc_version=True):
    env = virtual_environments.get_clean_system_environment()

    if set_tc_version:
        env['TEAMCITY_VERSION'] = "0.0.0"

    flake8_dir = os.path.join(os.getcwd(), "tests", "guinea-pigs", "flake8")

    command = os.path.join(
        os.getcwd(), venv.bin, 'flake8' +
        virtual_environments.get_exe_suffix()) + " " + options + " ."

    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            cwd=flake8_dir,
                            shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "$"))

    return output
def run(venv, file, clazz=None, test=None, options=""):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    if clazz:
        clazz_arg = ":" + clazz
    else:
        clazz_arg = ""

    if test:
        test_arg = "." + test
    else:
        test_arg = ""

    command = os.path.join(venv.bin, 'nosetests') + \
        " -v " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'nose', file) + clazz_arg + test_arg
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    return output
def test_issue_98(venv):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    # Start the process and wait for its output
    command = os.path.join(venv.bin, 'python') + " " + os.path.join(
        'tests', 'guinea-pigs', 'nose', 'issue_98', 'custom_test_loader.py')
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    test_name = 'simple_tests.SimpleTests.test_two'
    assert_service_messages(output, [
        ServiceMessage('testStarted', {
            'name': test_name,
            'flowId': test_name
        }),
        ServiceMessage('testIgnored', {
            'name': test_name,
            'message': 'Skipped: Skipping',
            'flowId': test_name
        }),
        ServiceMessage('testFinished', {
            'name': test_name,
            'flowId': test_name
        }),
    ])
Example #4
0
def run_command(command,
                env=None,
                print_output=True,
                set_tc_version=True,
                cwd=None):
    encoding = "UTF-8"  # Force UTF for remote process and parse its output in same encoding

    if env is not None:
        env_copy = dict(env)
    else:
        env_copy = virtual_environments.get_clean_system_environment()
    env_copy.update({'PYTHONIOENCODING': encoding})
    if set_tc_version:
        env_copy['TEAMCITY_VERSION'] = "0.0.0"
    elif 'TEAMCITY_VERSION' in env_copy:  # There could be this value in env when tests launched via PyCharm
        del env_copy['TEAMCITY_VERSION']

    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            shell=True,
                            env=env_copy,
                            cwd=cwd or get_teamcity_messages_root())
    output = "".join([x.decode(encoding) for x in proc.stdout.readlines()])
    proc.wait()
    if print_output:
        print("OUTPUT:" + output.replace("#", "*"))
    return output
def run(venv, file_name, test=None, options='', set_tc_version=True):
    env = virtual_environments.get_clean_system_environment()

    if set_tc_version:
        env['TEAMCITY_VERSION'] = "0.0.0"

    if test is not None:
        test_suffix = "::" + test
    else:
        test_suffix = ""

    command = os.path.join(venv.bin, 'py.test') + " " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'pytest', file_name) + test_suffix
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True,
                            cwd=get_teamcity_messages_root())
    output = "".join(
        [x.decode(get_output_encoding()) for x in proc.stdout.readlines()])
    print("OUTPUT: " + output.replace("#", "*"))
    proc.wait()

    return output
def run(venv, file_name, test=None, options="", set_tc_version=True):
    env = virtual_environments.get_clean_system_environment()

    if set_tc_version:
        env["TEAMCITY_VERSION"] = "0.0.0"

    if test is not None:
        test_suffix = "::" + test
    else:
        test_suffix = ""

    command = (
        os.path.join(venv.bin, "py.test")
        + " "
        + options
        + " "
        + os.path.join("tests", "guinea-pigs", "pytest", file_name)
        + test_suffix
    )
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    print("OUTPUT: " + output.replace("#", "*"))
    proc.wait()

    return output
def run(venv, file, clazz=None, test=None, options=""):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    if clazz:
        clazz_arg = ":" + clazz
    else:
        clazz_arg = ""

    if test:
        test_arg = "." + test
    else:
        test_arg = ""

    command = os.path.join(venv.bin, 'nosetests') + \
        " -v " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'nose', file) + clazz_arg + test_arg
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True,
                            cwd=get_teamcity_messages_root())
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    return output
Example #8
0
def test_diff_repr(venv):
    if "pytest==2.7" in venv.packages:
        pytest.skip("Diff is broken for ancient pytest")

    env = virtual_environments.get_clean_system_environment()
    env.update({'_JB_REPR_DIFF': '1'})
    output = run(venv, "../diff_assert_repr.py", env=env)
    package_name = "tests.guinea-pigs.diff_assert_repr"
    assert_service_messages(output, [
        ServiceMessage('testCount', {'count': "2"}),
        ServiceMessage('testStarted', {'name': package_name + ".test_test"}),
        ServiceMessage(
            'testFailed', {
                'name': package_name + ".test_test",
                "actual": "123",
                "expected": "|'123|'"
            }),
        ServiceMessage('testFinished', {'name': package_name + ".test_test"}),
        ServiceMessage('testStarted', {'name': package_name + ".test_test_2"}),
        ServiceMessage(
            'testFailed', {
                'name': package_name + ".test_test_2",
                "actual": "|[|]",
                "expected": "|'|[|]|'"
            }),
        ServiceMessage('testFinished',
                       {'name': package_name + ".test_test_2"}),
    ])
def test_twisted_trial(venv):
    packages = list(*venv.packages)
    packages.append("twisted")
    if os.name == 'nt':
        if sys.version_info < (2, 7):
            pytest.skip("pypiwin32 is available since Python 2.7")
        elif sys.version_info[:2] == (3, 4):
            packages.append("pypiwin32==219")
        else:
            packages.append("pypiwin32")
    venv_with_twisted = virtual_environments.prepare_virtualenv(packages)

    env = virtual_environments.get_clean_system_environment()
    env['PYTHONPATH'] = os.path.join(os.getcwd(), "tests", "guinea-pigs", "unittest")

    # Start the process and wait for its output
    trial_file = os.path.join(venv_with_twisted.bin, 'trial')
    trial_exe_file = os.path.join(venv_with_twisted.bin, 'trial.exe')
    trial_py_file = os.path.join(venv_with_twisted.bin, 'trial.py')

    if os.path.exists(trial_file):
        command = trial_file
    elif os.path.exists(trial_py_file):
        command = os.path.join(venv_with_twisted.bin, 'python') + " " + trial_py_file
    elif os.path.exists(trial_exe_file):
        command = trial_exe_file
    else:
        raise Exception("twisted trial is not found at " + trial_py_file + " or " + trial_file + " or " + trial_exe_file)

    command += " --reporter=teamcity twisted_trial"
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    test1 = "twisted_trial.test_case.CalculationTestCase.test_fail (some desc)"
    test2 = "twisted_trial.test_case.CalculationTestCase.test_ok"
    test3 = "twisted_trial.test_exception.TestFailure.testBadCode"

    ms = assert_service_messages(
        output,
        [
            ServiceMessage('testStarted', {'name': test1}),
            ServiceMessage('testFailed', {'name': test1}),
            ServiceMessage('testFinished', {'name': test1}),
            ServiceMessage('testStarted', {'name': test2}),
            ServiceMessage('testFinished', {'name': test2}),
            ServiceMessage('testStarted', {'name': test3}),
            ServiceMessage('testFailed', {'name': test3}),
            ServiceMessage('testFailed', {'name': test3}),
            ServiceMessage('testFinished', {'name': test3}),
        ])
    failed_ms = match(ms, ServiceMessage('testFailed', {'name': test1}))
    assert failed_ms.params['details'].index("5 != 4") > 0
def test_twisted_trial(venv):
    packages = list(*venv.packages)
    packages.append("twisted==15.2.1")
    if os.name == 'nt':
        if sys.version_info < (2, 7):
            pytest.skip("pypiwin32 is available since Python 2.7")
        packages.append("pypiwin32==219")
    venv_with_twisted = virtual_environments.prepare_virtualenv(packages)

    env = virtual_environments.get_clean_system_environment()
    env['PYTHONPATH'] = os.path.join(os.getcwd(), "tests", "guinea-pigs",
                                     "unittest")

    # Start the process and wait for its output
    trial_file = os.path.join(venv_with_twisted.bin, 'trial')
    trial_exe_file = os.path.join(venv_with_twisted.bin, 'trial.exe')
    trial_py_file = os.path.join(venv_with_twisted.bin, 'trial.py')

    if os.path.exists(trial_file):
        command = trial_file
    elif os.path.exists(trial_py_file):
        command = os.path.join(venv_with_twisted.bin,
                               'python') + " " + trial_py_file
    elif os.path.exists(trial_exe_file):
        command = trial_exe_file
    else:
        raise Exception("twisted trial is not found at " + trial_py_file +
                        " or " + trial_file + " or " + trial_exe_file)

    command += " --reporter=teamcity twisted_trial"
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    test1 = "twisted_trial.test_case.CalculationTestCase.test_fail (some desc)"
    test2 = "twisted_trial.test_case.CalculationTestCase.test_ok"

    ms = assert_service_messages(output, [
        ServiceMessage('testStarted', {'name': test1}),
        ServiceMessage('testFailed', {'name': test1}),
        ServiceMessage('testFinished', {'name': test1}),
        ServiceMessage('testStarted', {'name': test2}),
        ServiceMessage('testFinished', {'name': test2}),
    ])
    failed_ms = match(ms, ServiceMessage('testFailed', {'name': test1}))
    assert failed_ms.params['details'].index("5 != 4") > 0
def run(venv):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    command = os.path.join(os.getcwd(), venv.bin, 'python') + " manage.py test"
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
                            cwd=os.path.join(os.getcwd(), "tests", "guinea-pigs", "djangotest"), shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output)

    return output
def run_directly(venv, file):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    # Start the process and wait for its output
    command = os.path.join(venv.bin, 'python') + " " + os.path.join('tests', 'guinea-pigs', 'unittest', file)
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    return output
def run(venv):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    command = os.path.join(os.getcwd(), venv.bin, 'python') + " manage.py test"
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
                            cwd=os.path.join(os.getcwd(), "tests", "guinea-pigs", "djangotest"), shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output)

    return output
def run(venv, file, test=None, options='', set_tc_version=True):
    env = virtual_environments.get_clean_system_environment()

    if set_tc_version:
        env['TEAMCITY_VERSION'] = "0.0.0"

    test_suffix = ("::" + test) if test is not None else ""
    command = os.path.join(venv.bin, 'py.test') + " " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'pytest', file) + test_suffix
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    return output
Example #15
0
def run(venv, options):
    env = virtual_environments.get_clean_system_environment()

    command = os.path.join(
        os.getcwd(), venv.bin,
        'flake8' + virtual_environments.get_exe_suffix()) + " " + options + " " + os.path.join("tests", "guinea-pigs", "flake8")

    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
                            cwd=os.path.join(os.getcwd()), shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "$"))

    return output
Example #16
0
def run_directly(venv, file):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    # Start the process and wait for its output
    command = os.path.join(venv.bin, 'python') + " " + os.path.join(
        'tests', 'guinea-pigs', 'unittest', file)
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    return output
Example #17
0
def run_command(command, env=None, print_output=True, set_tc_version=True, cwd=None):
    encoding = "UTF-8"  # Force UTF for remote process and parse its output in same encoding

    if env is not None:
        env_copy = dict(env)
    else:
        env_copy = virtual_environments.get_clean_system_environment()
    env_copy.update({'PYTHONIOENCODING': encoding})
    if set_tc_version:
        env_copy['TEAMCITY_VERSION'] = "0.0.0"

    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True,
                            env=env_copy, cwd=cwd or get_teamcity_messages_root())
    output = "".join([x.decode(encoding) for x in proc.stdout.readlines()])
    proc.wait()
    if print_output:
        print("OUTPUT:" + output.replace("#", "*"))
    return output
Example #18
0
def run(venv, file, test=None, options='', set_tc_version=True):
    env = virtual_environments.get_clean_system_environment()

    if set_tc_version:
        env['TEAMCITY_VERSION'] = "0.0.0"

    test_suffix = ("::" + test) if test is not None else ""
    command = os.path.join(venv.bin, 'py.test') + " " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'pytest', file) + test_suffix
    print("RUN: " + command)
    proc = subprocess.Popen(command,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            env=env,
                            shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    return output
Example #19
0
def test_issue_98(venv):
    env = virtual_environments.get_clean_system_environment()
    env['TEAMCITY_VERSION'] = "0.0.0"

    # Start the process and wait for its output
    command = os.path.join(venv.bin, 'python') + " " + os.path.join('tests', 'guinea-pigs', 'nose', 'issue_98', 'custom_test_loader.py')
    print("RUN: " + command)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True)
    output = "".join([x.decode() for x in proc.stdout.readlines()])
    proc.wait()

    print("OUTPUT:" + output.replace("#", "*"))

    test_name = 'simple_tests.SimpleTests.test_two'
    assert_service_messages(
        output,
        [
            ServiceMessage('testStarted', {'name': test_name, 'flowId': test_name}),
            ServiceMessage('testIgnored', {'name': test_name, 'message': 'Skipped: Skipping', 'flowId': test_name}),
            ServiceMessage('testFinished', {'name': test_name, 'flowId': test_name}),
        ])