Esempio n. 1
0
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))
Esempio n. 2
0
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)
Esempio n. 3
0
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))
Esempio n. 4
0
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)
Esempio n. 5
0
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
Esempio n. 6
0
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))
Esempio n. 7
0
def file_exists(context, filepath):
    full_path = prepend_installroot(context, filepath)
    find_file_by_glob(full_path)
Esempio n. 8
0
def step_delete_file_with_globs(context, filepath):
    for path in glob.glob(prepend_installroot(context, filepath)):
        delete_file(path)
Esempio n. 9
0
def step_delete_directory(context, dirpath):
    full_path = prepend_installroot(context, dirpath)
    delete_directory(full_path)
Esempio n. 10
0
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)
Esempio n. 11
0
def step_delete_file(context, filepath):
    full_path = prepend_installroot(context, filepath)
    delete_file(full_path)
Esempio n. 12
0
def step_impl(context, dirpath):
    full_path = prepend_installroot(context, dirpath)
    ensure_directory_exists(full_path)
Esempio n. 13
0
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))
Esempio n. 14
0
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)
Esempio n. 15
0
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)))
Esempio n. 16
0
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)
Esempio n. 17
0
def create_compressed_file_with(context, compression, filepath):
    target_path = prepend_installroot(context, filepath)
    create_compressed_file_with_contents(target_path, compression,
                                         context.text)
Esempio n. 18
0
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))
Esempio n. 19
0
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
Esempio n. 20
0
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)