-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support .ini files and fix
convert_types
for recursion
- Loading branch information
1 parent
cb65060
commit 9333029
Showing
7 changed files
with
164 additions
and
21 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,18 @@ | ||
# https://docs.python.org/3/library/configparser.html | ||
|
||
[default] | ||
string = "value" | ||
number = 45 | ||
BOOLEAN = yes | ||
other_boolean = true | ||
|
||
[topsecret.server.example] | ||
Port = 50022 | ||
ForwardX11 = no | ||
nothing = null | ||
|
||
[section with spaces] | ||
# comment | ||
key with spaces = value with spaces | ||
empty = | ||
with colon : as seperator |
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
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 |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
|
||
def _load_toml(): | ||
with EXAMPLE_FILE.open("rb") as f: | ||
return loaders.toml(f) | ||
return loaders.toml(f, None) |
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,58 @@ | ||
import typing | ||
|
||
from src import configuraptor | ||
|
||
from .constants import PYTEST_EXAMPLES | ||
|
||
INI = PYTEST_EXAMPLES / "config.ini" | ||
|
||
|
||
class Default: | ||
string: str | ||
number: int | ||
boolean: bool | ||
other_boolean: bool | ||
|
||
|
||
class Example: | ||
port: int | ||
forwardx11: bool | ||
nothing: None | ||
|
||
|
||
class Server: | ||
example: Example | ||
|
||
|
||
class TopSecret: | ||
server: Server | ||
|
||
|
||
class WithSpaces: | ||
key_with_spaces: str | ||
empty: str | ||
with_colon: str | ||
|
||
|
||
class MyConfig: | ||
default: Default | ||
topsecret: TopSecret | ||
section_with_spaces: WithSpaces | ||
|
||
|
||
def test_basic_ini(): | ||
my_config = configuraptor.load_into(MyConfig, INI, convert_types=True) | ||
|
||
assert my_config | ||
assert my_config.default.string == "value" | ||
assert my_config.default.number == 45 | ||
assert my_config.default.boolean is True | ||
assert my_config.default.other_boolean is True | ||
|
||
assert my_config.topsecret.server.example.port == 50022 | ||
assert my_config.topsecret.server.example.forwardx11 is False | ||
assert my_config.topsecret.server.example.nothing is None | ||
|
||
assert isinstance(my_config.section_with_spaces.key_with_spaces, str) | ||
assert my_config.section_with_spaces.empty == "" | ||
assert my_config.section_with_spaces.with_colon == "as seperator" |