forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_util.py
More file actions
62 lines (49 loc) · 1.63 KB
/
_util.py
File metadata and controls
62 lines (49 loc) · 1.63 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
#!/usr/bin/env python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import logging
import sys
import traceback
class _simple_test_dict(dict):
def __init__(self):
self.print_str = "Simple %16s: %s"
self.failed = False
super(_simple_test_dict, self).__init__()
def run(self, name_list=None, verbose=False):
test_list = name_list if name_list is not None else self.keys()
for key in test_list:
self.print_log = ""
try:
test = self[key]
except KeyError:
print(self.print_str % (key, "NOTFOUND"))
continue
try:
test(verbose)
print(self.print_str % (key, "PASSED"))
except Exception:
print(self.print_str % (key, "FAILED"))
self.failed = True
if not verbose:
print(tests.print_log)
logging.error(traceback.format_exc())
if self.failed:
sys.exit(1)
tests = _simple_test_dict()
def print_func(verbose):
def print_func_impl(*args):
_print_log = ""
for arg in args:
_print_log += str(arg) + '\n'
if verbose:
print(_print_log)
tests.print_log += _print_log
return print_func_impl
def display_func(verbose):
return print_func(verbose)