def step_impl(context, first, second): full_path_first = prepend_installroot(context, first) full_path_second = prepend_installroot(context, second) f1 = find_file_by_glob(full_path_first) f2 = find_file_by_glob(full_path_second) found1 = read_file_contents(f1).strip() found2 = read_file_contents(f2).strip() if found1 == found2: return print_lines_diff(found1.split('\n'), found2.split('\n')) raise AssertionError("File '{}' contents differ from {}.".format(first, second))
def copy_file_to(context, source, destination): source = source.format(context=context) destination = prepend_installroot(context, destination) ensure_directory_exists(os.path.dirname(destination)) # If we dont specify destination with name keep the name of source file if (os.path.isdir(destination)): destination = os.path.join(destination, os.path.basename(source)) copy_file(source, destination)
def file_contents_is(context, filepath): expected = context.text.strip() full_path = prepend_installroot(context, filepath) f = find_file_by_glob(full_path) found = read_file_contents(f).strip() if expected == found: return print_lines_diff(expected.split('\n'), found.split('\n')) raise AssertionError("File '{}' contents is different then expected.".format(filepath))
def then_stdout_matches_line_by_line(context, filepath): """ Checks that each line of given file matches respective line in regular expressions. """ expected = context.text.split('\n') full_path = prepend_installroot(context, filepath) f = find_file_by_glob(full_path) found = read_file_contents(f).split('\n') lines_match_to_regexps_line_by_line(found, expected)
def file_does_not_contain(context, filepath): regexp_lines = context.text.split('\n') full_path = prepend_installroot(context, filepath) ensure_directory_exists(os.path.dirname(full_path)) read_str = read_file_contents(full_path) for line in regexp_lines: if re.search(line, read_str): print("line: " + line + " found") raise AssertionError("File %s contains: \n%s" % (filepath, read_str)) return
def file_has_mode(context, filepath, octal_mode_str): octal_mode = int(octal_mode_str, 8) matched_files = glob.glob(prepend_installroot(context, filepath)) if len(matched_files) < 1: raise AssertionError("No files matching: {0}".format(filepath)) if len(matched_files) > 1: raise AssertionError("Multiple files matching: {0} found:\n{1}" .format(filepath, '\n'.join(matched_files))) octal_file_mode = os.stat(matched_files[0]).st_mode & 0o777 assert oct(octal_mode) == oct(octal_file_mode), \ "File \"{}\" has mode \"{}\"".format(matched_files[0], oct(octal_file_mode))
def file_exists(context, filepath): full_path = prepend_installroot(context, filepath) find_file_by_glob(full_path)
def step_delete_file_with_globs(context, filepath): for path in glob.glob(prepend_installroot(context, filepath)): delete_file(path)
def step_delete_directory(context, dirpath): full_path = prepend_installroot(context, dirpath) delete_directory(full_path)
def step_impl(context, dst, src): dst = prepend_installroot(context, dst) src = prepend_installroot(context, src) ensure_directory_exists(os.path.dirname(dst)) os.symlink(src, dst)
def step_delete_file(context, filepath): full_path = prepend_installroot(context, filepath) delete_file(full_path)
def step_impl(context, dirpath): full_path = prepend_installroot(context, dirpath) ensure_directory_exists(full_path)
def step_impl(context, filepath): full_path = prepend_installroot(context, filepath) ensure_directory_exists(os.path.dirname(full_path)) create_file_with_contents(full_path, context.text.format(context=context))
def when_I_execute_sqliterepo_c_in_directory(context, arguments, directory): target_path = prepend_installroot(context, directory) run_in_context(context, "sqliterepo_c " + arguments.format(context=context), cwd=target_path, can_fail=True)
def file_does_not_exist(context, filepath): full_path = prepend_installroot(context, filepath) result = glob.glob(full_path) if len(result) > 0: raise AssertionError("Filepath %s matches existing files: \n%s" % (full_path, '\n'.join(result)))
def step_impl(context, source, destination): source = source.format(context=context) destination = prepend_installroot(context, destination) ensure_directory_exists(os.path.dirname(destination)) copy_tree(source, destination)
def create_compressed_file_with(context, compression, filepath): target_path = prepend_installroot(context, filepath) create_compressed_file_with_contents(target_path, compression, context.text)
def create_compressed_file_with(context, compression, filepath): file_path = prepend_installroot(context, filepath) ensure_file_exists(file_path) create_compressed_file_with_contents(file_path, compression, read_file_contents(file_path))
def step_set_up_http_server(context, path): full_path = prepend_installroot(context, path) host, port = start_server_based_on_type(context, full_path, 'http') context.dnf.ports[path] = port
def file_size_less_than(context, filepath, expected_size): full_path = prepend_installroot(context, filepath) size = os.path.getsize(full_path) assert size <= int(expected_size), 'File "{}" has size "{}"'.format( full_path, size)