-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest_utils.py
More file actions
175 lines (159 loc) · 5.83 KB
/
test_utils.py
File metadata and controls
175 lines (159 loc) · 5.83 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright (c) Contributors to the aswf-docker Project. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Tests for the utility commands
"""
import unittest
import logging
import tempfile
import os
from click.testing import CliRunner
from aswfdocker import utils, index, constants
from aswfdocker.cli import aswfdocker
class TestUtils(unittest.TestCase):
def test_get_docker_org(self):
self.assertEqual(utils.get_docker_org("", ""), "aswftesting")
self.assertEqual(
utils.get_docker_org(
constants.MAIN_GITHUB_ASWF_DOCKER_URL, "refs/heads/master",
),
"aswf",
)
self.assertEqual(
utils.get_docker_org(
constants.MAIN_GITHUB_ASWF_DOCKER_URL, "refs/heads/testing",
),
"aswftesting",
)
self.assertEqual(
utils.get_docker_org(
"https://github.com/randomfork/aswf-docker", "refs/heads/master"
),
"aswflocaltesting",
)
self.assertEqual(
utils.get_docker_org(
"https://github.com/randomfork/aswf-docker", "refs/heads/randombranch"
),
"aswflocaltesting",
)
def test_get_docker_push(self):
self.assertFalse(utils.get_docker_push("", ""))
self.assertTrue(
utils.get_docker_push(
constants.MAIN_GITHUB_ASWF_DOCKER_URL, "refs/heads/master",
)
)
self.assertTrue(
utils.get_docker_push(
constants.MAIN_GITHUB_ASWF_DOCKER_URL, "refs/heads/testing",
)
)
self.assertFalse(
utils.get_docker_push(
"https://github.com/randomfork/aswf-docker", "refs/heads/master"
)
)
self.assertFalse(
utils.get_docker_push(
"https://github.com/randomfork/aswf-docker", "refs/heads/randombranch"
)
)
def test_image_def_from_name(self):
with self.assertRaises(RuntimeError):
utils.get_image_spec("aswf/ci-package-openexr_2018")
self.assertEqual(
utils.get_image_spec("aswftesting/ci-common:1"),
("aswftesting", constants.ImageType.CI_IMAGE, "common", "1"),
)
self.assertEqual(
utils.get_image_spec("aswftesting/rt-base:2019"),
("aswftesting", constants.ImageType.RT_IMAGE, "base", "2019"),
)
self.assertEqual(
utils.get_image_spec("aswf/ci-package-openexr:2018"),
("aswf", constants.ImageType.PACKAGE, "openexr", "2018"),
)
self.assertEqual(
utils.get_image_spec("refs/tags/aswf/ci-package-openexr/2018"),
("aswf", constants.ImageType.PACKAGE, "openexr", "2018"),
)
self.assertEqual(
utils.get_image_spec("aswf/ci-package-clang:1-clang6"),
("aswf", constants.ImageType.PACKAGE, "clang", "1-clang6"),
)
class TestUtilsCli(unittest.TestCase):
def setUp(self):
self._log_handlers = logging.getLogger("").handlers
logging.getLogger("").handlers = []
self.maxDiff = None
def tearDown(self):
logging.getLogger("").handlers = self._log_handlers
def test_cli_getdockerorg(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["getdockerorg"])
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "aswftesting")
def test_cli_getdockerorgforced(self):
runner = CliRunner()
result = runner.invoke(
aswfdocker.cli,
[
"--repo-uri",
"https://github.com/AcademySoftwareFoundation/aswf-docker",
"--source-branch",
"refs/heads/master",
"getdockerorg",
],
)
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "aswf")
def test_cli_getdockerpush(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["getdockerpush"])
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.output, "false")
def test_cli_download(self):
runner = CliRunner()
with tempfile.TemporaryDirectory() as tmpdirname:
result = runner.invoke(
aswfdocker.cli,
[
"--repo-root",
tmpdirname,
"download",
"--package",
"tbb",
"--version",
"2019",
],
catch_exceptions=False,
)
self.assertEqual(result.exit_code, 0)
path = os.path.join(tmpdirname, "packages", "2019", "tbb.tar.gz")
self.assertEqual(result.output, path)
self.assertTrue(os.path.exists(result.output))
def test_cli_packages(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["packages"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
pkgs = result.output.split("\n")
self.assertGreater(len(pkgs), 20)
clang_version = list(
index.Index().iter_versions(constants.ImageType.PACKAGE, "clang")
)[0]
self.assertEqual(
pkgs[0], f"common/ci-package-clang:{clang_version}",
)
def test_cli_images(self):
runner = CliRunner()
result = runner.invoke(aswfdocker.cli, ["images"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
imgs = result.output.split("\n")
self.assertGreater(len(imgs), 15)
common_version = list(
index.Index().iter_versions(constants.ImageType.CI_IMAGE, "common")
)[0]
self.assertEqual(
imgs[0], f"common/ci-common:{common_version}",
)