forked from starlingx-staging/x.stx-distcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_ddt_tests.py
108 lines (91 loc) · 3.33 KB
/
setup_ddt_tests.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
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
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
def get_data_repo():
tmp_dir = os.environ['DATA_DIRECTORY']
return os.path.abspath(tmp_dir)
# Search the data repository to get all sub repositories
# Each sub repository will contain a configuration to run tests with
def get_cfgs():
return [d for d in os.listdir(data_dir)
if os.path.isdir(os.path.join(data_dir, d))]
# Some data sets may not have the correct database sources needed for the
# unit tests, this is specified in the tox file and filtered out here
def filter_cfgs(cfgs_full):
cfgs_usable = []
required = os.environ.get('REQUIRED_REPOS')
if required:
for cfg in cfgs_full:
subdirs = os.listdir('%s/%s' % (data_dir, cfg))
include = True
for d in required.split(','):
if d not in subdirs:
include = False
break
if include:
cfgs_usable.append(cfg)
else:
cfgs_usable = cfgs
return cfgs_usable
# writes the current data set source to a file within the tests default data
# repo this will be picked up when running tests to create the path to the
# current test configuration of the ddt framework to unpack
def set_current_test_data(cfg):
file = open('.current.cfg', 'w')
file.write('%s/%s' % (data_dir, cfg))
file.close()
def print_divider(width, txt):
width_new = (int(width) - len(txt)) / 2
print '%s%s%s' % ('_' * width_new, txt, '_' * width_new)
def get_divider_size():
width = 80
try:
rows, width = os.popen('stty size', 'r').read().split()
except Exception:
pass
return width
# Get all repository information
data_dir = get_data_repo()
print 'Using %s as data directory' % data_dir
cfgs = get_cfgs()
cfgs_usable = filter_cfgs(cfgs)
print 'Required repo databases: %s' % os.environ.get('REQUIRED_REPOS')
print "Test data folder(s) found: %s" % cfgs
if len(cfgs_usable) == 0:
print 'No usable data sets found'
exit
print 'Usable data folder(s): %s' % cfgs_usable
if os.environ.get('SINGLE_REPO') == 'True':
cfgs_usable = [cfgs_usable[0]]
print 'Restricting to single data set: %s' % cfgs_usable[0]
print ''
# Loop through all configurations and run unit tests with each
columns = get_divider_size()
for cfg in cfgs_usable:
print_divider(columns, cfg)
print 'Running unit tests with test data: %s' % cfg
set_current_test_data(cfg)
setuptools.setup(
setup_requires=['pbr>=1.8.0'],
pbr=True)
print ''