예제 #1
0
 def check(expr: str, truthyness: bool):
     check_expression(f'not not {expr}', str(truthyness))
예제 #2
0
def test_booleans():
    check_expression('True', 'True')
    check_expression('False', 'False')
예제 #3
0
def test_print():
    check_expression("'abc'", 'abc')
예제 #4
0
def test_print_tuples():
    # In the end, Python's __str__() is called, just check that we get what
    # we expected.
    check_expression('("a", "b")', "('a', 'b')")
예제 #5
0
def test_equality():
    check_expression('type(True) == type(False)', 'True')
    check_expression('type(()) == type((False, True))', 'True')
    check_expression('type("foo") == str', 'True')
    check_expression('type(print) == type("bar")', 'False')
예제 #6
0
def test_repr():
    check_expression('type(True)', 'bool')
    check_expression('type(())', 'tuple')
    check_expression('type("foo")', 'str')
    check_expression('type(print)', 'callable')
예제 #7
0
def test_equals():
    check_expression('True == True', 'True')
    check_expression('True == False', 'False')

    check_expression("'foo' == 'foo'", 'True')
    check_expression("'foo' == 'bar'", 'False')

    check_expression("((), ('a', 'b')) == ((), ('a', 'b'))", 'True')
    check_expression("((), ('a', 'b', ())) == ((), ('a', 'b'))", 'False')

    check_expression('False == ()', 'False')
    check_expression("'foo' == ('foo',)", 'False')
예제 #8
0
def test_multiple_ops():
    check_expression("'a' == 'a' != 'b'", 'True')
    check_expression("'a' == 'b' == 'b'", 'False')
    check_expression("'a' != 'b' != 'a'", 'True')
예제 #9
0
def test_not_equals():
    check_expression('True != False', 'True')
    check_expression('False != ()', 'True')
    check_expression('() != ()', 'False')
예제 #10
0
def test_non_booleans():
    check_expression("True and 'a'", 'a')
    check_expression("False and 'a'", 'False')

    check_expression("True or 'a'", 'Tr' 'ue')
    check_expression("False or 'a'", 'a')
예제 #11
0
def test_chain():
    check_expression('True and True and True', 'True')
    check_expression('True and False and True', 'False')