def test_nullable2(self): tc = typechecker.Typechecker([], []) cell = mkc('Str', True) tc.work = False tc.set_nullable(cell) self.assertIs(True, cell['nullable']) self.assertIs(False, tc.work)
def test_type_cells1(self): tc = typechecker.Typechecker([], []) cell1, cell2 = mkc('Str', True), mkc(None, False) self.assertIsNone(tc.type_cells(cell1, cell2, False)) self.assertEqual(mkc('Str', True), cell1) self.assertEqual(mkc('Str', True), cell2) self.assertIs(True, tc.work)
def test_constrain3(self): tc = typechecker.Typechecker([], []) cell = mkc('Str', False) tc.work = False tc.constrain_type(cell, 'Str') self.assertEqual('Str', cell['type']) self.assertIs(False, tc.work)
def test_reset_polymorphic_calls(self): tc = typechecker.Typechecker([self.t1], self.world) tc.reset_type_environment() env = tc.type_env_builtins rule = self.rules[7] typ = mkc(None, False) self.assertEqual(5, len(env.keys())) self.assertEqual({1: [typ, typ, typ]}, env[rule.id])
def test_reset(self): tc = typechecker.Typechecker([self.t1], self.world) tc.reset_types() sch1 = self.t1.schema for (_, cols) in six.iteritems(sch1.map): for col in cols: self.assertIs(False, col['nullable']) self.assertIsNone(col['type'])
def test_reset_variables(self): tc = typechecker.Typechecker([self.t1], self.world) tc.reset_type_environment() env = tc.type_env self.assertEqual(5, len(env.keys())) for variables in six.itervalues(env): for (v, cell) in six.iteritems(variables): self.assertIn(v, [u'x', u'y']) self.assertEqual(mkc(None, False), cell)
def test_type_rule(self): rule = self.rules[2] tc = typechecker.Typechecker([self.t1], self.world) tc.reset_types() tc.reset_type_environment() tc.type_facts(self.t1) tc.type_rule(self.t1, rule) self.assertEqual(mkc('Int', False), tc.type_env[rule.id]['x']) self.assertEqual('Int', self.t1.schema.map['p'][0]['type']) self.assertIs(True, tc.work)
def test_type_all(self): tc = typechecker.Typechecker([self.t1], self.world) type_env = tc.type_all() smap = self.t1.schema.map self.assertEqual('Int', smap['p'][0]['type']) # propagation of l self.assertEqual('Str', smap['q'][0]['type']) # propagation of m self.assertEqual('Str', smap['q'][1]['type']) self.assertEqual('Str', smap['r'][0]['type']) self.assertEqual('Scalar', smap['k'][0]['type']) # prop of ext table self.assertEqual('Int', smap['s'][0]['type']) # through builtins rule = self.rules[7] typ = mkc('Int', False) self.assertEqual([typ, typ, typ], type_env[rule.id][1])
def test_type_facts(self): tc = typechecker.Typechecker([self.t1], self.world) tc.reset_types() tc.reset_type_environment() tc.type_facts(self.t1) cols1 = self.t1.schema.map['l'] self.assertEqual(1, len(cols1)) self.assertEqual('Int', cols1[0]['type']) self.assertIs(False, cols1[0]['nullable']) cols2 = self.t1.schema.map['m'] self.assertEqual(1, len(cols2)) self.assertEqual('Str', cols2[0]['type']) self.assertIs(False, cols2[0]['nullable'])
def test_type_constant(self): tc = typechecker.Typechecker([], []) def check(val, typ, nullable): cell = mkc(None, False) tc.type_constant(val, cell) self.assertEqual(mkc(typ, nullable), cell) check(1, 'Int', False) check('aaa', 'Str', False) check(True, 'Bool', False) check(1.3, 'Float', False) check(None, None, True) check((1, 3), 'Scalar', False)
def typecheck(self): """Typechecker for rules defined""" typer = typechecker.Typechecker(self.z3theories.values(), self.theories) return typer.type_all()
def test_type_cells5(self): tc = typechecker.Typechecker([], []) cell1, cell2 = mkc('Int', False), mkc('Str', True) self.assertIsNotNone(tc.type_cells(cell1, cell2, False))