Skip to content

Commit

Permalink
Added separated tests for BaseType
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Nov 9, 2023
1 parent 755d8e9 commit bf49fef
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_basetype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import libcst as cst
from codemodder.codemods.utils import BaseType


class TestBaseType:
def test_binary_op_number(self):
e = cst.parse_expression("1 + float(2)")
assert BaseType.infer_expression_type(e) == BaseType.NUMBER

def test_binary_op_string_mixed(self):
e = cst.parse_expression('f"a"+foo()')
assert BaseType.infer_expression_type(e) == BaseType.STRING

def test_binary_op_list(self):
e = cst.parse_expression("[1,2] + [x for x in [3]] + list((4,5))")
assert BaseType.infer_expression_type(e) == BaseType.LIST

def test_binary_op_none(self):
e = cst.parse_expression("foo() + bar()")
assert BaseType.infer_expression_type(e) == None

def test_bytes(self):
e = cst.parse_expression('b"123"')
assert BaseType.infer_expression_type(e) == BaseType.BYTES

def test_if_mixed(self):
e = cst.parse_expression('1 if True else "a"')
assert BaseType.infer_expression_type(e) == None

def test_if_numbers(self):
e = cst.parse_expression("abs(1) if True else 2")
assert BaseType.infer_expression_type(e) == BaseType.NUMBER

def test_if_numbers2(self):
e = cst.parse_expression("float(1) if True else len([1,2])")
assert BaseType.infer_expression_type(e) == BaseType.NUMBER

0 comments on commit bf49fef

Please sign in to comment.