-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprerequisites_check_test.py
More file actions
86 lines (68 loc) · 2.32 KB
/
prerequisites_check_test.py
File metadata and controls
86 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Tests for keras_remote.cli.prerequisites_check — tool availability checks."""
from unittest import mock
import click
from absl.testing import absltest
from keras_remote.cli.prerequisites_check import (
check_gcloud,
check_gcloud_auth,
check_gke_auth_plugin,
check_kubectl,
)
_MODULE = "keras_remote.cli.prerequisites_check"
class TestToolChecks(absltest.TestCase):
"""Tests for CLI-only tool checks (kubectl)."""
def test_kubectl_present(self):
with mock.patch("shutil.which", return_value="/usr/bin/kubectl"):
check_kubectl()
def test_kubectl_missing(self):
with (
mock.patch("shutil.which", return_value=None),
self.assertRaisesRegex(click.ClickException, "kubectl not found"),
):
check_kubectl()
class TestDelegatedChecks(absltest.TestCase):
"""Tests for checks that delegate to keras_remote.credentials."""
def test_check_gcloud_delegates(self):
with mock.patch(f"{_MODULE}.credentials.ensure_gcloud"):
check_gcloud()
def test_check_gcloud_converts_error(self):
with (
mock.patch(
f"{_MODULE}.credentials.ensure_gcloud",
side_effect=RuntimeError("gcloud CLI not found"),
),
self.assertRaisesRegex(click.ClickException, "gcloud CLI not found"),
):
check_gcloud()
def test_check_gke_auth_plugin_delegates(self):
with mock.patch(f"{_MODULE}.credentials.ensure_gke_auth_plugin"):
check_gke_auth_plugin()
def test_check_gke_auth_plugin_converts_error(self):
with (
mock.patch(
f"{_MODULE}.credentials.ensure_gke_auth_plugin",
side_effect=RuntimeError("Failed to install gke-gcloud-auth-plugin"),
),
self.assertRaisesRegex(
click.ClickException,
"Failed to install gke-gcloud-auth-plugin",
),
):
check_gke_auth_plugin()
def test_check_gcloud_auth_delegates(self):
with mock.patch(f"{_MODULE}.credentials.ensure_adc"):
check_gcloud_auth()
def test_check_gcloud_auth_converts_error(self):
with (
mock.patch(
f"{_MODULE}.credentials.ensure_adc",
side_effect=RuntimeError("Failed to configure Application Default"),
),
self.assertRaisesRegex(
click.ClickException,
"Failed to configure Application Default",
),
):
check_gcloud_auth()
if __name__ == "__main__":
absltest.main()