Skip to content

Commit 1ed9c3c

Browse files
fix type hints and add unit tests
1 parent bccfa73 commit 1ed9c3c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/psij/job_spec.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
from __future__ import annotations
2+
13
import sys
24
from pathlib import Path
3-
from typing import Optional, List, Dict, Any
5+
from typing import Any, Dict, List, Optional
46

57
from typeguard import check_argument_types
68

79
from psij.job_attributes import JobAttributes
810
from psij.resource_spec import ResourceSpec
9-
1011
from psij.utils import path_object_to_full_path as o2p
1112

1213

1314
class JobSpec(object):
1415
"""A class to hold information about the characteristics of a:class:`~psij.Job`."""
1516

1617
def __init__(self, name: Optional[str] = None, executable: Optional[str] = None,
17-
arguments: Optional[List[str]] = None, directory: Optional[Path] = None,
18+
arguments: Optional[List[str]] = None, directory: Optional[str | Path] = None,
1819
inherit_environment: bool = True, environment: Optional[Dict[str, str]] = None,
19-
stdin_path: Optional[Path] = None, stdout_path: Optional[Path] = None,
20-
stderr_path: Optional[Path] = None, resources: Optional[ResourceSpec] = None,
21-
attributes: Optional[JobAttributes] = None, pre_launch: Optional[Path] = None,
22-
post_launch: Optional[Path] = None, launcher: Optional[str] = None):
20+
stdin_path: Optional[str | Path] = None, stdout_path: Optional[str | Path] = None,
21+
stderr_path: Optional[str | Path] = None, resources: Optional[ResourceSpec] = None,
22+
attributes: Optional[JobAttributes] = None, pre_launch: Optional[str | Path] = None,
23+
post_launch: Optional[str | Path] = None, launcher: Optional[str] = None):
2324
"""
2425
Constructs a `JobSpec` object while allowing its properties to be initialized.
2526

tests/test_job_spec.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
2+
from pathlib import Path
13

24
import pytest
35

4-
from psij import JobSpec, JobExecutor, Job
6+
from psij import Job, JobExecutor, JobSpec
57

68

79
def _test_spec(spec: JobSpec) -> None:
@@ -32,8 +34,12 @@ def test_environment_types() -> None:
3234
spec.environment = {'foo': 'bar'}
3335
assert spec.environment['foo'] == 'bar'
3436

35-
spec.environment = {'foo': 'biz'}
36-
assert spec.environment['foo'] == 'biz'
37+
assert JobSpec(directory=os.path.join("test", "path")).directory == Path("test") / "path"
38+
assert JobSpec(stdin_path=os.path.join("test", "path")).directory == Path("test") / "path"
39+
assert JobSpec(stdout_path=os.path.join("test", "path")).directory == Path("test") / "path"
40+
assert JobSpec(stderr_path=os.path.join("test", "path")).directory == Path("test") / "path"
41+
assert JobSpec(pre_launch=os.path.join("test", "path")).directory == Path("test") / "path"
42+
assert JobSpec(post_launch=os.path.join("test", "path")).directory == Path("test") / "path"
3743

3844

3945
test_environment_types()

0 commit comments

Comments
 (0)