-
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
2f11ea9
commit 0189e06
Showing
3 changed files
with
103 additions
and
104 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
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
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import libcst as cst | ||
from codemodder.codemods.utils import BaseType | ||
from codemodder.codemods.utils import BaseType, infer_expression_type | ||
|
||
|
||
class TestBaseType: | ||
def test_binary_op_number(self): | ||
e = cst.parse_expression("1 + float(2)") | ||
assert BaseType.infer_expression_type(e) == BaseType.NUMBER | ||
assert 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 | ||
assert 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 | ||
assert 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 | ||
assert infer_expression_type(e) == None | ||
|
||
def test_bytes(self): | ||
e = cst.parse_expression('b"123"') | ||
assert BaseType.infer_expression_type(e) == BaseType.BYTES | ||
assert 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 | ||
assert 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 | ||
assert 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 | ||
assert infer_expression_type(e) == BaseType.NUMBER |