Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelfeld committed Jun 21, 2016
2 parents 9fd01eb + 1e9ab83 commit 4452758
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
21 changes: 11 additions & 10 deletions poirot/poirot.py
Expand Up @@ -17,18 +17,19 @@


def main(args=sys.argv, render_results=True):
args.pop(0)
info = parse_arguments(args)
results = {}

# checks that command invoked on a git directory
if not os.path.exists(info["git_dir"]):
raise IOError("""Invalid .git directory: {dir}\nSpecify
the correct local directory with
--dir""".format(dir=info["git_dir"]))
def is_git_dir(dir):
# checks that command invoked on a git directory
if not os.path.exists(dir):
raise IOError("""Invalid .git directory: {dir}\nSpecify
the correct local directory with
--dir""".format(dir=dir))

# searches staged changes
if info["staged"]:
is_git_dir(info["git_dir"])
print(style("Investigating staged revisions", "blue"))
for pattern in info["patterns"]:
pattern = try_utf8_decode(pattern)
Expand All @@ -47,12 +48,13 @@ def main(args=sys.argv, render_results=True):
merge_committed("message", pattern, revision, info, results)


if not render_results:
return results
# output results to JSON file
elif info["output"]:
if info["output"]:
with open(info["output"], "w") as outfile:
json.dump(results, outfile, ensure_ascii=False, indent=4)

if not render_results:
return results
# render results in console if any pattern matches found
elif any(results.values()):
render(results, info)
Expand Down Expand Up @@ -81,7 +83,6 @@ def clone_pull(git_url, repo_dir):
git pull if the repository already exists at `repo_dir`.
Runs only if url argument provided to poirot command.
"""

try:
cmd = ["git", "clone", git_url, repo_dir]
subprocess.check_output(cmd, universal_newlines=True)
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures
Submodule fixtures deleted from 9e456e
19 changes: 9 additions & 10 deletions tests/poirot_tests.py
Expand Up @@ -15,20 +15,20 @@ def setUp():
current_dir = os.path.dirname(os.path.realpath(__file__))
test_repo = "https://github.com/emanuelfeld/poirot-test-repo.git"
test_dir = "{}/fixtures".format(current_dir)
execute_cmd(["mkdir", test_dir])
args = [
"--url={url}".format(url=test_repo),
"--revlist=all",
"--dir={dir}".format(dir=test_dir),
"--patterns=poirot/patterns/default.txt, https://raw.githubusercontent.com/emanuelfeld/poirot-patterns/master/default.txt",
"--term=frabjous"
"--term=frabjous",
"--output={dir}/test_results.json".format(dir=test_dir)
]
info = parse_arguments(args)
output_args = copy(args)
output_args = output_args + ["--output={dir}/test_results.json".format(dir=test_dir)]


def tearDown():
execute_cmd(["rm", "{dir}/test_results.json".format(dir=test_dir)])
execute_cmd(["rm", "-rf", test_dir])


def test_execute_cmd():
Expand All @@ -54,12 +54,6 @@ def test_info_parser():
eq_(info["git_url"], "https://github.com/emanuelfeld/poirot-test-repo.git")


def test_output():
main(output_args)
with open("{}/test_results.json".format(test_dir)) as infile:
results = json.load(infile)
eq_("cd956e8" in results["frabjous"], True)

def test_find_matches():
results = main(args=args, render_results=False)
frabjous = results["frabjous"]
Expand All @@ -75,6 +69,11 @@ def test_find_matches():
eq_(info["patterns"]["pass(word?)[[:blank:]]*[=:][[:blank:]]*.+"], "Usernames and Passwords")
ok_("log" in password["2f04563"].keys())

# test JSON output
with open("{}/test_results.json".format(test_dir)) as infile:
results = json.load(infile)
eq_("cd956e8" in results["frabjous"], True)


def test_parse_post_diff():
results = [(sha, metadata) for sha, metadata in search_committed(target="diff", pattern="frabjous", revlist="cd956e8^!", info=info)]
Expand Down

0 comments on commit 4452758

Please sign in to comment.