Skip to content

Commit d22f60f

Browse files
authored
Merge pull request #211 from roaffix/feature/move-tests-to-rootdir
Move tests to root dir. Minor setup refactoring
2 parents 2a48a39 + 632cb8f commit d22f60f

22 files changed

+322
-257
lines changed

arrayfire/tests/simple/__init__.py

-24
This file was deleted.

arrayfire/tests/simple_tests.py

-27
This file was deleted.

setup.cfg

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[metadata]
2+
name = arrayfire
3+
version = 3.6.20181017
4+
description = Python bindings for ArrayFire
5+
licence = BSD
6+
long_description = file: README.md
7+
maintainer = Pavan Yalamanchili
8+
maintainer_email = [email protected]
9+
url = http://arrayfire.com
10+
classifiers =
11+
Programming Language :: Python
12+
Programming Language :: Python :: 2.7
13+
Programming Language :: Python :: 3
14+
Programming Language :: Python :: 3.6
15+
16+
[options]
17+
packages = find:
18+
19+
[options.packages.find]
20+
exclude =
21+
examples
22+
tests
23+
24+
[flake8]
25+
application-import-names = arrayfire
26+
import-order-style = pep8
27+
max-line-length = 119

setup.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
#######################################################
44
# Copyright (c) 2015, ArrayFire
@@ -9,19 +9,8 @@
99
# http://arrayfire.com/licenses/BSD-3-Clause
1010
########################################################
1111

12-
from setuptools import setup, find_packages
13-
#from __af_version__ import full_version
12+
# TODO: Look for af libraries during setup
1413

15-
#TODO:
16-
#1) Look for af libraries during setup
14+
from setuptools import setup
1715

18-
setup(
19-
author="Pavan Yalamanchili",
20-
author_email="[email protected]",
21-
name="arrayfire",
22-
version="3.6.20181017",
23-
description="Python bindings for ArrayFire",
24-
license="BSD",
25-
url="http://arrayfire.com",
26-
packages=find_packages()
27-
)
16+
setup()

arrayfire/tests/__init__.py renamed to tests/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
#######################################################
24
# Copyright (c) 2015, ArrayFire
35
# All rights reserved.

arrayfire/tests/__main__.py renamed to tests/__main__.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
#######################################################
24
# Copyright (c) 2015, ArrayFire
35
# All rights reserved.
@@ -10,35 +12,38 @@
1012
from __future__ import absolute_import
1113

1214
import sys
13-
from .simple_tests import *
15+
16+
from . import simple
1417

1518
tests = {}
1619
tests['simple'] = simple.tests
1720

21+
1822
def assert_valid(name, name_list, name_str):
1923
is_valid = any([name == val for val in name_list])
20-
if not is_valid:
21-
err_str = "The first argument needs to be a %s name\n" % name_str
22-
err_str += "List of supported %ss: %s" % (name_str, str(list(name_list)))
23-
raise RuntimeError(err_str)
24+
if is_valid:
25+
return
26+
err_str = "The first argument needs to be a %s name\n" % name_str
27+
err_str += "List of supported %ss: %s" % (name_str, str(list(name_list)))
28+
raise RuntimeError(err_str)
2429

25-
if __name__ == "__main__":
2630

31+
if __name__ == "__main__":
2732
module_name = None
2833
num_args = len(sys.argv)
2934

30-
if (num_args > 1):
35+
if num_args > 1:
3136
module_name = sys.argv[1].lower()
3237
assert_valid(sys.argv[1].lower(), tests.keys(), "module")
3338

34-
if (module_name is None):
39+
if module_name is None:
3540
for name in tests:
3641
tests[name].run()
3742
else:
3843
test = tests[module_name]
3944
test_list = None
4045

41-
if (num_args > 2):
46+
if num_args > 2:
4247
test_list = sys.argv[2:]
4348
for test_name in test_list:
4449
assert_valid(test_name.lower(), test.keys(), "test")

tests/simple/__init__.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
#######################################################
4+
# Copyright (c) 2015, ArrayFire
5+
# All rights reserved.
6+
#
7+
# This file is distributed under 3-clause BSD license.
8+
# The complete license agreement can be obtained at:
9+
# http://arrayfire.com/licenses/BSD-3-Clause
10+
########################################################
11+
12+
from ._util import tests
13+
from .algorithm import simple_algorithm
14+
from .arith import simple_arith
15+
from .array_test import simple_array
16+
from .blas import simple_blas
17+
from .data import simple_data
18+
from .device import simple_device
19+
from .image import simple_image
20+
from .index import simple_index
21+
from .interop import simple_interop
22+
from .lapack import simple_lapack
23+
from .random import simple_random
24+
from .signal import simple_signal
25+
from .sparse import simple_sparse
26+
from .statistics import simple_statistics
27+
28+
__all__ = [
29+
"tests",
30+
"simple_algorithm",
31+
"simple_arith",
32+
"simple_array",
33+
"simple_blas",
34+
"simple_data",
35+
"simple_device",
36+
"simple_image",
37+
"simple_index",
38+
"simple_interop",
39+
"simple_lapack",
40+
"simple_random",
41+
"simple_signal",
42+
"simple_sparse",
43+
"simple_statistics"
44+
]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
#######################################################
24
# Copyright (c) 2015, ArrayFire
35
# All rights reserved.
@@ -6,13 +8,13 @@
68
# The complete license agreement can be obtained at:
79
# http://arrayfire.com/licenses/BSD-3-Clause
810
########################################################
9-
import traceback
11+
1012
import logging
11-
import arrayfire as af
1213
import sys
14+
import traceback
1315

14-
class _simple_test_dict(dict):
1516

17+
class _simple_test_dict(dict):
1618
def __init__(self):
1719
self.print_str = "Simple %16s: %s"
1820
self.failed = False
@@ -21,7 +23,7 @@ def __init__(self):
2123
def run(self, name_list=None, verbose=False):
2224
test_list = name_list if name_list is not None else self.keys()
2325
for key in test_list:
24-
self.print_log = ''
26+
self.print_log = ""
2527
try:
2628
test = self[key]
2729
except KeyError:
@@ -31,27 +33,30 @@ def run(self, name_list=None, verbose=False):
3133
try:
3234
test(verbose)
3335
print(self.print_str % (key, "PASSED"))
34-
except Exception as e:
36+
except Exception:
3537
print(self.print_str % (key, "FAILED"))
3638
self.failed = True
37-
if (not verbose):
39+
if not verbose:
3840
print(tests.print_log)
3941
logging.error(traceback.format_exc())
4042

41-
if (self.failed):
43+
if self.failed:
4244
sys.exit(1)
4345

46+
4447
tests = _simple_test_dict()
4548

49+
4650
def print_func(verbose):
4751
def print_func_impl(*args):
48-
_print_log = ''
52+
_print_log = ""
4953
for arg in args:
5054
_print_log += str(arg) + '\n'
51-
if (verbose):
55+
if verbose:
5256
print(_print_log)
5357
tests.print_log += _print_log
5458
return print_func_impl
5559

60+
5661
def display_func(verbose):
5762
return print_func(verbose)

arrayfire/tests/simple/algorithm.py renamed to tests/simple/algorithm.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
2+
23
#######################################################
34
# Copyright (c) 2015, ArrayFire
45
# All rights reserved.
@@ -9,18 +10,19 @@
910
########################################################
1011

1112
import arrayfire as af
13+
1214
from . import _util
1315

14-
def simple_algorithm(verbose = False):
16+
17+
def simple_algorithm(verbose=False):
1518
display_func = _util.display_func(verbose)
16-
print_func = _util.print_func(verbose)
19+
print_func = _util.print_func(verbose)
1720

1821
a = af.randu(3, 3)
1922
k = af.constant(1, 3, 3, dtype=af.Dtype.u32)
2023
af.eval(k)
2124

22-
print_func(af.sum(a), af.product(a), af.min(a), af.max(a),
23-
af.count(a), af.any_true(a), af.all_true(a))
25+
print_func(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a))
2426

2527
display_func(af.sum(a, 0))
2628
display_func(af.sum(a, 1))
@@ -58,27 +60,27 @@ def simple_algorithm(verbose = False):
5860
b = (a > 0.1) * a
5961
c = (a > 0.4) * a
6062
d = b / c
61-
print_func(af.sum(d));
62-
print_func(af.sum(d, nan_val=0.0));
63-
display_func(af.sum(d, dim=0, nan_val=0.0));
63+
print_func(af.sum(d))
64+
print_func(af.sum(d, nan_val=0.0))
65+
display_func(af.sum(d, dim=0, nan_val=0.0))
6466

65-
val,idx = af.sort_index(a, is_ascending=True)
67+
val, idx = af.sort_index(a, is_ascending=True)
6668
display_func(val)
6769
display_func(idx)
68-
val,idx = af.sort_index(a, is_ascending=False)
70+
val, idx = af.sort_index(a, is_ascending=False)
6971
display_func(val)
7072
display_func(idx)
7173

72-
b = af.randu(3,3)
73-
keys,vals = af.sort_by_key(a, b, is_ascending=True)
74+
b = af.randu(3, 3)
75+
keys, vals = af.sort_by_key(a, b, is_ascending=True)
7476
display_func(keys)
7577
display_func(vals)
76-
keys,vals = af.sort_by_key(a, b, is_ascending=False)
78+
keys, vals = af.sort_by_key(a, b, is_ascending=False)
7779
display_func(keys)
7880
display_func(vals)
7981

80-
c = af.randu(5,1)
81-
d = af.randu(5,1)
82+
c = af.randu(5, 1)
83+
d = af.randu(5, 1)
8284
cc = af.set_unique(c, is_sorted=False)
8385
dd = af.set_unique(af.sort(d), is_sorted=True)
8486
display_func(cc)
@@ -90,4 +92,5 @@ def simple_algorithm(verbose = False):
9092
display_func(af.set_intersect(cc, cc, is_unique=True))
9193
display_func(af.set_intersect(cc, cc, is_unique=False))
9294

93-
_util.tests['algorithm'] = simple_algorithm
95+
96+
_util.tests["algorithm"] = simple_algorithm

0 commit comments

Comments
 (0)