From bf49fefc77652b0eded3432badd86d49f6ecc1e1 Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:33:42 -0300 Subject: [PATCH] Added separated tests for BaseType --- tests/test_basetype.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_basetype.py diff --git a/tests/test_basetype.py b/tests/test_basetype.py new file mode 100644 index 000000000..e72907ecb --- /dev/null +++ b/tests/test_basetype.py @@ -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