def test_actual_code():
    text = """
        flags = bitfield_property(
            FLAGA=0x00000001,
            FLAGB=0x00000002,
            FLAGC=0x00000004,
            FLAGD=0x00000008,
            FLAGE=0x00000010,
            FLAGF=0x00000020,
            # comment
            FLAGG=0x00000040,
            FLAGH=0x00000080,
            FLAGI=0x00000100,
            # comment
            FLAGJ=0x00000200,
            FLAGK=0x00000400,
        )
    """
    assert_transform(
        hex_to_bitshift,
        text,
        [
            '1 << 0',
            '1 << 1',
            '1 << 2',
            '1 << 3',
            '1 << 4',
            '1 << 5',
            '1 << 6',
            '1 << 7',
            '1 << 8',
            '1 << 9',
            '1 << 10',
        ],
    )
Beispiel #2
0
def test_actual_code():
    text = """
        if condition:
            # only when condition
            id = component.get(
                self.logic,
                id=id.method(),
            )
            ids = id.keys()
        else:
            if component.yes():
                ids = DO().get(
                    self.logic,
                    id=id.method(),
                )
            else:
                ids = component.get(
                    self.logic,
                    id=id.method(),
                )
    """
    assert_transform(
        method_to_function,
        text,
        [
            'function(id)',
            'function(id)',
            'function(id)',
        ],
    )
Beispiel #3
0
def test_actual_code():
    text = """
        def cold_war(self, foo, bar):
            if foo <> bar:
                launch_the_nukes()
    """
    assert_transform(
        deprecated_inequality_operator,
        text,
        ['foo != bar'],
    )
Beispiel #4
0
def test_multi_line():
    text = """session.query(
        mu,
    ).filter(
        mu.t > abc,
        mu.id == id,
    ).count()"""
    expected = """session.query(
        sqlalchemy.func.count(),
    ).filter(
        mu.t > abc,
        mu.id == id,
    ).scalar()"""
    assert_transform(sqla_count, text, [expected])
Beispiel #5
0
def test_actual_code():
    text = """something before
        x = session.query(
            mr,
        ).filter(
            mr.t < xyz,
        ).count()
    something after
    """
    expected = """session.query(
            sqlalchemy.func.count(),
        ).filter(
            mr.t < xyz,
        ).scalar()"""
    assert_transform(sqla_count, text, [expected])
def test_actual_code():
    text = """
    def get(self):
        '''Returns a thing that does a thing because we really
        want to do that thing
        '''
        self.abcd.efgh('Do: {}'.format(
            self.opt.thing_to_do
        ))
        derp = []
    """
    assert_transform(
        dbl_quote_docstring,
        text,
        [
            '''"""Returns a thing that does a thing because we really
        want to do that thing
        """'''
        ],
    )
Beispiel #7
0
def test_actual_code():
    text = """
        def somefunc(self):
            obj = something(self.attr).obj
            if obj is None:
                var = None
            else:
                var = self.attr.C.id(obj.attribute)['str']

            return self.x(
                abc=True,
                efg='str',
                hij='str',
                klm={
                    'str': str,
                },
            )
    """
    assert_transform(
        attribute_to_function,
        text,
        ['function(obj)'],
    )
Beispiel #8
0
def test_expr():
    text = 'if let x = a + 1 / b where x == -y {'
    expected = 'if let x = a + 1 / b, x == -y {'
    assert_transform(swift, text, [expected])
Beispiel #9
0
def test_more_dots():
    assert_transform(
        attribute_to_function,
        'self.id = o.id.attribute',
        ['function(o.id)'],
    )
Beispiel #10
0
def test_object_id():
    assert_transform(
        attribute_to_function,
        "'id': ID(obj['id']).attribute",
        ["function(ID(obj['id']))"],
    )
Beispiel #11
0
def test_no_self_dot():
    assert_transform(
        method_to_function,
        'self.method()',
        [],
    )
Beispiel #12
0
def test_simple():
    assert_transform(
        attribute_to_function,
        'obj.attribute',
        ['function(obj)'],
    )
Beispiel #13
0
def test_ignore_hex_not_power_of_two():
    assert_transform(
        hex_to_bitshift,
        'SOME_FLAG = 0x123',
        [None],
    )
Beispiel #14
0
def test_object_id():
    assert_transform(
        method_to_function,
        "'id': ID(objs['id']).method()",
        ["function(ID(objs['id']))"],
    )
Beispiel #15
0
def test_parse_hexnums():
    assert_transform(
        hex_to_bitshift,
        'SOME_FLAG = 0xa',
        [None],
    )
Beispiel #16
0
def test_avoid_negative_shift_count():
    assert_transform(
        hex_to_bitshift,
        'SOME_FLAG = 0x0',
        [None],
    )
Beispiel #17
0
def test_globals_and_locals():
    assert_transform(
        exec_function,
        'exec str in globals(), locals()',
        ['exec(str, globals(), locals())'],
    )
Beispiel #18
0
def test_compound():
    text = 'if let x = a, y = b, z = c where x == y && y != z {'
    expected = 'if let x = a, let y = b, let z = c, x == y && y != z {'
    assert_transform(swift, text, [expected])
Beispiel #19
0
def test_no_match():
    assert_transform(
        nl_at_eof,
        'something\n',
        [],
    )
Beispiel #20
0
def test_match():
    assert_transform(
        nl_at_eof,
        'something',
        ['g\n'],
    )
Beispiel #21
0
def test_simple():
    assert_transform(
        deprecated_inequality_operator,
        '1 <> 2',
        ['1 != 2'],
    )
Beispiel #22
0
def test_one_liner():
    assert_transform(
        sqla_count,
        'session.query(x).filter(y).count()',
        ['session.query(sqlalchemy.func.count()).filter(y).scalar()'],
    )
Beispiel #23
0
def test_one_liner():
    assert_transform(
        swift,
        'if let x = a where x == y {',
        ['if let x = a, x == y {'],
    )
Beispiel #24
0
def test_simple():
    assert_transform(
        method_to_function,
        'id.method()',
        ['function(id)'],
    )
Beispiel #25
0
def test_simple():
    assert_transform(
        hex_to_bitshift,
        'FLAGA = 0x00000001',
        ['1 << 0'],
    )