Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parent_dir():
return abspath(lp(".."))
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")
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")
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 == "create {}".format(lp("my/file"))
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")
def test_pretend_main(tmpfolder, git_mock, caplog):
for flag in ["--pretend", "-P"]:
args = ["my-project", flag]
cli.main(args)
assert not 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", "requirements.txt")
assert find_report(caplog, "create", lp("my_project/__init__.py"))
assert find_report(caplog, "run", "git init")
assert find_report(caplog, "run", "git add")