Skip to content

Commit

Permalink
ODSC-47592. Fix test_jobs_python_runtime.py
Browse files Browse the repository at this point in the history
- removed hardcoded config path from test_dsc_job.py
- added if to update kwargs with default_signer in jobs  serializer write_to_fle
- fixed check-docstring-first pro-commit check in serializer.py
  • Loading branch information
liudmylaru committed Sep 20, 2023
1 parent 4b55395 commit c71f6e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
14 changes: 10 additions & 4 deletions ads/jobs/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import yaml
from ads.common.auth import default_signer

# Special type to represent the current enclosed class.
# This type is used by factory class method or when a method returns ``self``.
Self = TypeVar("Self", bound="Serializable")
"""Special type to represent the current enclosed class.
This type is used by factory class method or when a method returns ``self``.
"""


class Serializable(ABC):
Expand Down Expand Up @@ -72,6 +70,14 @@ def _write_to_file(s: str, uri: str, **kwargs) -> None:
"if you wish to overwrite."
)

# Add default signer if the uri is an object storage uri, and
# the user does not specify config or signer.
if (
uri.startswith("oci://")
and "config" not in kwargs
and "signer" not in kwargs
):
kwargs.update(default_signer())
with fsspec.open(uri, "w", **kwargs) as f:
f.write(s)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies = [
"asteval>=0.9.25",
"cerberus>=1.3.4",
"cloudpickle>=1.6.0",
"fsspec>=0.8.7",
"fsspec>=0.8.7,<2023.9.1", # v2.9.1 introduced issues, releved by unit tests
"gitpython>=3.1.2",
"jinja2>=2.11.2",
"matplotlib>=3.1.3",
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/jobs/test_dsc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ def assert_job_creation(self, job, expected_infra_spec, expected_runtime_spec):
random.seed(threading.get_ident() + os.getpid())
random_suffix = "".join(random.choices(string.ascii_uppercase, k=6))
yaml_uri = f"oci://{self.BUCKET}@{self.NAMESPACE}/tests/{timestamp}/example_job_{random_suffix}.yaml"
config_path = "~/.oci/config"
job.to_yaml(uri=yaml_uri, config=config_path)
job.to_yaml(uri=yaml_uri)
print(f"Job YAML saved to {yaml_uri}")
try:
job = Job.from_yaml(uri=yaml_uri, config=config_path)
job = Job.from_yaml(uri=yaml_uri)
except Exception:
self.fail(f"Failed to load job from YAML\n{traceback.format_exc()}")

Expand Down

0 comments on commit c71f6e3

Please sign in to comment.