Skip to content

Commit 1f36b2c

Browse files
committed
Add tests.
1 parent b0894e8 commit 1f36b2c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2024 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/up
5+
"""Contains tests for DataScienceJobRun class."""
6+
7+
from unittest import TestCase, mock
8+
9+
import oci
10+
from ads.jobs import DataScienceJobRun
11+
12+
13+
class JobRunTestCase(TestCase):
14+
"""Contains test cases for Job runs."""
15+
16+
@mock.patch("ads.jobs.builders.infrastructure.dsc_job.DataScienceJobRun.sync")
17+
def test_job_run_wait(self, *args):
18+
"""Test waiting for job run."""
19+
run = DataScienceJobRun()
20+
run.lifecycle_state = oci.data_science.models.JobRun.LIFECYCLE_STATE_IN_PROGRESS
21+
22+
# Mock time.sleep to change the job run lifecycle state.
23+
def mock_sleep(*args, **kwargs):
24+
run.lifecycle_state = (
25+
oci.data_science.models.JobRun.LIFECYCLE_STATE_SUCCEEDED
26+
)
27+
28+
with mock.patch("time.sleep", wraps=mock_sleep):
29+
run.wait()
30+
31+
self.assertEqual(
32+
run.lifecycle_state,
33+
oci.data_science.models.JobRun.LIFECYCLE_STATE_SUCCEEDED,
34+
)
35+
36+
def test_job_run_exit_code(self):
37+
"""Tests job run exit code."""
38+
run = DataScienceJobRun()
39+
self.assertEqual(run.exit_code, None)
40+
run.lifecycle_state = run.LIFECYCLE_STATE_SUCCEEDED
41+
self.assertEqual(run.exit_code, 0)
42+
run.lifecycle_state = run.LIFECYCLE_STATE_IN_PROGRESS
43+
run.lifecycle_details = "Job run in progress."
44+
self.assertEqual(run.exit_code, None)
45+
run.lifecycle_state = run.LIFECYCLE_STATE_FAILED
46+
run.lifecycle_details = "Job run artifact execution failed with exit code 21."
47+
self.assertEqual(run.exit_code, 21)

0 commit comments

Comments
 (0)