def run_tests(self) -> bool: try: self._compose.up() variables = {} if self.inventory is not None: variables = read_source_file(self.inventory) variables['INVENTORY'] = get_filename(self.inventory) variables = try_get_object(fill_template_str( variables, {})) # fill env vars variables['CURRENT_DIR'] = self.path test_files = get_files(self.tests_path) results = [] for file in test_files: self.all_includes = [] try: variables['TEST_NAME'] = file test = self.prepare_test(file, variables) test.run() results.append(True) info('Test ' + file + ' passed.') except Exception as e: warning('Test ' + file + ' failed: ' + str(e)) results.append(False) return all(results) finally: self._compose.down()
def test_find_all_in_dir(self): files = ['d', 'd/test1.yaml', 'd/test2.yaml'] self.__populate_files(files) result = get_files(join(self.test_dir, 'd')) expected = [ join(self.test_dir, f) for f in files if f.endswith('yaml') ] expected.reverse() self.assertEqual(sorted(expected), sorted(result))
def test_find_all_filter_unknown(self): files = [ 'd', 'd/d1', 'd/test1.yaml', 'd/test2.yaml', 'd/d1/test3.yaml' ] self.__populate_files(files) with open(join(self.test_dir, 'd/Readme.md'), 'w') as f: f.write('first_readme') with open(join(self.test_dir, 'd/d1/Readme.md'), 'w') as f: f.write('second_readme') result = get_files(join(self.test_dir, 'd')) expected = [ join(self.test_dir, f) for f in files if f.endswith('yaml') ] expected.reverse() self.assertEqual(sorted(expected), sorted(result))
def read_tests(self, test_path: str) -> List[ParseResult]: """ Parse all tests at path, return pairs of (tests run before the test, test) """ results = [] for test_file in get_files(test_path): try: raw_test = self.read_test(test_file) run_on_include = self.fill_includes_recursive( test_file, raw_test, None) results += [ ParseResult(raw_test, run_on_include=run_on_include) ] except Exception as e: results += [ParseResult(test_file, parse_error=str(e))] return results
def run_tests(self) -> bool: try: self._compose.up() if self.system_vars: debug('Use system variables: ' + str(list(self.system_vars.keys()))) variables = self.system_vars else: variables = {} if self.inventory is not None: inv_vars = read_source_file(self.inventory) inv_vars['INVENTORY'] = get_filename(self.inventory) variables = try_get_object( fill_template_str(inv_vars, variables)) # fill env vars variables['CURRENT_DIR'] = self.path variables[ 'RESOURCES_DIR'] = self.resources or self.path + '/resources' test_files = get_files(self.tests_path) results = [] for file in test_files: self.all_includes = [] try: variables['TEST_NAME'] = file test = self.prepare_test(file, variables) logger.log_storage.test_start(file) test.run() results.append(True) info('Test ' + file + ' passed.') logger.log_storage.test_end(file, True) except Exception as e: warning('Test ' + file + ' failed: ' + str(e)) results.append(False) logger.log_storage.test_end(file, False, str(e)) return all(results) finally: logger.log_storage.write_report(self.path) self._compose.down()
def test_find_one_file(self): self.__populate_files(['test_file.yaml']) file = join(self.test_dir, 'test_file.yaml') result = get_files(file) self.assertEqual([file], result)