Skip to content

Commit c38b1de

Browse files
committed
feat: Treat job template extensions other than .json as YAML
Currently, the `openjd run` and other commands will fail if the job template they receive has an extension different from .json, .yml, or .yaml. This change treats all non-.json extensions as YAML, so that job templates can be named with different extensions like `.ojdt` that clearly distinguish them from generic JSON or YAML. Signed-off-by: Mark <[email protected]>
1 parent 3be2661 commit c38b1de

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/openjd/cli/_common/_validation_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616

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

2425

2526
def read_template(template_file: Path) -> dict[str, Any]:

test/openjd/cli/test_common.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def template_dir_and_cwd():
5050
[
5151
pytest.param(".template.json", json.dump, id="Successful JSON"),
5252
pytest.param(".template.yaml", yaml.dump, id="Successful YAML"),
53+
pytest.param(".ojdt", yaml.dump, id="Successful YAML with alternate extension"),
5354
],
5455
)
5556
def test_read_template_success(tempfile_extension: str, doc_serializer: Callable):
@@ -119,6 +120,12 @@ def test_read_template_fileerror(
119120
'specificationVersion: "jobtemplate-2023-09"\n',
120121
id="YAML missing field",
121122
),
123+
pytest.param(
124+
# Extensions other than .json are treated as YAML
125+
".template.ojdt",
126+
'specificationVersion: "jobtemplate-2023-09"\n',
127+
id="YAML missing field",
128+
),
122129
],
123130
)
124131
def test_read_job_template_parsingerror(tempfile_extension: str, file_contents: str):
@@ -152,6 +159,12 @@ def test_read_job_template_parsingerror(tempfile_extension: str, file_contents:
152159
'specificationVersion: "environment-2023-09"\n',
153160
id="YAML missing field",
154161
),
162+
pytest.param(
163+
# Extensions other than .json are treated as YAML
164+
".template.ojde",
165+
'specificationVersion: "environment-2023-09"\n',
166+
id="YAML missing field",
167+
),
155168
],
156169
)
157170
def test_read_environment_template_parsingerror(tempfile_extension: str, file_contents: str):
@@ -243,15 +256,6 @@ def test_get_job_params_success(mock_param_args: list[str], expected_param_value
243256
"is not a file",
244257
id="Parameter filepath is not a file",
245258
),
246-
pytest.param(
247-
["file://some-image.png"],
248-
True,
249-
True,
250-
"some-image.png",
251-
None,
252-
"is not JSON or YAML",
253-
id="Parameter filepath is not JSON/YAML",
254-
),
255259
pytest.param(
256260
["file://forbidden-file.json"],
257261
True,

0 commit comments

Comments
 (0)