-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds function to convert config types
Config parser types are by default strings. They aren't converted. This adds a function to do that for ints, floats, and booleans.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 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,21 @@ | ||
import configparser | ||
from hamilton_sdk.tracking import constants | ||
|
||
|
||
def test__convert_to_type(): | ||
# using configparser to make it more realistic | ||
config = configparser.ConfigParser() | ||
config["SDK_CONSTANTS"] = { | ||
"CAPTURE_DATA_STATISTICS": "true", | ||
"MAX_LIST_LENGTH_CAPTURE": "5", | ||
"MAX_DICT_LENGTH_CAPTURE": "10", | ||
"SOMETHING_ELSE": "11.0", | ||
"Another_thing": "1asdfasdf", | ||
} | ||
assert constants._convert_to_type(config["SDK_CONSTANTS"]["CAPTURE_DATA_STATISTICS"]) is True | ||
assert constants._convert_to_type(config["SDK_CONSTANTS"]["MAX_LIST_LENGTH_CAPTURE"]) == 5 | ||
assert constants._convert_to_type(config["SDK_CONSTANTS"]["MAX_DICT_LENGTH_CAPTURE"]) == 10 | ||
assert constants._convert_to_type(config["SDK_CONSTANTS"]["SOMETHING_ELSE"]) == 11.0 | ||
assert constants._convert_to_type(config["SDK_CONSTANTS"]["Another_thing"]) == "1asdfasdf" | ||
o = object() | ||
assert constants._convert_to_type(o) == o |