示例#1
0
 def test_callable_type_with_default_args(self):
     c = Callable([self.x, self.y], [ARG_POS, ARG_OPT], [None, None],
                  Any(), False)
     assert_equal(str(c), 'def (X?, Y?=) -> any')
     
     c2 = Callable([self.x, self.y], [ARG_OPT, ARG_OPT], [None, None],
                   Any(), False)
     assert_equal(str(c2), 'def (X?=, Y?=) -> any')
示例#2
0
 def test_callable_type(self):
     c = Callable([self.x, self.y],
                  [ARG_POS, ARG_POS],
                  [None, None],
                  Any(), False)
     assert_equal(str(c), 'def (X?, Y?) -> any')
     
     c2 = Callable([], [], [], Void(None), False)
     assert_equal(str(c2), 'def ()')
示例#3
0
 def assert_expand(self, orig, map_items, result):
     lower_bounds = {}
     
     for id, t in map_items:
         lower_bounds[id] = t
     
     exp = expand_type(orig, lower_bounds)
     # Remove erased tags (asterisks).
     assert_equal(str(exp).replace('*', ''), str(result))
示例#4
0
文件: testinfer.py 项目: khukri/mypy
 def assert_vararg_map(self, caller_kinds, callee_kinds, expected,
                        vararg_type):
     result = map_actuals_to_formals(
         caller_kinds,
         [],
         callee_kinds,
         [],
         lambda i: vararg_type)
     assert_equal(result, expected)
示例#5
0
文件: testsolve.py 项目: gtreddy/mypy
 def assert_solve(self, vars, constraints, results):
     res = []
     for r in results:
         if isinstance(r, tuple):
             res.append(r[0])
         else:
             res.append(r)
     actual = solve_constraints(vars, constraints, self.fx.basic)
     assert_equal(str(actual), str(res))
示例#6
0
文件: testinfer.py 项目: khukri/mypy
 def assert_map(self, caller_kinds, callee_kinds, expected):
     caller_kinds, caller_names = expand_caller_kinds(caller_kinds)
     callee_kinds, callee_names = expand_callee_kinds(callee_kinds)
     result = map_actuals_to_formals(
         caller_kinds,
         caller_names,
         callee_kinds,
         callee_names,
         lambda i: Any())
     assert_equal(result, expected)
示例#7
0
 def test_generic_function_type(self):
     c = Callable([self.x, self.y], [ARG_POS, ARG_POS], [None, None],
                  self.y, False, None,
                  TypeVars([TypeVarDef('X', -1)]))
     assert_equal(str(c), 'def <X> (X?, Y?) -> Y?')
     
     v = TypeVars([TypeVarDef('Y', -1, UnboundType('X')),
                   TypeVarDef('X', -2)])
     c2 = Callable([], [], [], Void(None), False, None, v)
     assert_equal(str(c2), 'def <Y is X?, X> ()')
示例#8
0
 def assert_simple_join(self, s, t, join):
     result = join_types(s, t, self.fx.basic)
     actual = str(result)
     expected = str(join)
     assert_equal(actual, expected,
                  'join({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(s, result),
                     '{} not subtype of {}'.format(s, result))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(t, result),
                     '{} not subtype of {}'.format(t, result))
示例#9
0
 def assert_simple_meet(self, s, t, meet):
     result = meet_types(s, t, self.fx.basic)
     actual = str(result)
     expected = str(meet)
     assert_equal(actual, expected,
                  'meet({}, {}) == {{}} ({{}} expected)'.format(s, t))
     if not isinstance(s, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, s),
                     '{} not subtype of {}'.format(result, s))
     if not isinstance(t, ErrorType) and not isinstance(result, ErrorType):
         assert_true(is_subtype(result, t),
                     '{} not subtype of {}'.format(result, t))
示例#10
0
文件: testlex.py 项目: khukri/mypy
 def assert_line(self, s, a):
     s = s.replace('\\n', '\n')
     s = s.replace('\\r', '\r')
     
     tt = lex(s)
     r = []
     for t in tt:
         r.append(t.line)
     if len(r) == len(a) + 2:
         a = a[:]
         a.append(a[-1])
         a.append(a[-1])
     assert_equal(r, a)
示例#11
0
文件: testlex.py 项目: khukri/mypy
 def assert_lex(self, src, lexed):
     src = src.replace('\\n', '\n')
     src = src.replace('\\r', '\r')
     
     if lexed.endswith(' ...'):
         lexed = lexed[:-3] + 'Break() Eof()'
     
     l = lex(src)
     r = []
     for t in l:
         r.append(str(t))
     act = ' '.join(r)
     if act != lexed:
         print('Actual:  ', act)
         print('Expected:', lexed)
     assert_equal(act, lexed)
示例#12
0
 def test_callable_type_with_var_args(self):
     c = Callable([self.x], [ARG_STAR], [None], Any(), False)
     assert_equal(str(c), 'def (*X?) -> any')
     
     c2 = Callable([self.x, self.y], [ARG_POS, ARG_STAR],
                   [None, None], Any(), False)
     assert_equal(str(c2), 'def (X?, *Y?) -> any')
     
     c3 = Callable([self.x, self.y], [ARG_OPT, ARG_STAR], [None, None],
                   Any(), False)
     assert_equal(str(c3), 'def (X?=, *Y?) -> any')
示例#13
0
 def test_generic_unbound_type(self):
     u = UnboundType('Foo', [UnboundType('T'), Any()])
     assert_equal(str(u), 'Foo?<T?, any>')
示例#14
0
 def test_type_variable_binding(self):
     assert_equal(str(TypeVarDef('X', 1)), 'X')
     assert_equal(str(TypeVarDef('X', 1, UnboundType('Y'))), 'X is Y?')
示例#15
0
 def test_tuple_type(self):
     assert_equal(str(TupleType([])), 'tuple<>')
     assert_equal(str(TupleType([self.x])), 'tuple<X?>')
     assert_equal(str(TupleType([self.x, Any()])), 'tuple<X?, any>')
示例#16
0
 def assert_replace(self, orig, result):
     assert_equal(str(replace_type_vars(orig)), str(result))
示例#17
0
 def assert_erase(self, orig, result):
     assert_equal(str(erase_type(orig, self.fx.basic)), str(result))
示例#18
0
 def test_any(self):
     assert_equal(str(Any()), 'any')
示例#19
0
 def test_simple_unbound_type(self):
     u = UnboundType('Foo')
     assert_equal(str(u), 'Foo?')
示例#20
0
 def test_void_type(self):
     assert_equal(str(Void(None)), 'void')