示例#1
0
    def test_any_tuple_constant(self):
        input = (1, '2', False)
        node = ast.parse(str(input)).body[0].value
        expected_output = TupleType(UnionType.build([Type.str, Type.int]))

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#2
0
    def test_integer_list_constant(self):
        input = [1, 2, 3]
        node = ast.parse(str(input)).body[0].value
        expected_output = ListType(Type.int)

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#3
0
    def test_string_tuple_constant(self):
        input = (1, 2, 3)
        node = ast.parse(str(input)).body[0].value
        expected_output = TupleType(Type.int)

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#4
0
    def test_boolean_tuple_constant(self):
        input = (True, False)
        node = ast.parse(str(input)).body[0].value
        expected_output = TupleType(Type.bool)

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#5
0
    def test_string_constant(self):
        input = 'unit_test'
        node = ast.parse(str(input)).body[0].value
        expected_output = Type.str

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#6
0
    def test_negative_integer_constant(self):
        input = -10
        node = ast.parse(str(input)).body[0].value
        expected_output = Type.int

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)
示例#7
0
    def test_any_list_constant(self):
        input = [1, '2', False]
        node = ast.parse(str(input)).body[0].value
        expected_output = ListType(Type.any)

        typeanalyser = TypeAnalyser(Analyser(node), {})
        output = typeanalyser.get_type(input)

        self.assertEqual(expected_output, output)