1 """A set of tools for use in integration tests.""" 6 from hashlib
import sha1
9 from nose.tools
import assert_equal
12 CYCLUS_HAS_COIN =
None 15 if sys.version_info[0] >= 3:
16 str_types = (bytes, str)
18 str_types = (str, unicode)
21 return int(sha1(x.encode()).hexdigest(), 16)
25 for i
in range(4, -1, -1):
26 h, ind[i] = divmod(h, 2**32)
29 sha1array =
lambda x: np.array(
idx(
hasher(x)), np.uint32)
32 """Checks if hdf5 database contains the specified tables. 34 return all([t
in db.root
for t
in tables])
37 """Finds ids of the specified data located in the specified data_table, 38 and extracts the corresponding id from the specified id_table. 41 for i, d
in enumerate(data_table):
42 if isinstance(d, np.ndarray)
and isinstance(data, np.ndarray):
44 ids.append(id_table[i])
45 elif isinstance(d, np.ndarray)
and not isinstance(data, np.ndarray):
47 ids.append(id_table[i])
49 ids.append(id_table[i])
53 """Finds exit times of the specified agent from the exit table. 57 for index
in exit_table[
"AgentId"]:
59 exit_times.append(exit_table[
"ExitTime"][i])
66 """Runs cyclus with various inputs and creates output databases 70 cmd = [cyclus,
"-o", out_path,
"--input-file", in_path]
75 """Runs a command in a subprocess and verifies that it executed properly. 77 if not isinstance(args, str_types):
79 print(
"TESTING: running command in {0}:\n\n{1}\n".format(cwd, args))
80 env = dict(os.environ)
81 env[
'_'] = subprocess.check_output([
'which',
'cyclus'], cwd=cwd).strip()
82 with tempfile.NamedTemporaryFile()
as f:
83 rtn = subprocess.call(args, shell=
True, cwd=cwd, stdout=f, stderr=f, env=env)
86 print(
"STDOUT + STDERR:\n\n" + f.read().decode())
92 global CYCLUS_HAS_COIN
93 if CYCLUS_HAS_COIN
is not None:
94 return CYCLUS_HAS_COIN
95 s = subprocess.check_output([
'cyclus',
'--version'], universal_newlines=
True)
96 s = s.strip().replace(
'Dependencies:',
'')
97 m = {k.strip(): v.strip()
for k,v
in [line.split()[:2]
for line
in s.splitlines()
99 CYCLUS_HAS_COIN = m[
'Coin-Cbc'] !=
'-1' 100 return CYCLUS_HAS_COIN
cycamore::GrowthRegion int
def run_cyclus(cyclus, cwd, in_path, out_path)
def exit_times(agent_id, exit_table)
def check_cmd(args, cwd, holdsrtn)
def table_exist(db, tables)
def find_ids(data, data_table, id_table)