def test_update_call_arg_in_source_list(): source_lines = textwrap.dedent("""\ setup( foo=1, bar=[ "a", "b", r"c", ], baz=2, ) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert "".join(result) == textwrap.dedent("""\ setup( foo=1, bar=[ "x", "y", ], baz=2, ) """)
def test_update_call_arg_in_source_no_function_call(capsys): source_lines = textwrap.dedent("""\ """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert result == source_lines assert "Did not find setup() call" in capsys.readouterr().err
def test_update_call_arg_in_source_no_keyword(capsys): source_lines = textwrap.dedent("""\ setup() """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert result == source_lines assert ("Did not find bar= argument in setup() call" in capsys.readouterr().err)
def test_update_call_arg_in_source_too_complicated(capsys): source_lines = textwrap.dedent("""\ setup( bar=bar) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert result == source_lines assert ("Did not understand bar= formatting in setup() call" in capsys.readouterr().err)
def test_update_call_arg_in_source_string(): source_lines = textwrap.dedent("""\ setup( foo=1, bar="x", baz=2, ) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", "y") assert "".join(result) == textwrap.dedent("""\ setup( foo=1, bar="y", baz=2, ) """)
def test_update_call_arg_in_source_string_spaces(): # This is against PEP-8 but there are setup.py files out there that do # not follow PEP-8. source_lines = textwrap.dedent("""\ setup ( foo = 1, bar = 'x', baz = 2, ) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", "y") assert "".join(result) == textwrap.dedent("""\ setup ( foo = 1, bar = 'y', baz = 2, ) """)
def test_update_call_arg_in_source_maybe_dotted_name(): source_lines = textwrap.dedent("""\ setuptools.setup( foo=1, bar="x", baz=2, ) """).splitlines(True) result = update_call_arg_in_source(source_lines, ("setup", "setuptools.setup"), "bar", "y") assert "".join(result) == textwrap.dedent("""\ setuptools.setup( foo=1, bar="y", baz=2, ) """)
def test_update_call_arg_in_source_fixes_opening_bracket(): source_lines = textwrap.dedent("""\ setup(foo=1, bar=['a', 'b', 'c'], baz=2, ) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert "".join(result) == textwrap.dedent("""\ setup(foo=1, bar=[ 'x', 'y', ], baz=2, ) """)
def test_update_call_arg_in_source_preserves_indent_and_quote_style(): source_lines = textwrap.dedent("""\ setup(foo=1, bar=[ 'a', 'b', 'c', ], ) """).splitlines(True) result = update_call_arg_in_source(source_lines, "setup", "bar", ["x", "y"]) assert "".join(result) == textwrap.dedent("""\ setup(foo=1, bar=[ 'x', 'y', ], ) """)