Skip to content

Commit ecd2c34

Browse files
authored
Add opctl integration tests (#265)
1 parent 72ebdc5 commit ecd2c34

File tree

20 files changed

+903
-26
lines changed

20 files changed

+903
-26
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ repos:
1313
args: ['--allow-multiple-documents']
1414
- id: detect-private-key
1515
- id: end-of-file-fixer
16+
exclude: '\.ipynb?$'
1617
- id: pretty-format-json
1718
args: ['--autofix']
1819
- id: trailing-whitespace

README-development.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ for development and testing purposes.
3030
Install Anaconda from `https://repo.continuum.io/miniconda/` for the operating system you are using.
3131

3232
In the terminal client, enter the following where <yourenvname> is the name you want to call your environment,
33-
and set the Python version you want to use. ADS SDK requires Python >=3.7.
33+
and set the Python version you want to use. ADS SDK requires Python >=3.8.
3434

3535
```bash
36-
conda create -n <yourenvname> python=3.7 anaconda
36+
conda create -n <yourenvname> python=3.8 anaconda
3737
```
3838

3939
This installs the Python version and all the associated anaconda packaged libraries at `path_to_your_anaconda_location/anaconda/envs/<yourenvname>`
@@ -79,6 +79,61 @@ Use `ads_version.json` for versioning. The ADS SDK is packaged as a wheel. To ge
7979

8080
This wheel can then be installed using `pip`.
8181

82+
## Running tests
83+
84+
The SDK uses pytest as its test framework.
85+
86+
### Running default setup tests
87+
88+
Default setup tests for testing ADS SDK without extra dependencies, specified in setup.py.
89+
90+
```bash
91+
# Update your environment with tests dependencies
92+
pip install -r test-requirements.txt
93+
# Run default setup tests
94+
python3 -m pytest tests/unitary/default_setup
95+
```
96+
97+
### Running all unit tests
98+
99+
To run all unit test install extra dependencies to test all modules of ADS ASD.
100+
101+
```bash
102+
# Update your environment with tests dependencies
103+
pip install -r dev-requirements.txt
104+
# Run all unit tests
105+
python3 -m pytest tests/unitary
106+
```
107+
108+
### Running integration tests
109+
110+
ADS opctl integration tests can't be run together with all other integration tests, they require special setup.
111+
To run all but opctl integration tests, you can run:
112+
113+
```bash
114+
# Update your environment with tests dependencies
115+
pip install -r dev-requirements.txt
116+
# Run integration tests
117+
python3 -m pytest tests/integration --ignore=tests/integration/opctl
118+
```
119+
120+
### Running opctl integration tests
121+
122+
ADS opctl integration tests utilize cpu, gpu jobs images and need dataexpl_p37_cpu_v2 and pyspark30_p37_cpu_v3 Data Science Environments be installed, see the [About Conda Environments](https://docs.oracle.com/en-us/iaas/data-science/using/conda_understand_environments.htm).
123+
To build development container, see the [Build Development Container Image](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/opctl/localdev/jobs_container_image.html).
124+
125+
```bash
126+
# Update your environment with tests dependencies
127+
pip install -r test-requirements.txt
128+
pip install -e ".[opctl]"
129+
pip install oci oci-cli
130+
# Build cpu and gpu jobs images
131+
ads opctl build-image -d job-local
132+
ads opctl build-image -g -d job-local
133+
# Run opclt integration tests
134+
python3 -m pytest tests/integration/opctl
135+
```
136+
82137
## Security
83138

84139
Consult the [security guide](./SECURITY.md) for our responsible security

ads/opctl/cmds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, config: Dict):
120120
@property
121121
def backend(self):
122122
if self._backend == BACKEND_NAME.LOCAL.value:
123-
kind = self.config.get("kind")
123+
kind = self.config.get("kind") or self.config["execution"].get("kind")
124124
if kind not in self.LOCAL_BACKENDS_MAP:
125125
options = [backend for backend in self.LOCAL_BACKENDS_MAP.keys()]
126126
# Special case local backend option not supported by this factory.

tests/conftest.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,3 @@
22

33
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5-
6-
import pytest
7-
8-
9-
def pytest_addoption(parser):
10-
parser.addoption(
11-
"--opctl",
12-
action="store_true",
13-
default=False,
14-
help="run opctl tests",
15-
)
16-
17-
18-
def pytest_configure(config):
19-
config.addinivalue_line("markers", "opctl: mark opctl tests")
20-
21-
22-
def pytest_collection_modifyitems(config, items):
23-
if not config.getoption("--opctl"):
24-
skip_opctl = pytest.mark.skip(reason="need --opctl option to run")
25-
for item in items:
26-
if "opctl" in item.keywords:
27-
item.add_marker(skip_opctl)

tests/integration/opctl/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
7+
def test_import_nested():
8+
print("This is an imported module from nested folder.")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
import argparse
7+
import os
8+
import json
9+
from test_mod import test_import
10+
from folder.test_mod import test_import_nested
11+
import ads
12+
13+
if __name__ == "__main__":
14+
parser = argparse.ArgumentParser()
15+
parser.add_argument("-n", "--name", required=False, default="ADS")
16+
args = parser.parse_args()
17+
print(f"ADS {ads.__version__}")
18+
print("Running user script...")
19+
print(f"Hello World from {args.name}")
20+
print("Printing environment variables...")
21+
print(json.dumps(dict(os.environ), indent=2))
22+
test_import()
23+
test_import_nested()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
import os
7+
from test_mod import test_import
8+
import ads
9+
10+
11+
def operate(spec=None, **kwargs):
12+
print(f"ADS {ads.__version__}")
13+
test_import()
14+
print(kwargs["oci_auth"])
15+
name = spec["name"] if spec else ""
16+
print("Hello World", name)
17+
if "TEST_ENV" in os.environ:
18+
print(f"Test passing environment variables TEST_ENV={os.environ['TEST_ENV']}")

0 commit comments

Comments
 (0)