def test_issue_98(venv): # Start the process and wait for its output custom_test_loader = os.path.join(get_teamcity_messages_root(), 'tests', 'guinea-pigs', 'nose', 'issue_98', 'custom_test_loader.py') command = os.path.join(venv.bin, 'python') + " " + custom_test_loader output = run_command(command) 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 }), ], actual_messages_predicate=lambda ms: ms.name != "testCount")
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
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, options="", arguments="", lang_dir="eng"): cwd = os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs", "behave", lang_dir) behave = " ".join([ os.path.join(venv.bin, "python"), os.path.join(os.path.dirname(cwd), "_behave_runner.py"), options, arguments ]) return run_command(behave, cwd=cwd)
def test_smoke(venv): output = run(venv, os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs", "djangotest1")) test_name = "test_smoke.SmokeTestCase.test_xxx (XXX identity)" assert_service_messages( output, [ ServiceMessage('testCount', {'count': "1"}), ServiceMessage('testStarted', {'name': test_name}), ServiceMessage('testFinished', {'name': test_name}), ])
def test_smoke(venv): output = run(venv, os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs", "djangotest2")) test_name = "test_smoke.SmokeTestCase.test_xxx (XXX identity)" assert_service_messages( output, [ ServiceMessage('testCount', {'count': "1"}), ServiceMessage('testStarted', {'name': test_name}), ServiceMessage('testFinished', {'name': test_name}), ])
def test_issue_98(venv): # Start the process and wait for its output custom_test_loader = os.path.join(get_teamcity_messages_root(), 'tests', 'guinea-pigs', 'nose', 'issue_98', 'custom_test_loader.py') command = os.path.join(venv.bin, 'python') + " " + custom_test_loader output = run_command(command) 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}), ], actual_messages_predicate=lambda ms: ms.name != "testCount" )
def prepare_virtualenv(packages=()): """ Prepares a virtual environment. :rtype : VirtualEnvDescription """ vroot = get_vroot() env_key = get_env_key(packages) vdir = os.path.join(vroot, env_key) vbin = os.path.join(vdir, ('bin', 'Scripts')[_windows]) vpython = os.path.join(vbin, 'python' + get_exe_suffix()) vpip = os.path.join(vbin, 'pip' + get_exe_suffix()) vpip_install = [vpip, "install"] if (2, 5) <= sys.version_info < (2, 6): vpip_install.append("--insecure") venv_description = VirtualEnvDescription(home_dir=vdir, bin_dir=vbin, python=vpython, pip=vpip, packages=packages) print("Will install now") print(str(venv_description)) env = get_clean_system_environment() env['PIP_DOWNLOAD_CACHE'] = os.path.abspath(os.path.join(vroot, "pip-download-cache")) # Cache environment done_flag_file = os.path.join(vdir, "done") if not os.path.exists(done_flag_file): if os.path.exists(vdir): shutil.rmtree(vdir) virtualenv.create_environment(vdir) # Update for newly created environment if sys.version_info >= (2, 7): _call([vpython, "-m", "pip", "install", "--upgrade", "pip", "setuptools"], env=env, cwd=get_teamcity_messages_root()) for package_spec in packages: _call(vpip_install + [package_spec], env=env) open(done_flag_file, 'a').close() # Update for env. that already exists: does not take long, but may save old envs. if sys.version_info >= (2, 7): _call([vpython, "-m", "pip", "install", "--upgrade", "pip", "setuptools"], env=env, cwd=get_teamcity_messages_root()) _call([vpython, "setup.py", "install"], env=env, cwd=get_teamcity_messages_root()) return venv_description
def prepare_virtualenv(packages=()): """ Prepares a virtual environment. :rtype : VirtualEnvDescription """ vroot = get_vroot() env_key = get_env_key(packages) vdir = os.path.join(vroot, env_key) vbin = os.path.join(vdir, ('bin', 'Scripts')[_windows]) vpython = os.path.join(vbin, 'python' + get_exe_suffix()) vpip = os.path.join(vbin, 'pip' + get_exe_suffix()) vpip_install = [vpip, "install"] if (2, 5) <= sys.version_info < (2, 6): vpip_install.append("--insecure") venv_description = VirtualEnvDescription(home_dir=vdir, bin_dir=vbin, python=vpython, pip=vpip, packages=packages) env = get_clean_system_environment() env['PIP_DOWNLOAD_CACHE'] = os.path.abspath(os.path.join(vroot, "pip-download-cache")) # Cache environment done_flag_file = os.path.join(vdir, "done") if not os.path.exists(done_flag_file): if os.path.exists(vdir): shutil.rmtree(vdir) virtualenv.create_environment(vdir) for package_spec in packages: rc = subprocess.call(vpip_install + [package_spec], env=env) if rc != 0: raise Exception("Unable to install " + package_spec + " to " + vroot) open(done_flag_file, 'a').close() rc = subprocess.call([vpython, "setup.py", "install"], env=env, cwd=get_teamcity_messages_root()) if rc != 0: raise Exception("Unable to setup.py install to " + vroot) return venv_description
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, cwd=get_teamcity_messages_root()) output = "".join([x.decode() for x in proc.stdout.readlines()]) proc.wait() print("OUTPUT:" + output.replace("#", "*")) return output
def make_ini(content): path = os.path.join(get_teamcity_messages_root(), 'pytest.ini') with open(path, 'w+') as f: f.write(content) yield os.remove(path)
def run(venv, options="", arguments="", lang_dir="eng"): cwd = os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs", "behave", lang_dir) behave = " ".join([os.path.join(venv.bin, "python"), os.path.join(os.path.dirname(cwd), "_behave_runner.py"), options, arguments]) return run_command(behave, cwd=cwd)