-
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 15, 2017
1 parent
64469ad
commit 10555a6
Showing
8 changed files
with
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Test Config.""" | ||
import sys | ||
from pathlib import Path | ||
import pytest | ||
from user_config import Config, Section, StringOption | ||
|
||
class FallbackConfig(Config): | ||
|
||
"""Test configuration fallback.""" | ||
|
||
application = "test" | ||
author = "nobody" | ||
|
||
class GeneralSection(Section): | ||
|
||
"""General section.""" | ||
|
||
string = StringOption(default="default") | ||
|
||
general = GeneralSection() | ||
|
||
def test_default(): | ||
config_directory = Path(__file__).parents[0] / 'test_config' | ||
sys.argv = [sys.argv[0]] | ||
config = FallbackConfig( | ||
file_name="default", | ||
global_path=config_directory / 'global', | ||
user_path=config_directory / 'user') | ||
assert config.general.string == "default" | ||
|
||
def test_global(): | ||
config_directory = Path(__file__).parents[0] / 'test_config' | ||
sys.argv = [sys.argv[0]] | ||
config = FallbackConfig( | ||
file_name="global", | ||
global_path=config_directory / 'global', | ||
user_path=config_directory / 'user') | ||
assert config.general.string == "global" | ||
|
||
def test_user(): | ||
config_directory = Path(__file__).parents[0] / 'test_config' | ||
sys.argv = [sys.argv[0]] | ||
config = FallbackConfig( | ||
file_name="user", | ||
global_path=config_directory / 'global', | ||
user_path=config_directory / 'user') | ||
assert config.general.string == "user" | ||
|
||
def test_cli(): | ||
config_directory = Path(__file__).parents[0] / 'test_config' | ||
sys.argv = [sys.argv[0], '--string', 'cli'] | ||
config = FallbackConfig( | ||
file_name="user", | ||
global_path=config_directory / 'global', | ||
user_path=config_directory / 'user') | ||
assert config.general.string == "cli" | ||
|
||
def test_required_attributes(): | ||
class NoApplication(Config): | ||
"""Test missing application attribute.""" | ||
author = "nobody" | ||
with pytest.raises(AttributeError): | ||
NoApplication() | ||
class NoAuthor(Config): | ||
"""Test missing author attribute.""" | ||
application = "test" | ||
with pytest.raises(AttributeError): | ||
NoAuthor() |
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,2 @@ | ||
[general] | ||
# string = default |
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,2 @@ | ||
[general] | ||
string = global |
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,2 @@ | ||
[general] | ||
string = global |
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,2 @@ | ||
[general] | ||
# string = default |
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,2 @@ | ||
[general] | ||
# string = default |
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,2 @@ | ||
[general] | ||
string = user |
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