-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
755d8e9
commit bf49fef
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |