-
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.
- Loading branch information
nihlaeth
committed
Feb 12, 2017
1 parent
44a5281
commit ee97e17
Showing
5 changed files
with
63 additions
and
3 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,3 +1,6 @@ | ||
[aliases] | ||
test=pytest | ||
|
||
[build_sphinx] | ||
source-dir = doc/source | ||
build-dir = doc/build | ||
|
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,56 @@ | ||
"""Test ConfigElement and subclasses.""" | ||
import argparse | ||
import pytest | ||
|
||
from user_config import ConfigElement, InvalidData | ||
|
||
def validate_length(value): | ||
"""Custom validator.""" | ||
if len(value) > 3: | ||
raise InvalidData('we cant handle more than three characters') | ||
|
||
# pylint:disable=no-self-use | ||
class TestConfigElement(object): | ||
|
||
def test_init(self): | ||
with pytest.raises(InvalidData): | ||
config_element = ConfigElement(default=42) | ||
config_element = ConfigElement(doc="test") | ||
assert config_element.doc == "test" | ||
assert config_element.required | ||
config_element = ConfigElement(required=False) | ||
assert not config_element.required | ||
config_element = ConfigElement(short_name='f') | ||
# pylint: disable=protected-access | ||
assert config_element._short_name == '-f' | ||
config_element = ConfigElement(short_name='-f') | ||
assert config_element._short_name == '-f' | ||
config_element = ConfigElement(long_name='force') | ||
assert config_element._long_name == '--force' | ||
config_element = ConfigElement(long_name='--force') | ||
assert config_element._long_name == '--force' | ||
config_element = ConfigElement( | ||
default='hi', validate=validate_length) | ||
assert config_element.get_default() == 'hi' | ||
with pytest.raises(InvalidData): | ||
config_element = ConfigElement( | ||
default='high', validate=validate_length) | ||
|
||
def test_default(self): | ||
config_element = ConfigElement() | ||
assert not config_element.has_default() | ||
assert config_element.get_default() is None | ||
config_element = ConfigElement(default="test") | ||
assert config_element.has_default() | ||
assert config_element.get_default() == "test" | ||
|
||
def test_parser(self): | ||
config_element = ConfigElement() | ||
config_element.element_name = "test" | ||
parser = argparse.ArgumentParser(prog="test application") | ||
config_element.construct_parser(parser) | ||
arguments = vars(parser.parse_args(['--test', 'success'])) | ||
assert arguments['test'] == 'success' | ||
data = {} | ||
config_element.extract_data_from_parser(arguments, data) | ||
assert data['test'] == 'success' |
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