예제 #1
0
def test_return_value_is_filled_dict_by_keyword():
    # when method return dict(a='b')
    try:
        assert ReturnedExpression(
            _ast.Return(
                value=_ast.Call(
                    func=_ast.Name(id='dict', ctx=_ast.Load()),
                    args=[],
                    keywords=[_ast.keyword(arg='a', value=_ast.Str(s='b'))],
                ),
                lineno=1,
            ), ).value_not_none() is True
    except (AttributeError):
        assert ReturnedExpression(
            _ast.Return(
                value=_ast.Call(
                    func=_ast.Name(id='dict', ctx=_ast.Load()),
                    args=[],
                    keywords=[
                        _ast.keyword(arg='a',
                                     value=_ast.JoinedStr(values=['a', 'b']))
                    ],
                ),
                lineno=1,
            ), ).value_not_none() is True
class ConstructorMutableAttribsLineNumberFixture:
    definition_is_none = None
    definition_is_not_a_function = _ast.Pass
    constructor_with_empty_body = _ast.FunctionDef(name='__init__', body=[])
    try:
        constructor_with_immutable = _ast.FunctionDef(
            name='__init__',
            body=[
                _ast.Assign(lineno=1, value=_ast.Tuple(elts=[1, 2, 3])),
                _ast.Assign(lineno=2, value=_ast.Str(s='a')),
            ],
        )
    except (AttributeError):
        constructor_with_immutable = _ast.FunctionDef(
            name='__init__',
            body=[
                _ast.Assign(lineno=1, value=_ast.Tuple(elts=[1, 2, 3])),
                _ast.Assign(lineno=3, value=_ast.JoinedStr(values=None)),
            ],
        )
    constructor_with_mutable = _ast.FunctionDef(
        name='__init__',
        body=[
            _ast.Assign(lineno=1, value=_ast.List(elts=[1, 2, 3])),
            _ast.Assign(lineno=2, value=_ast.Set(elts=[1, 2, 3])),
            _ast.Assign(lineno=3, value=_ast.Dict(keys=['a'])),
        ],
    )
예제 #3
0
def test_return_value_is_filled_frozenset_by_keyword():
    # when method return frozenset('1')
    try:
        assert ReturnedExpression(
            _ast.Return(
                value=_ast.Call(
                    func=_ast.Name(id='frozenset', ctx=_ast.Load()),
                    args=[_ast.Str(s='1')],
                    keywords=[],
                ),
                lineno=1,
            ), ).value_not_none() is True
    except (AttributeError):
        assert ReturnedExpression(
            _ast.Return(
                value=_ast.Call(
                    func=_ast.Name(id='frozenset', ctx=_ast.Load()),
                    args=[_ast.JoinedStr(values=['1'])],
                    keywords=[],
                ),
                lineno=1,
            ), ).value_not_none() is True
예제 #4
0
def test_return_value_is_filled_joined_string():
    # when method return '{}{}{}'.format('a', 'b', 'c')
    assert ReturnedExpression(
        _ast.Return(value=_ast.JoinedStr(values=['a', 'b', 'c']),
                    lineno=1)).value_not_none() is True
예제 #5
0
def test_return_value_is_empty_joined_string():
    # when method return ''
    assert ReturnedExpression(
        _ast.Return(value=_ast.JoinedStr(values=[]),
                    lineno=1)).value_not_none() is False