Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/openjd/cli/_common/_validation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@


def get_doc_type(filepath: Path) -> DocumentType:
# If the file has a .json extension, treat it strictly
# as JSON, otherwise treat it as YAML.
if filepath.suffix.lower() == ".json":
return DocumentType.JSON
elif filepath.suffix.lower() in (".yaml", ".yml"):
else:
return DocumentType.YAML
raise RuntimeError(f"'{str(filepath)}' is not JSON or YAML.")


def read_template(template_file: Path) -> dict[str, Any]:
Expand Down
22 changes: 13 additions & 9 deletions test/openjd/cli/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def template_dir_and_cwd():
[
pytest.param(".template.json", json.dump, id="Successful JSON"),
pytest.param(".template.yaml", yaml.dump, id="Successful YAML"),
pytest.param(".ojdt", yaml.dump, id="Successful YAML with alternate extension"),
],
)
def test_read_template_success(tempfile_extension: str, doc_serializer: Callable):
Expand Down Expand Up @@ -119,6 +120,12 @@ def test_read_template_fileerror(
'specificationVersion: "jobtemplate-2023-09"\n',
id="YAML missing field",
),
pytest.param(
# Extensions other than .json are treated as YAML
".template.ojdt",
'specificationVersion: "jobtemplate-2023-09"\n',
id="YAML missing field",
),
],
)
def test_read_job_template_parsingerror(tempfile_extension: str, file_contents: str):
Expand Down Expand Up @@ -152,6 +159,12 @@ def test_read_job_template_parsingerror(tempfile_extension: str, file_contents:
'specificationVersion: "environment-2023-09"\n',
id="YAML missing field",
),
pytest.param(
# Extensions other than .json are treated as YAML
".template.ojde",
'specificationVersion: "environment-2023-09"\n',
id="YAML missing field",
),
],
)
def test_read_environment_template_parsingerror(tempfile_extension: str, file_contents: str):
Expand Down Expand Up @@ -243,15 +256,6 @@ def test_get_job_params_success(mock_param_args: list[str], expected_param_value
"is not a file",
id="Parameter filepath is not a file",
),
pytest.param(
["file://some-image.png"],
True,
True,
"some-image.png",
None,
"is not JSON or YAML",
id="Parameter filepath is not JSON/YAML",
),
pytest.param(
["file://forbidden-file.json"],
True,
Expand Down