def run_tests(tests): any_failures = False for test_spec in tests: test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.')) # TODO(aneeshusa): switch back to scandir on Python 3.5+ tests = sorted(path for path in os.listdir(test_dir) if is_python_script(os.path.join(test_dir, path))) for test in tests: test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3]) test_mod = importlib.import_module(test_mod_name) if not hasattr(test_mod, 'run'): # Not a test script continue try: result = test_mod.run() except Exception as e: message = 'Test \'{}\' raised an exception:'.format(test) result = Failure(message, str(e)) if result.is_success(): print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message)) else: any_failures = True print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message)) for line in result.output.splitlines(): print(' {}'.format(line)) return 1 if any_failures else 0
def run_tests(tests): any_failures = False for test_spec in tests: test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.')) python_scripts = filter(is_python_script, os.scandir(test_dir)) tests = sorted([entry.name for entry in python_scripts]) for test in tests: test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3]) test_mod = importlib.import_module(test_mod_name) if not hasattr(test_mod, 'run'): # Not a test script continue try: result = test_mod.run() except Exception as e: message = 'Test \'{}\' raised an exception:'.format(test) result = Failure(message, str(e)) if result.is_success(): print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message)) else: any_failures = True print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message)) for line in result.output.splitlines(): print(' {}'.format(line)) return 1 if any_failures else 0
def run_tests(tests): any_failures = False for test_spec in tests: test_dir = os.path.join(project_path(), 'tests', *test_spec.split('.')) # TODO(aneeshusa): switch back to scandir on Python 3.5+ tests = sorted( path for path in os.listdir(test_dir) if is_python_script(os.path.join(test_dir, path)) ) for test in tests: test_mod_name = 'tests.{}.{}'.format(test_spec, test[:-3]) test_mod = importlib.import_module(test_mod_name) if not hasattr(test_mod, 'run'): # Not a test script continue try: result = test_mod.run() except Exception as e: message = 'Test \'{}\' raised an exception:'.format(test) result = Failure(message, str(e)) if result.is_success(): print('[ {} ] {}'.format(color(GREEN, 'PASS'), result.message)) else: any_failures = True print('[ {} ] {}'.format(color(RED, 'FAIL'), result.message)) for line in result.output.splitlines(): print(' {}'.format(line)) return 1 if any_failures else 0
def run(): paths = ["test.py", "tests"] paths = [os.path.join(project_path(), path) for path in paths] command = ["flake8"] + paths ret = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) if ret.returncode == 0: return Success("Tests passed flake8 lint") else: return Failure("Tests failed flake8 lint:", ret.stdout)
def run(): paths = ['test.py', 'tests'] paths = [os.path.join(project_path(), path) for path in paths] command = ['flake8'] + paths ret = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) if ret.returncode == 0: return Success("Tests passed flake8 lint") else: return Failure("Tests failed flake8 lint:", ret.stdout)
def run(): paths = ['test.py', 'tests'] paths = [os.path.join(project_path(), path) for path in paths] command = ['flake8'] + paths proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) stdout, _ = proc.communicate() if proc.returncode != 0: return Failure("Tests failed flake8 lint:", stdout) return Success("Tests passed flake8 lint")
def run(): CONF_DIR = os.path.join(project_path(), 'buildbot', 'master', 'files', 'config') # Have to specify master.cfg separately because it is not a .py file command = ['flake8', CONF_DIR, os.path.join(CONF_DIR, 'master.cfg')] ret = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) if ret.returncode == 0: return Success("Buildbot master config passed linting") else: return Failure("Buildbot master config lint check failed:", ret.stdout)
def run(): CONF_DIR = os.path.join(project_path(), 'buildbot', 'master', 'files', 'config') # Have to specify master.cfg separately because it is not a .py file command = ['flake8', CONF_DIR, "/home/servo/buildbot/master/master.cfg"] proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) stdout, _ = proc.communicate() if proc.returncode != 0: return Failure("Buildbot master config lint check failed:", stdout) return Success("Buildbot master config passed linting")
def run(): paths = ['test.py', 'tests'] paths = [os.path.join(project_path(), path) for path in paths] command = ['flake8'] + paths proc = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True ) stdout, _ = proc.communicate() if proc.returncode != 0: return Failure("Tests failed flake8 lint:", stdout) return Success("Tests passed flake8 lint")
def run(): CONF_DIR = os.path.join( project_path(), 'buildbot', 'master', 'files', 'config' ) # Have to specify master.cfg separately because it is not a .py file command = ['flake8', CONF_DIR, "/home/servo/buildbot/master/master.cfg"] proc = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True ) stdout, _ = proc.communicate() if proc.returncode != 0: return Failure("Buildbot master config lint check failed:", stdout) return Success("Buildbot master config passed linting")
def run(): with open(os.path.join( project_path(), 'servo-build-dependencies', 'map.jinja' )) as jinja_file: template = Template(jinja_file.read()) sdk_vars = template.module.android['sdk'] failures = [] checks = {} for version, sdk in sdk_vars.items(): if version == 'current': if sdk not in sdk_vars: failures.append( 'The current SDK is not pointed at any installed SDK' ) continue checks[os.path.join(BASE_DIR, 'current')] = { 'type': 'link', 'target': os.path.join(BASE_DIR, sdk) } sdk = sdk_vars[sdk] for path_template, spec in CHECKS.items(): path = path_template.format(os.path.join(BASE_DIR, version), **sdk) checks[path] = spec for path, spec in sorted(checks.items(), key=lambda kv: kv[0]): exists = os.path.lexists(path) if spec['type'] == 'absent': if exists: failures.append('{} should not exist'.format(path)) continue if not exists: failures.append('{} does not exist but should'.format(path)) continue info = os.stat(path).st_mode if spec['type'] == 'directory': if not (os.path.isdir(path) and not os.path.islink(path)): failures.append('{} should be a directory'.format(path)) if not has_perms(0o700, info): failures.append( '{} should have at least perms 700'.format(path) ) elif spec['type'] == 'file': if not (os.path.isfile(path) and not os.path.islink(path)): failures.append('{} should be a file'.format(path)) perms = 0o700 if spec['executable'] else 0o600 if not has_perms(perms, info): failures.append( '{} should have at least perms {:o}'.format(path, perms) ) elif spec['type'] == 'link': if not os.path.islink(path): failures.append('{} should be a symlink'.format(path)) if not os.path.realpath(path) == spec['target']: failures.append( '{} should be a link to {}'.format(path, spec['target']) ) else: failures.append('Unknown spec for path {}'.format(path)) if failures: output = '\n'.join(('- {}'.format(f) for f in failures)) return Failure('Android SDK(s) not installed properly:', output) return Success('Android SDK(s) are properly installed')
def run(): with open( os.path.join(project_path(), 'servo-build-dependencies', 'map.jinja')) as jinja_file: template = Template(jinja_file.read()) sdk_vars = template.module.android['sdk'] failures = [] checks = {} for version, sdk in sdk_vars.items(): if version == 'current': if sdk not in sdk_vars: failures.append( 'The current SDK is not pointed at any installed SDK') continue checks[os.path.join(BASE_DIR, 'current')] = { 'type': 'link', 'target': os.path.join(BASE_DIR, sdk) } sdk = sdk_vars[sdk] for path_template, spec in CHECKS.items(): path = path_template.format(os.path.join(BASE_DIR, version), **sdk) checks[path] = spec for path, spec in sorted(checks.items(), key=lambda kv: kv[0]): exists = os.path.lexists(path) if spec['type'] == 'absent': if exists: failures.append('{} should not exist'.format(path)) continue if not exists: failures.append('{} does not exist but should'.format(path)) continue info = os.stat(path).st_mode if spec['type'] == 'directory': if not (os.path.isdir(path) and not os.path.islink(path)): failures.append('{} should be a directory'.format(path)) if not has_perms(0o700, info): failures.append( '{} should have at least perms 700'.format(path)) elif spec['type'] == 'file': if not (os.path.isfile(path) and not os.path.islink(path)): failures.append('{} should be a file'.format(path)) perms = 0o700 if spec['executable'] else 0o600 if not has_perms(perms, info): failures.append('{} should have at least perms {:o}'.format( path, perms)) elif spec['type'] == 'link': if not os.path.islink(path): failures.append('{} should be a symlink'.format(path)) if not os.path.realpath(path) == spec['target']: failures.append('{} should be a link to {}'.format( path, spec['target'])) else: failures.append('Unknown spec for path {}'.format(path)) if failures: output = '\n'.join(('- {}'.format(f) for f in failures)) return Failure('Android SDK(s) not installed properly:', output) return Success('Android SDK(s) are properly installed')