|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | # -------------------------------------------------------------------------------------------- |
5 | 5 |
|
| 6 | +""" Test the index and the wheels from both the index and from source extensions in repository """ |
| 7 | + |
6 | 8 | from __future__ import print_function |
7 | 9 |
|
8 | 10 | import os |
|
12 | 14 | import zipfile |
13 | 15 | import hashlib |
14 | 16 | import shutil |
| 17 | +import subprocess |
15 | 18 | from util import get_repo_root |
16 | 19 | from wheel.install import WHEEL_INFO_RE |
17 | 20 |
|
18 | 21 | INDEX_PATH = os.path.join(get_repo_root(), 'src', 'index.json') |
| 22 | +SRC_PATH = os.path.join(get_repo_root(), 'src') |
| 23 | + |
| 24 | +# Extensions to skip dep. check. Aim to keep this list empty. |
| 25 | +SKIP_DEP_CHECK = ['azure_cli_iot_ext'] |
19 | 26 |
|
20 | 27 |
|
21 | 28 | def catch_dup_keys(pairs): |
@@ -62,6 +69,9 @@ def get_extension_modname(ext_dir): |
62 | 69 | EXTENSIONS_MOD_PREFIX = 'azext_' |
63 | 70 | pos_mods = [n for n in os.listdir(ext_dir) |
64 | 71 | if n.startswith(EXTENSIONS_MOD_PREFIX) and os.path.isdir(os.path.join(ext_dir, n))] |
| 72 | + if len(pos_mods) != 1: |
| 73 | + raise AssertionError("Expected 1 module to load starting with " |
| 74 | + "'{}': got {}".format(EXTENSIONS_MOD_PREFIX, pos_mods)) |
65 | 75 | return pos_mods[0] |
66 | 76 |
|
67 | 77 |
|
@@ -180,8 +190,42 @@ def test_metadata(self): |
180 | 190 | "Metadata for {} in index doesn't match the expected of: \n" |
181 | 191 | "{}".format(item['filename'], json.dumps(metadata, indent=2, sort_keys=True, |
182 | 192 | separators=(',', ': ')))) |
| 193 | + run_requires = metadata.get('run_requires') |
| 194 | + if run_requires and ext_name not in SKIP_DEP_CHECK: |
| 195 | + deps = run_requires[0]['requires'] |
| 196 | + self.assertTrue(all(not dep.startswith('azure-') for dep in deps), |
| 197 | + "Dependencies of {} use disallowed extension dependencies. " |
| 198 | + "Remove these dependencies: {}".format(item['filename'], deps)) |
183 | 199 | shutil.rmtree(extensions_dir) |
184 | 200 |
|
185 | 201 |
|
| 202 | +class TestSourceWheels(unittest.TestCase): |
| 203 | + |
| 204 | + def test_source_wheels(self): |
| 205 | + # Test we can build all sources into wheels and that metadata from the wheel is valid |
| 206 | + from subprocess import PIPE |
| 207 | + built_whl_dir = tempfile.mkdtemp() |
| 208 | + source_extensions = [os.path.join(SRC_PATH, n) for n in os.listdir(SRC_PATH) |
| 209 | + if os.path.isdir(os.path.join(SRC_PATH, n))] |
| 210 | + for s in source_extensions: |
| 211 | + try: |
| 212 | + subprocess.check_call(['python', 'setup.py', 'bdist_wheel', '-q', '-d', built_whl_dir], |
| 213 | + cwd=s, stdout=PIPE, stderr=PIPE) |
| 214 | + except subprocess.CalledProcessError as err: |
| 215 | + self.fail("Unable to build extension {} : {}".format(s, err)) |
| 216 | + for filename in os.listdir(built_whl_dir): |
| 217 | + ext_file = os.path.join(built_whl_dir, filename) |
| 218 | + ext_dir = tempfile.mkdtemp(dir=built_whl_dir) |
| 219 | + ext_name = WHEEL_INFO_RE(filename).groupdict().get('name') |
| 220 | + metadata = get_ext_metadata(ext_dir, ext_file, ext_name) |
| 221 | + run_requires = metadata.get('run_requires') |
| 222 | + if run_requires and ext_name not in SKIP_DEP_CHECK: |
| 223 | + deps = run_requires[0]['requires'] |
| 224 | + self.assertTrue(all(not dep.startswith('azure-') for dep in deps), |
| 225 | + "Dependencies of {} use disallowed extension dependencies. " |
| 226 | + "Remove these dependencies: {}".format(filename, deps)) |
| 227 | + shutil.rmtree(built_whl_dir) |
| 228 | + |
| 229 | + |
186 | 230 | if __name__ == '__main__': |
187 | 231 | unittest.main() |
0 commit comments