Exemple #1
0
def test_format():
    formatter = ReportFormatter()

    def format(*args, **kwargs):
        return formatter.format(make_record(*args, **kwargs)).lstrip()

    assert format("run", "ls -lf .") == "run  ls -lf ."
    assert format("run", "ls", context=parent_dir()) == "run  ls from '..'"
    assert format("copy", getcwd(),
                  target=lp("../dir/../dir")) == "copy  . to '{}'".format(
                      lp("../dir"))
    fmt_out = format("create", lp("my/file"), nesting=1)
    assert fmt_out == f"create    {lp('my/file')}"
Exemple #2
0
def test_report(caplog, tmpfolder):
    # Given the logger level is properly configured
    caplog.set_level(logging.INFO)
    # When the report method is called,
    name = uniqstr()
    logger.report("make", str(tmpfolder.join(name)))
    # Then the message should be formatted accordingly.
    logs = caplog.text
    match = re.search("make.+" + name, logs)
    assert match
    # And relative paths should be used
    assert lp("/tmp") not in match.group(0)
Exemple #3
0
def test_verbose_main(tmpfolder, git_mock, caplog):
    args = ["my-project", "--verbose"]
    cli.main(args)
    assert os.path.exists(args[0])

    # Check for some log messages
    assert find_report(caplog, "invoke", "get_default_options")
    assert find_report(caplog, "invoke", "verify_options_consistency")
    assert find_report(caplog, "invoke", "define_structure")
    assert find_report(caplog, "invoke", "create_structure")
    assert find_report(caplog, "create", "setup.py")
    assert find_report(caplog, "create", lp("my_project/__init__.py"))
    assert find_report(caplog, "run", "git init")
    assert find_report(caplog, "run", "git add")
Exemple #4
0
def test_colored_report(tmpfolder, caplog, uniq_raw_logger):
    # Given the logger is properly set,
    uniq_raw_logger.setLevel(logging.INFO)
    formatter = ColoredReportFormatter()
    uniq_logger = ReportLogger(uniq_raw_logger,
                               formatter=formatter,
                               propagate=True)
    # When the report method is called,
    name = uniqstr()
    uniq_logger.report("make", str(tmpfolder.join(name)))
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.messages[-1]
    assert re.search(ansi_pattern("make") + ".+" + name, out)
    # And relative paths should be used
    assert lp("/tmp") not in out
Exemple #5
0
def test_format_path():
    formatter = ReportFormatter()
    format = formatter.format_path
    # Formatter should abbrev paths but keep other subjects unchanged
    assert format("not a command") == "not a command"
    assert format("git commit") == "git commit"
    assert format("a random message") == "a random message"
    assert format(getcwd()) == "."
    assert format(lp("../dir/../dir/..")) == lp("..")
    assert format(lp("../dir/../dir/../foo")) == lp("../foo")
    # shorter absolute is better than relative
    assert format(lp("/a")) == lp("/a")
Exemple #6
0
def parent_dir():
    return abspath(lp(".."))