implement varargs (#83)

* implement varargs

* clean up varargs
This commit is contained in:
Philipp Moritz
2016-06-04 16:22:10 -07:00
parent 2b52b91acb
commit f9aeb5d018
6 changed files with 74 additions and 24 deletions
+17 -1
View File
@@ -191,7 +191,8 @@ class APITest(unittest.TestCase):
def testKeywordArgs(self):
test_dir = os.path.dirname(os.path.abspath(__file__))
test_path = os.path.join(test_dir, "testrecv.py")
services.start_singlenode_cluster(return_drivers=False, num_workers_per_objstore=3, worker_path=test_path)
services.start_singlenode_cluster(return_drivers=False, num_workers_per_objstore=1, worker_path=test_path)
x = test_functions.keyword_fct1(1)
self.assertEqual(halo.pull(x), "1 hello")
x = test_functions.keyword_fct1(1, "hi")
@@ -225,6 +226,21 @@ class APITest(unittest.TestCase):
services.cleanup()
def testVariableNumberOfArgs(self):
test_dir = os.path.dirname(os.path.abspath(__file__))
test_path = os.path.join(test_dir, "testrecv.py")
services.start_singlenode_cluster(return_drivers=False, num_workers_per_objstore=1, worker_path=test_path)
x = test_functions.varargs_fct1(0, 1, 2)
self.assertEqual(halo.pull(x), "0 1 2")
x = test_functions.varargs_fct2(0, 1, 2)
self.assertEqual(halo.pull(x), "1 2")
self.assertTrue(test_functions.kwargs_exception_thrown)
self.assertTrue(test_functions.varargs_and_kwargs_exception_thrown)
services.cleanup()
class ReferenceCountingTest(unittest.TestCase):
def testDeallocation(self):
+26
View File
@@ -52,3 +52,29 @@ def keyword_fct2(a="hello", b="world"):
@halo.remote([int, int, str, str], [str])
def keyword_fct3(a, b, c="hello", d="world"):
return "{} {} {} {}".format(a, b, c, d)
# Test variable numbers of arguments
@halo.remote([int], [str])
def varargs_fct1(*a):
return " ".join(map(str, a))
@halo.remote([int, int], [str])
def varargs_fct2(a, *b):
return " ".join(map(str, b))
try:
@halo.remote([int], [])
def kwargs_throw_exception(**c):
return ()
kwargs_exception_thrown = False
except:
kwargs_exception_thrown = True
try:
@halo.remote([int, str, int], [str])
def varargs_and_kwargs_throw_exception(a, b="hi", *c):
return "{} {} {}".format(a, b, c)
varargs_and_kwargs_exception_thrown = False
except:
varargs_and_kwargs_exception_thrown = True