-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from manu-chroma/master
schema_salad/main.py: --version now correctly prints version
- Loading branch information
Showing
2 changed files
with
50 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
import sys | ||
|
||
import schema_salad.main as cli_parser | ||
|
||
""" for capturing print() output """ | ||
from contextlib import contextmanager | ||
from StringIO import StringIO | ||
|
||
@contextmanager | ||
def captured_output(): | ||
new_out, new_err = StringIO(), StringIO() | ||
old_out, old_err = sys.stdout, sys.stderr | ||
try: | ||
sys.stdout, sys.stderr = new_out, new_err | ||
yield sys.stdout, sys.stderr | ||
finally: | ||
sys.stdout, sys.stderr = old_out, old_err | ||
|
||
|
||
""" test different sets of command line arguments""" | ||
class ParseCliArgs(unittest.TestCase): | ||
|
||
def test_version(self): | ||
args = [["--version"], ["-v"]] | ||
for arg in args: | ||
with captured_output() as (out, err): | ||
cli_parser.main(arg) | ||
|
||
response = out.getvalue().strip() # capture output and strip newline | ||
self.assertTrue("Current version" in response) | ||
|
||
def test_empty_input(self): | ||
# running schema_salad tool wihtout any args | ||
args = [] | ||
with captured_output() as (out, err): | ||
cli_parser.main(args) | ||
|
||
response = out.getvalue().strip() | ||
self.assertTrue("error: too few arguments" in response) |