-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit and system tests for log lvl in cmd line
Setting the log level in the command line got broken. I didn't really think of this as a fragile element until it got badly torn up by the CLI parsing refactor. Adding multiple tests which capture this potential for breakage at multiple levels will suffice for now.
- Loading branch information
Showing
2 changed files
with
79 additions
and
50 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 |
---|---|---|
@@ -1,75 +1,85 @@ | ||
#!/usr/bin/python | ||
|
||
import mock | ||
import io | ||
from nose.tools import istest | ||
|
||
import logging | ||
import salve | ||
from salve.cli import parser | ||
from tests.util import ensure_except | ||
from tests.util import ensure_except, MockedGlobals | ||
|
||
|
||
@istest | ||
def parse_cmd1(): | ||
""" | ||
Unit: Command Line Parse Deploy Manifest File Specified | ||
Verifies that attempting to run from the commandline successfully | ||
parses manifest file specification in sys.argv | ||
""" | ||
fake_argv = ['./salve.py', 'deploy', '-m', 'a/b/c'] | ||
class TestsWithMockedIO(MockedGlobals): | ||
@istest | ||
@mock.patch('sys.argv', ['./salve.py', 'deploy', '-m', 'a/b/c']) | ||
def parse_cmd1(self): | ||
""" | ||
Unit: Command Line Parse Deploy Manifest File Specified | ||
Verifies that attempting to run from the commandline successfully | ||
parses manifest file specification in sys.argv | ||
""" | ||
p = parser.get_parser() | ||
|
||
p = parser.get_parser() | ||
with mock.patch('sys.argv', fake_argv): | ||
args = p.parse_args() | ||
assert args.manifest == 'a/b/c' | ||
assert args.directory is None | ||
assert args.configfile is None | ||
|
||
@istest | ||
@mock.patch('sys.argv', | ||
['./salve.py', 'deploy', '-c', 'p/q', '-m', 'root.man']) | ||
def parse_cmd2(self): | ||
""" | ||
Unit: Command Line Parse Deploy Config File Other Order | ||
Verifies that attempting to run from the commandline successfully | ||
parses config file specification in sys.argv after the deploy | ||
subcommand | ||
""" | ||
p = parser.get_parser() | ||
|
||
@istest | ||
def parse_cmd2(): | ||
""" | ||
Unit: Command Line Parse Deploy Config File Other Order | ||
Verifies that attempting to run from the commandline successfully | ||
parses config file specification in sys.argv after the deploy subcommand | ||
""" | ||
fake_argv = ['./salve.py', 'deploy', '-c', 'p/q', '-m', 'root.man'] | ||
|
||
p = parser.get_parser() | ||
with mock.patch('sys.argv', fake_argv): | ||
args = p.parse_args() | ||
assert args.configfile == 'p/q' | ||
assert args.directory is None | ||
assert args.manifest == 'root.man' | ||
|
||
@istest | ||
@mock.patch('sys.argv', | ||
['./salve.py', '-c', 'a/b', 'deploy', '-c', 'p/q', '-m', | ||
'root.man']) | ||
def parse_cmd3(self): | ||
""" | ||
Unit: Command Line Parse Deploy Config Option Override | ||
Confirms that passsing an option to a subparser overrides the value it | ||
was given in the parent | ||
""" | ||
p = parser.get_parser() | ||
|
||
@istest | ||
def parse_cmd3(): | ||
""" | ||
Unit: Command Line Parse Deploy Config Option Override | ||
Confirms that passsing an option to a subparser overrides the value it was | ||
given in the parent | ||
""" | ||
fake_argv = ['./salve.py', '-c', 'a/b', 'deploy', '-c', 'p/q', | ||
'-m', 'root.man'] | ||
|
||
p = parser.get_parser() | ||
with mock.patch('sys.argv', fake_argv): | ||
args = p.parse_args() | ||
assert args.configfile == 'p/q' | ||
assert args.directory is None | ||
assert args.manifest == 'root.man' | ||
|
||
@istest | ||
@mock.patch('sys.argv', ['./salve.py', 'deploy', '-c', 'p/q']) | ||
def parse_cmd4(self): | ||
""" | ||
Unit: Command Line Parse Deploy No Manifest | ||
Confirms that omitting the manifest option causes a hard abort. | ||
""" | ||
p = parser.get_parser() | ||
|
||
ensure_except(SystemExit, p.parse_args) | ||
|
||
@istest | ||
def parse_cmd4(): | ||
""" | ||
Unit: Command Line Parse Deploy No Manifest | ||
Confirms that omitting the manifest option causes a hard abort. | ||
""" | ||
fake_argv = ['./salve.py', 'deploy', '-c', 'p/q'] | ||
stderr = io.StringIO() | ||
@istest | ||
@mock.patch('sys.argv', | ||
['./salve.py', 'deploy', '-m', 'a/b/c', '-l', 'INFO']) | ||
def parse_cmd5(self): | ||
""" | ||
Unit: Command Line Parse Set Log Level | ||
Checks that the log level can be set by loading args | ||
""" | ||
args = parser.load_args() | ||
assert args.manifest == 'a/b/c' | ||
assert args.directory is None | ||
assert args.configfile is None | ||
assert args.log_level == 'INFO' | ||
|
||
p = parser.get_parser() | ||
with mock.patch('sys.argv', fake_argv): | ||
with mock.patch('sys.stderr', stderr): | ||
ensure_except(SystemExit, p.parse_args) | ||
assert salve.logger.level == logging.INFO |