-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mainline' into moorec/fix-integ-test
- Loading branch information
Showing
6 changed files
with
77 additions
and
22 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 +1 @@ | ||
deadline-cloud-test-fixtures ~= 0.6.2 | ||
deadline-cloud-test-fixtures == 0.7.* |
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,27 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import json | ||
import os | ||
from typing import Any | ||
from ._yaml import deadline_yaml_dump | ||
|
||
|
||
def save_yaml_or_json_to_file( | ||
bundle_dir: str, | ||
filename: str, | ||
file_type: str, | ||
data: Any, | ||
) -> None: | ||
""" | ||
Saves data as either a JSON or YAML file depending on the file_type provided. Useful for saving | ||
job bundle data files which can be in either format. file_type should be either "YAML" or "JSON". | ||
""" | ||
with open( | ||
os.path.join(bundle_dir, f"{filename}.{file_type.lower()}"), "w", encoding="utf8" | ||
) as f: | ||
if file_type == "YAML": | ||
deadline_yaml_dump(data, f) | ||
elif file_type == "JSON": | ||
json.dump(data, f, indent=2) | ||
else: | ||
raise RuntimeError(f"Unexpected file type '{file_type}' in job bundle:\n{bundle_dir}") |
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,27 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import os | ||
from pathlib import Path | ||
import tempfile | ||
import pytest | ||
from deadline.client.job_bundle.saver import save_yaml_or_json_to_file | ||
|
||
|
||
def test_save_yaml_or_json_to_file(): | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
save_yaml_or_json_to_file( | ||
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="YAML" | ||
) | ||
assert Path(os.path.join(temp_dir, "test.yaml")).read_text() == "test: test\n" | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
save_yaml_or_json_to_file( | ||
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="JSON" | ||
) | ||
assert Path(os.path.join(temp_dir, "test.json")).read_text() == '{\n "test": "test"\n}' | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
with pytest.raises(RuntimeError): | ||
save_yaml_or_json_to_file( | ||
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="NOT_VALID" | ||
) |