Skip to content

Commit 0a5e418

Browse files
authored
Add GitHub Actions for Python unit tests (#1677)
* Add GitHub Actions for Python unit tests * Add PythonPath * Add health * Add pwd * Mock kube config * Add Rest PATH
1 parent 42e3cb2 commit 0a5e418

File tree

12 files changed

+48
-40
lines changed

12 files changed

+48
-40
lines changed

.github/workflows/test-python.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Python Test
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v2
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.7
20+
21+
- name: Install Packages
22+
run: |
23+
pip install grpcio-testing==1.40.0
24+
pip install pytest==5.1.2
25+
26+
pip install -r cmd/suggestion/chocolate/v1beta1/requirements.txt
27+
pip install -r cmd/suggestion/hyperopt/v1beta1/requirements.txt
28+
pip install -r cmd/suggestion/skopt/v1beta1/requirements.txt
29+
pip install -r cmd/suggestion/optuna/v1beta1/requirements.txt
30+
pip install -r cmd/suggestion/nas/enas/v1beta1/requirements.txt
31+
pip install -r cmd/suggestion/hyperband/v1beta1/requirements.txt
32+
pip install -r cmd/suggestion/nas/darts/v1beta1/requirements.txt
33+
34+
pip install -r cmd/earlystopping/medianstop/v1beta1/requirements.txt
35+
36+
- name: Run Python test
37+
run: |
38+
export PYTHONPATH=$(pwd):$(pwd)/pkg/apis/manager/v1beta1/python:$(pwd)/pkg/apis/manager/health/python
39+
echo $PYTHONPATH
40+
pytest ./test/unit/v1beta1/suggestion
41+
pytest ./test/unit/v1beta1/earlystopping

test/e2e/v1beta1/scripts/python-tests.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/suggestion/v1beta1/test_requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/earlystopping/v1beta1/test_medianstop_service.py renamed to test/unit/v1beta1/earlystopping/test_medianstop_service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import grpc
1616
import grpc_testing
1717
import unittest
18+
from unittest.mock import patch
1819

1920
from pkg.apis.manager.v1beta1.python import api_pb2
2021

@@ -23,6 +24,11 @@
2324

2425
class TestMedianStop(unittest.TestCase):
2526
def setUp(self):
27+
# Mock load Kubernetes config.
28+
patcher = patch('pkg.earlystopping.v1beta1.medianstop.service.config.load_kube_config')
29+
self.mock_sum = patcher.start()
30+
self.addCleanup(patcher.stop)
31+
2632
servicers = {
2733
api_pb2.DESCRIPTOR.services_by_name['EarlyStopping']: MedianStopService(
2834
)
@@ -60,7 +66,7 @@ def test_get_earlystopping_rules(self):
6066
invocation_metadata={},
6167
request=request, timeout=1)
6268

63-
response, metadata, code, details = get_earlystopping_rules.termination()
69+
_, _, code, _ = get_earlystopping_rules.termination()
6470

6571
self.assertEqual(code, grpc.StatusCode.OK)
6672

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)