def test_basic_usage(self): c = Context(a=1, b=2) self.assertEqual(c.a, 1) self.assertEqual(c.b, 2) self.assertEqual(c['a'], 1) self.assertEqual(c['b'], 2) c.c = 3 self.assertEqual(c.c, 3) self.assertEqual(c['c'], 3)
def test_context_behaves_like_dict(self): c = Context(a=1) c.b = 2 keys = list(c.keys()) keys.sort() self.assertEqual(keys, ['a', 'b']) values = list(c.values()) values.sort() self.assertEqual(values, [1, 2]) self.assertTrue('a' in c) self.assertTrue('b' in c) self.assertTrue('c' not in c)
def test_context_behaves_like_dict(self): c = Context(a=1) c.b = 2 keys = c.keys() keys.sort() self.assertEqual(keys, ['a', 'b']) values = c.values() values.sort() self.assertEqual(values, [1, 2]) self.assertTrue('a' in c) self.assertTrue('b' in c) self.assertTrue('c' not in c)
def test_variable_declarations(self): g = self.group context = Context(x=1.0) expect = 'cdef double x = 1.0' self.assertEqual(g.get_variable_declarations(context), expect) context = Context(x=1) expect = 'cdef long x = 1' self.assertEqual(g.get_variable_declarations(context), expect) context = Context(x=[1., 2.]) expect = ('cdef DoubleArray _x = DoubleArray(aligned(2, 8)*' 'self.n_threads)\n' 'cdef double* x = _x.data') self.assertEqual(g.get_variable_declarations(context), expect) context = Context(x=(0, 1., 2.)) expect = ('cdef DoubleArray _x = DoubleArray(aligned(3, 8)*' 'self.n_threads)\n' 'cdef double* x = _x.data') self.assertEqual(g.get_variable_declarations(context), expect)