summaryrefslogtreecommitdiff
path: root/tests/functional/s/simplifiable/simplifiable_if_expression.py
blob: 94db05f2c861b1cf2b3db582438fea8f0a5e0697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Test that some if expressions can be simplified."""

# pylint: disable=missing-docstring, invalid-name


def test_simplifiable_1(arg):
    # Simple test that can be replaced by bool(arg)
    return True if arg else False # [simplifiable-if-expression]


def test_simplifiable_2(arg):
    # Simple test that can be replaced by not arg
    return False if arg else True # [simplifiable-if-expression]


def test_simplifiable_3(arg):
    # Simple test that can be replaced by arg == 1
    return True if arg == 1 else False # [simplifiable-if-expression]


def test_simplifiable_4(arg):
    # Simple test that can be replaced by not (arg == 1)
    return False if arg == 1 else True # [simplifiable-if-expression]


def test_not_simplifiable(arg):
    x = True if arg else True
    y = 0 if arg else 1
    t = False if arg != 1 else False
    t2 = None if arg > 3 else False
    return x, y, t, t2


def convoluted_function():
    a = []
    b = []
    if bool('special test'):
        a = True
    else:
        b = False
    return a + b


FLYING_THINGS = ["bird", "plane", "superman", "this example"]


def is_flying_animal(an_object):
    is_flying = False
    if isinstance(an_object, str) and an_object in FLYING_THINGS:  # [simplifiable-if-statement]
        is_flying = True
    else:
        is_flying = False
    return is_flying