-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unused code, add commandline tests
- Loading branch information
1 parent
90d8e69
commit fc263ce
Showing
5 changed files
with
51 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
import subprocess | ||
import os | ||
|
||
file_content = \ | ||
""" | ||
def fib(n): | ||
if n < 2: | ||
return 1 | ||
return fib(n-1) + fib(n-2) | ||
fib(5) | ||
""" | ||
class TestCommandLineBasic(unittest.TestCase): | ||
def build_script(self): | ||
with open("cmdline_test.py", "w") as f: | ||
f.write(file_content) | ||
|
||
def cleanup(self, output_file="result.html"): | ||
os.remove("cmdline_test.py") | ||
os.remove(output_file) | ||
|
||
def template(self, cmd_list, expected_output_file="result.html", success=True): | ||
self.build_script() | ||
result = subprocess.run(cmd_list) | ||
self.assertTrue(success ^ (result.returncode != 0)) | ||
self.assertTrue(os.path.exists(expected_output_file)) | ||
self.cleanup(output_file=expected_output_file) | ||
|
||
def test_run(self): | ||
self.template(["python", "-m", "codesnap", "cmdline_test.py"]) | ||
|
||
def test_outputfile(self): | ||
self.template(["python", "-m", "codesnap", "-o", "result.html", "cmdline_test.py"]) | ||
self.template(["python", "-m", "codesnap", "-o", "result.json", "cmdline_test.py"], expected_output_file="result.json") | ||
self.template(["python", "-m", "codesnap", "--output_file", "result.html", "cmdline_test.py"]) | ||
self.template(["python", "-m", "codesnap", "--output_file", "result.json", "cmdline_test.py"], expected_output_file="result.json") | ||
|
||
def test_tracer(self): | ||
self.template(["python", "-m", "codesnap", "--tracer", "c", "cmdline_test.py"]) | ||
self.template(["python", "-m", "codesnap", "--tracer", "python", "cmdline_test.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters