Skip to content

Commit 4ee4f6c

Browse files
Remove unused imports and re-organise in unit_test.py
1 parent a39742f commit 4ee4f6c

File tree

1 file changed

+46
-58
lines changed

1 file changed

+46
-58
lines changed

tests/unit_test.py

+46-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 IBM, Red Hat
1+
# Copyright 2022 IBM, Red Hat
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,86 +13,73 @@
1313
# limitations under the License.
1414

1515

16-
from pathlib import Path
17-
import sys
1816
import filecmp
1917
import os
2018
import re
19+
import sys
2120
import uuid
22-
from io import StringIO
23-
24-
from codeflare_sdk.ray.cluster import cluster
21+
from pathlib import Path
2522

2623
parent = Path(__file__).resolve().parents[1]
2724
aw_dir = os.path.expanduser("~/.codeflare/resources/")
2825
sys.path.append(str(parent) + "/src")
2926

30-
from kubernetes import client, config, dynamic
27+
from unittest.mock import MagicMock, patch
28+
29+
import openshift
30+
import pandas as pd
31+
import pytest
32+
import ray
33+
import yaml
34+
from kubernetes import client, config
35+
from pytest_mock import MockerFixture
36+
from ray.job_submission import JobSubmissionClient
37+
38+
import codeflare_sdk.common.widgets.widgets as cf_widgets
39+
from codeflare_sdk.common.kubernetes_cluster import (
40+
Authentication,
41+
KubeConfigFileAuthentication,
42+
TokenAuthentication,
43+
config_check,
44+
)
45+
from codeflare_sdk.common.utils.generate_cert import (
46+
export_env,
47+
generate_ca_cert,
48+
generate_tls_cert,
49+
)
3150
from codeflare_sdk.ray.appwrapper.awload import AWManager
51+
from codeflare_sdk.ray.appwrapper.status import AppWrapper, AppWrapperStatus
52+
from codeflare_sdk.ray.client.ray_jobs import RayJobClient
3253
from codeflare_sdk.ray.cluster.cluster import (
3354
Cluster,
3455
ClusterConfiguration,
56+
_app_wrapper_status,
57+
_copy_to_ray,
3558
_map_to_ray_cluster,
59+
_ray_cluster_status,
60+
get_cluster,
3661
list_all_clusters,
3762
list_all_queued,
38-
_copy_to_ray,
39-
get_cluster,
40-
_app_wrapper_status,
41-
_ray_cluster_status,
42-
)
43-
from codeflare_sdk.common.kubernetes_cluster import (
44-
TokenAuthentication,
45-
Authentication,
46-
KubeConfigFileAuthentication,
47-
config_check,
4863
)
64+
from codeflare_sdk.ray.cluster.generate_yaml import gen_names, is_openshift_cluster
4965
from codeflare_sdk.ray.cluster.pretty_print import (
50-
print_no_resources_found,
5166
print_app_wrappers_status,
5267
print_cluster_status,
5368
print_clusters,
54-
)
55-
from codeflare_sdk.ray.appwrapper.status import (
56-
AppWrapper,
57-
AppWrapperStatus,
69+
print_no_resources_found,
5870
)
5971
from codeflare_sdk.ray.cluster.status import (
72+
CodeFlareClusterStatus,
6073
RayCluster,
6174
RayClusterStatus,
62-
CodeFlareClusterStatus,
6375
)
64-
from codeflare_sdk.common.utils.generate_cert import (
65-
generate_ca_cert,
66-
generate_tls_cert,
67-
export_env,
68-
)
69-
7076
from tests.unit_test_support import (
71-
createClusterWithConfig,
7277
createClusterConfig,
78+
createClusterWithConfig,
7379
createClusterWrongType,
7480
get_package_and_version,
7581
)
7682

77-
import codeflare_sdk.common.kubernetes_cluster.kube_api_helpers
78-
from codeflare_sdk.ray.cluster.generate_yaml import (
79-
gen_names,
80-
is_openshift_cluster,
81-
)
82-
83-
import codeflare_sdk.common.widgets.widgets as cf_widgets
84-
import pandas as pd
85-
86-
import openshift
87-
from openshift.selector import Selector
88-
import ray
89-
import pytest
90-
import yaml
91-
from unittest.mock import MagicMock, patch
92-
from pytest_mock import MockerFixture
93-
from ray.job_submission import JobSubmissionClient
94-
from codeflare_sdk.ray.client.ray_jobs import RayJobClient
95-
9683
# For mocking openshift client results
9784
fake_res = openshift.Result("fake")
9885

@@ -156,7 +143,7 @@ def test_token_auth_creation():
156143
assert token_auth.skip_tls == False
157144
assert token_auth.ca_cert_path == f"{parent}/tests/auth-test.crt"
158145

159-
except Exception as e:
146+
except Exception:
160147
assert 0 == 1
161148

162149

@@ -204,7 +191,7 @@ def test_config_check_no_config_file(mocker):
204191
mocker.patch("codeflare_sdk.common.kubernetes_cluster.auth.config_path", None)
205192
mocker.patch("codeflare_sdk.common.kubernetes_cluster.auth.api_client", None)
206193

207-
with pytest.raises(PermissionError) as e:
194+
with pytest.raises(PermissionError):
208195
config_check()
209196

210197

@@ -282,7 +269,7 @@ def test_config_creation():
282269

283270
def test_config_creation_wrong_type():
284271
with pytest.raises(TypeError):
285-
config = createClusterWrongType()
272+
createClusterWrongType()
286273

287274

288275
def test_cluster_creation(mocker):
@@ -890,7 +877,7 @@ def test_ray_job_wrapping(mocker):
890877
def test_print_no_resources(capsys):
891878
try:
892879
print_no_resources_found()
893-
except:
880+
except Exception:
894881
assert 1 == 0
895882
captured = capsys.readouterr()
896883
assert captured.out == (
@@ -903,7 +890,7 @@ def test_print_no_resources(capsys):
903890
def test_print_no_cluster(capsys):
904891
try:
905892
print_cluster_status(None)
906-
except:
893+
except Exception:
907894
assert 1 == 0
908895
captured = capsys.readouterr()
909896
assert captured.out == (
@@ -924,7 +911,7 @@ def test_print_appwrappers(capsys):
924911
)
925912
try:
926913
print_app_wrappers_status([aw1, aw2])
927-
except:
914+
except Exception:
928915
assert 1 == 0
929916
captured = capsys.readouterr()
930917
assert captured.out == (
@@ -997,7 +984,7 @@ def test_ray_details(mocker, capsys):
997984
print_clusters([ray1, ray2])
998985
print_cluster_status(ray1)
999986
print_cluster_status(ray2)
1000-
except:
987+
except Exception:
1001988
assert 0 == 1
1002989
captured = capsys.readouterr()
1003990
assert captured.out == (
@@ -2602,13 +2589,14 @@ def test_AWManager_submit_remove(mocker, capsys):
26022589
assert testaw.submitted == False
26032590

26042591

2605-
from cryptography.x509 import load_pem_x509_certificate
26062592
import base64
2593+
26072594
from cryptography.hazmat.primitives.serialization import (
2608-
load_pem_private_key,
26092595
Encoding,
26102596
PublicFormat,
2597+
load_pem_private_key,
26112598
)
2599+
from cryptography.x509 import load_pem_x509_certificate
26122600

26132601

26142602
def test_generate_ca_cert():

0 commit comments

Comments
 (0)