def then_stdout_is(context): """ Checks for the exact match of the test's stdout. Supports the <REPOSYNC> placeholder on the first line, which will match against the repository synchronization lines (i.e. the "Last metadata expiration check:" line as well as the individual repo download lines) in the test's output. """ expected = context.text.format(context=context).rstrip().split('\n') found = context.cmd_stdout.rstrip().split('\n') if found == [""]: found = [] clean_expected, clean_found = handle_reposync(expected, found) if clean_expected == clean_found: return rs_offset = 0 if len(clean_expected) < len(expected): if len(clean_found) == len(found): rs_offset = 1 # reposync was not in found, prepend a single line to pad for the # <REPOSYNC> line in expected found = [""] + found else: rs_offset = len(found) - len(clean_found) # prepend empty lines to expected to pad for multiple reposync # lines in found expected = [""] * (rs_offset - 1) + expected print_lines_diff(expected, found, num_lines_equal=rs_offset) raise AssertionError("Stdout is not: %s" % context.text)
def keys_do_not_differ(prim, flist, oth): if prim.keys() != flist.keys(): print_lines_diff(prim.keys(), flist.keys()) raise AssertionError( "Primary and Filelists have different package sets.") if prim.keys() != oth.keys(): print_lines_diff(prim.keys(), oth.keys()) raise AssertionError("Primary and Other have different package sets.")
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 check_microdnf_transaction(context, mode): check_context_table(context, ["Action", "Package"]) transaction = parse_microdnf_transaction_table(context.cmd_stdout.splitlines()) table = sorted([(a, p) for a, p in context.table]) if transaction != table: print_lines_diff(table, transaction) raise AssertionError("Transaction table mismatch")
def then_stderr_is(context): expected = context.text.format(context=context).strip().split('\n') found = context.cmd_stderr.strip().split('\n') if expected == found: return print_lines_diff(expected, found) raise AssertionError("Stderr is not: %s" % context.text)
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 step_impl(context): check_context_table(context, ["Package", "Reason"]) cmd = context.dnf.get_cmd(context) + [ "repoquery --qf '%{name}-%{evr}.%{arch},%{reason}' --installed" ] run_in_context(context, " ".join(cmd)) expected = [[p, r] for p, r in context.table] found = sorted( [r.split(",") for r in context.cmd_stdout.strip().split('\n')]) if found != expected: print_lines_diff(expected, found) raise AssertionError("Package reasons mismatch")
def check_microdnf_transaction(context, mode): check_context_table(context, ["Action", "Package"]) transaction = parse_microdnf_transaction_table( context.cmd_stdout.splitlines()) table = sorted([(a, p) for a, p in context.table]) updated_table = [] for action, nevra in table: if action in ["upgraded", "downgraded", "reinstalled", "obsoleted"]: action = "replaced" updated_table.append((action, nevra)) updated_table.sort() if transaction != updated_table: print_lines_diff(updated_table, transaction) raise AssertionError("Transaction table mismatch")
def step_impl(context, spec=None): IN = [ 'Command Line', ] ACTIONS = [ 'Install', 'Removed', 'Upgrade', 'Upgraded', 'Reinstall', 'Reinstalled', 'Downgrade', 'Downgraded', 'Obsoleted', 'Reason Change' ] check_context_table(context, ["Key", "Value"]) if spec is None: spec = "" h_info = parsed_history_info(context, spec) expected_actions = [] for key, value in context.table: if key in h_info: if key in IN and value in h_info[key]: continue elif value == h_info[key]: continue else: raise AssertionError( '[history] {0} "{1}" not matched by "{2}".'.format( key, h_info[key], value)) elif key in ACTIONS: expected_actions.append([key, value]) else: raise AssertionError('[history] key "{0}" not found.'.format(key)) found_actions = [] for a in h_info[None]: action = a.split() if action[0:2] == ["Reason", "Change"]: found_actions.append(["Reason Change", action[2]]) else: found_actions.append(action[0:2]) if expected_actions != found_actions: print_lines_diff(expected_actions, found_actions) raise AssertionError("History actions mismatch")
def repodata_do_not_differ(prim1, prim2, flist1, flist2, oth1, oth2): # Compare packages by checksums if prim1.keys() != prim2.keys(): print_lines_diff(prim1.keys(), prim2.keys()) raise AssertionError("Primary repodata have different package sets.") # Compare packages by name if prim1.packages() != prim2.packages(): print_lines_diff(prim1.packages(), prim2.packages()) raise AssertionError( "Primary repodata have different sets of package names.") diff = prim1.diff(prim2) if diff: raise AssertionError("Primary repodata are different.\n" "Difference: %s" % (diff)) diff = flist1.diff(flist2) if diff: raise AssertionError("Filelists repodata are different.\n" "Difference: %s" % (diff)) diff = oth1.diff(oth2) if diff: raise AssertionError("Other repodata are different.\n" "Difference: %s" % (diff))