forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_import.py
55 lines (41 loc) · 1.47 KB
/
test_import.py
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
""" Test if we can import everything from conda.
This basically tests syntax correctness and whether the internal imports work.
Created to test py3k compatibility.
"""
from __future__ import print_function, division, absolute_import
import os
import sys
import unittest
import conda
PREFIX = os.path.dirname(os.path.abspath(conda.__file__))
class TestImportAllConda(unittest.TestCase):
def _test_import(self, subpackage):
# Prepare
prefix = PREFIX
module_prefix = 'conda'
if subpackage:
prefix = os.path.join(prefix, subpackage)
module_prefix = '%s.%s' % (module_prefix, subpackage)
# Try importing root
__import__(module_prefix)
# Import each module in given (sub)package
for fname in os.listdir(prefix):
# Discard files that are not of interest
if fname.startswith('__'):
continue
elif not fname.endswith('.py'):
continue
elif fname.startswith('windows') and sys.platform != 'win32':
continue
# Import
modname = module_prefix + '.' + fname.split('.')[0]
print('importing', modname)
__import__(modname)
def test_import_root(self):
self._test_import('')
def test_import_cli(self):
self._test_import('cli')
def test_import_progressbar(self):
self._test_import('progressbar')
if __name__ == '__main__':
unittest.main()