cres = compile_isolated(pyfunc, [types.int16, types.int16]) cfunc = cres.entry_point self.assertTrue(cfunc(1, 6), pyfunc(1, 6)) @tag('important') def test_loop3_int32(self): pyfunc = loop3 cres = compile_isolated(pyfunc, [types.int32] * 3) cfunc = cres.entry_point arglist = [ (1, 2, 1), (2, 8, 3), (-10, -11, -10), (-10, -10, -2), ] for args in arglist: self.assertEqual(cfunc(*args), pyfunc(*args)) @tag('important') @unittest.skipIf(sys.version_info >= (3,), "test is Python 2-specific") def test_xrange(self): pyfunc = xrange_usecase cres = compile_isolated(pyfunc, (types.int32,)) cfunc = cres.entry_point self.assertEqual(cfunc(5), pyfunc(5)) if __name__ == '__main__': unittest.main()
return "bar" def test_string_eq(self): @udf(BooleanVal(FunctionContext, StringVal)) def fn(context, a): if a == "foo": return True elif a == "bar": return False else: return None def test_return_string_literal(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return "foo" def test_return_empty_string(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return "" def test_string_len(self): @udf(IntVal(FunctionContext, StringVal)) def fn(context, a): return len(a) if __name__ == "__main__": unittest.main(verbosity=2)
with self.assertRaises(ValueError): compute_fingerprint([]) def test_sets(self): distinct = DistinctChecker() s = compute_fingerprint(set([1])) self.assertEqual(compute_fingerprint(set([2, 3])), s) distinct.add(s) distinct.add(compute_fingerprint([1])) distinct.add(compute_fingerprint(set([1j]))) distinct.add(compute_fingerprint(set([4.5, 6.7]))) distinct.add(compute_fingerprint(set([(1,)]))) with self.assertRaises(ValueError): compute_fingerprint(set()) with self.assertRaises(NotImplementedError): compute_fingerprint(frozenset([2, 3])) def test_complicated_type(self): # Generating a large fingerprint t = None for i in range(1000): t = (t,) s = compute_fingerprint(t) if __name__ == '__main__': unittest.main()
cfunc() def test_unpack_tuple_too_small(self): self.check_unpack_error(unpack_tuple_too_small) def test_unpack_tuple_too_small_npm(self): self.check_unpack_error(unpack_tuple_too_small, no_pyobj_flags) def test_unpack_tuple_too_large(self): self.check_unpack_error(unpack_tuple_too_large) def test_unpack_tuple_too_large_npm(self): self.check_unpack_error(unpack_tuple_too_large, no_pyobj_flags) def test_unpack_range_too_small(self): self.check_unpack_error(unpack_range_too_small) def test_unpack_range_too_small_npm(self): self.check_unpack_error(unpack_range_too_small, no_pyobj_flags) def test_unpack_range_too_large(self): self.check_unpack_error(unpack_range_too_large) def test_unpack_range_too_large_npm(self): self.check_unpack_error(unpack_range_too_large, no_pyobj_flags) if __name__ == '__main__': unittest.main(buffer=True)
l = range(10) self.assertEqual(cfunc(l, 1), pyfunc(l, 1)) @unittest.expectedFailure def test_list_count(self): pyfunc = list_count cr = compile_isolated(pyfunc, (types.Dummy('list'), types.int32)) cfunc = cr.entry_point l = [1, 1, 2, 1] self.assertEqual(cfunc(l, 1), pyfunc(l, 1)) @unittest.expectedFailure def test_list_sort(self): pyfunc = list_sort cr = compile_isolated(pyfunc, (types.Dummy('list'), )) cfunc = cr.entry_point l = np.random.randint(10, size=10) self.assertEqual(cfunc(l), pyfunc(l)) @unittest.expectedFailure def test_list_reverse(self): pyfunc = list_reverse cr = compile_isolated(pyfunc, (types.Dummy('list'), )) cfunc = cr.entry_point l = range(10) self.assertEqual(cfunc(l), pyfunc(l)) if __name__ == '__main__': unittest.main(buffer=True)