summaryrefslogtreecommitdiff
path: root/subplot/summain.py
blob: 98eecf24471ee802877fe082a637a29a47c5e28f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import logging
import os


def install_summain(ctx):
    runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
    srcdir = globals()["srcdir"]
    bindir = os.path.join(srcdir, "target", "debug")
    runcmd_prepend_to_path(ctx, dirname=bindir)


def create_directory(ctx, dirname=None):
    os.mkdir(dirname)


def create_file(ctx, filename=None):
    open(filename, "w").close()


def set_atime(ctx, filename=None, timestamp=None):
    st = os.lstat(filename)
    os.utime(filename, (int(timestamp), int(st.st_mtime)))


def set_mtime(ctx, filename=None, timestamp=None):
    st = os.lstat(filename)
    os.utime(filename, (int(st.st_atime), int(timestamp)))


def output_matches_file(ctx, filename=None):
    runcmd_get_stdout = globals()["runcmd_get_stdout"]
    get_file = globals()["get_file"]
    assert_eq = globals()["assert_eq"]

    actual = runcmd_get_stdout(ctx)
    expected = get_file(filename).decode("UTF-8")
    logging.debug("output_matches:")
    logging.debug(f"  actual: {actual!r}")
    logging.debug(f"  expect: {expected!r}")
    assert_eq(actual, expected)