-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for YAML data files in load_data [RHELDST-4904]
The load_data method will accept both YAML and JSON files, but will load the data.yaml file by default. This change enables cdn-definitions-private to cease maintaining two sets of data, in both YAML and JSON forms -- only data.yaml files will be provided and maintained. Those who wish to use the cdn-definitions-private data will be able to do so without a manual conversion of the YAML data file into a JSON file.
- Loading branch information
1 parent
614467e
commit 34e906f
Showing
5 changed files
with
33 additions
and
8 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,2 @@ | ||
PyYAML | ||
pathlib |
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,2 @@ | ||
pytest | ||
jsonschema | ||
PyYAML |
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,13 +1,25 @@ | ||
from cdn_definitions._impl import load_data | ||
|
||
|
||
def test_can_load_custom_data(monkeypatch, tmpdir): | ||
def test_can_load_custom_json_data(monkeypatch, tmpdir): | ||
json_file = tmpdir.join("myfile.json") | ||
json_file.write('{"hello": "world"}') | ||
json_file.write('{"hello": "json"}') | ||
|
||
# If we set an env var pointing at the above JSON file, the library | ||
# should load it instead of the bundled data | ||
monkeypatch.setenv("CDN_DEFINITIONS_PATH", str(json_file)) | ||
data = load_data() | ||
|
||
assert data == {"hello": "world"} | ||
assert data == {"hello": "json"} | ||
|
||
|
||
def test_can_load_custom_yaml_data(monkeypatch, tmpdir): | ||
yaml_file = tmpdir.join("myfile.yaml") | ||
yaml_file.write("hello: yaml") | ||
|
||
# If we set an env var pointing at the above YAML file, the library | ||
# should load it instead of the bundled data | ||
monkeypatch.setenv("CDN_DEFINITIONS_PATH", str(yaml_file)) | ||
data = load_data() | ||
|
||
assert data == {"hello": "yaml"} |
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