repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
palantir/python-language-server | import time
import mock
from flaky import flaky
from pyls import _utils
def test_merge_dicts():
asser | {'a': False, 'b': {'x': 123, 'y': [], 'z': 987}} | assert | collection | test/test_utils.py | test_merge_dicts | 79 | null | |
palantir/python-language-server | from pyls import uris
from pyls.plugins.hover import pyls_hover
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """
def main():
\"\"\"hello world\"\"\"
pass
"""
NUMPY_DOC = """
import numpy as np
np.sin
"""
def test_numpy_hover(workspace):
# Over the blank line
no_h... | pyls_hover(doc, numpy_hov_position_2)['contents'][0] | assert | func_call | test/plugins/test_hover.py | test_numpy_hover | 44 | null | |
palantir/python-language-server | from test import unix_only, windows_only
import pytest
from pyls import uris
@unix_only
@pytest.mark.parametrize('uri,path', [
('file:///foo/bar#frag', '/foo/bar'),
('file:/foo/bar#frag', '/foo/bar'),
('file:/foo/space%20%3Fbar#frag', '/foo/space ?bar'),
])
def test_to_fs_path(uri, path):
assert uris.... | path | assert | variable | test/test_uris.py | test_to_fs_path | 14 | null | |
palantir/python-language-server | from pyls import lsp, uris
from pyls.workspace import Document
from pyls.plugins import pyflakes_lint
DOC_URI = uris.from_fs_path(__file__)
DOC = """import sys
def hello():
\tpass
import json
"""
DOC_SYNTAX_ERR = """def hello()
pass
"""
DOC_UNDEFINED_NAME_ERR = "a = b"
DOC_ENCODING = u"""# encoding=utf-8
impo... | 'invalid syntax' | assert | string_literal | test/plugins/test_pyflakes_lint.py | test_syntax_error_pyflakes | 43 | null | |
palantir/python-language-server | from pyls import lsp, uris
from pyls.workspace import Document
from pyls.plugins import pyflakes_lint
DOC_URI = uris.from_fs_path(__file__)
DOC = """import sys
def hello():
\tpass
import json
"""
DOC_SYNTAX_ERR = """def hello()
pass
"""
DOC_UNDEFINED_NAME_ERR = "a = b"
DOC_ENCODING = u"""# encoding=utf-8
impo... | lsp.DiagnosticSeverity.Warning | assert | complex_expr | test/plugins/test_pyflakes_lint.py | test_pyflakes | 36 | null | |
palantir/python-language-server | from test.fixtures import DOC_URI, DOC
from pyls.workspace import Document
def test_word_at_position(doc):
""" Return the position under the cursor (or last in line if past the end) """
# import sys
assert doc.word_at_position({'line': 0, 'character': 8}) == 'sys'
# Past end of import sys
assert do... | '' | assert | string_literal | test/test_document.py | test_word_at_position | 37 | null | |
palantir/python-language-server | from pyls import uris
from pyls.plugins.hover import pyls_hover
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """
def main():
\"\"\"hello world\"\"\"
pass
"""
NUMPY_DOC = """
import numpy as np
np.sin
"""
def test_numpy_hover(workspace):
# Over the blank line
no_h... | pyls_hover(doc, numpy_hov_position_1)['contents'][0] | assert | func_call | test/plugins/test_hover.py | test_numpy_hover | 41 | null | |
palantir/python-language-server | import os
import sys
import pytest
from pyls import uris
PY2 = sys.version_info.major == 2
DOC_URI = uris.from_fs_path(__file__)
def path_as_uri(path):
return pathlib.Path(os.path.abspath(path)).as_uri()
def test_get_document(pyls):
pyls.workspace.put_document(DOC_URI, 'TEXT')
assert pyls.workspace.g... | 'TEXT' | assert | string_literal | test/test_workspace.py | test_get_document | 36 | null | |
palantir/python-language-server | from pyls import uris
from pyls.plugins.yapf_format import pyls_format_document, pyls_format_range
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """A = [
'h', 'w',
'a'
]
B = ['h',
'w']
"""
GOOD_DOC = """A = ['hello', 'world']\n"""
def test_range_format(workspace)... | "A = ['h', 'w', 'a']\n\nB = ['h',\n\n\n'w']\n" | assert | string_literal | test/plugins/test_yapf_format.py | test_range_format | 42 | null | |
palantir/python-language-server | from test.fixtures import DOC_URI, DOC
from pyls.workspace import Document
def test_offset_at_position(doc):
assert doc.offset_at_position({'line': 0, 'character': 8}) == 8
assert doc.offset_at_position({'line': 1, 'character': 5}) == 16
assert doc.offset_at_position({'line': 2, 'character': 0}) == | 12 | assert | numeric_literal | test/test_document.py | test_offset_at_position | 25 | null | |
palantir/python-language-server | from pyls import uris
from pyls.plugins.autopep8_format import pyls_format_document, pyls_format_range
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """a = 123
def func():
pass
"""
GOOD_DOC = """A = ['hello', 'world']\n"""
INDENTED_DOC = """def foo():
print('asdf',
... | "a = 123\n\n\ndef func():\n pass\n" | assert | string_literal | test/plugins/test_autopep8_format.py | test_format | 43 | null | |
palantir/python-language-server | import os
import pytest
from pyls import uris
from pyls.plugins.rope_rename import pyls_rename
from pyls.workspace import Document
DOC_NAME = "test1.py"
DOC = """class Test1():
pass
class Test2(Test1):
pass
"""
def tmp_workspace(temp_workspace_factory):
return temp_workspace_factory({DOC_NAME: DOC})
de... | [ { "range": { "start": {"line": 0, "character": 0}, "end": {"line": 5, "character": 0}, }, "newText": "class ShouldBeRenamed():\n pass\n\nclass Test2(ShouldBeRenamed):\n pass\n", } ] | assert | collection | test/plugins/test_rope_rename.py | test_rope_rename | 36 | null | |
palantir/python-language-server | from pyls import lsp, uris
from pyls.workspace import Document
from pyls.plugins import mccabe_lint
DOC_URI = uris.from_fs_path(__file__)
DOC = """def hello():
\tpass
"""
DOC_SYNTAX_ERR = """def hello()
\tpass"""
def test_mccabe(config, workspace):
old_settings = config.settings
try:
config.update({'... | {'line': 0, 'character': 6} | assert | collection | test/plugins/test_mccabe_lint.py | test_mccabe | 30 | null | |
palantir/python-language-server | import os
import sys
import pytest
from pyls import uris
from pyls.plugins.jedi_rename import pyls_rename
from pyls.workspace import Document
LT_PY36 = sys.version_info.major < 3 or (sys.version_info.major == 3 and sys.version_info.minor < 6)
DOC_NAME = 'test1.py'
DOC = '''class Test1():
pass
class Test2(Test1)... | 1 | assert | numeric_literal | test/plugins/test_jedi_rename.py | test_jedi_rename | 42 | null | |
palantir/python-language-server | import os
import time
import multiprocessing
import sys
from threading import Thread
from pyls_jsonrpc.exceptions import JsonRpcMethodNotFound
import pytest
from pyls.python_ls import start_io_lang_server, PythonLanguageServer
CALL_TIMEOUT = 10
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
def start... | None | assert | none_literal | test/test_language_server.py | client_server | 59 | null | |
palantir/python-language-server | from pyls import uris
from pyls.plugins.yapf_format import pyls_format_document, pyls_format_range
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """A = [
'h', 'w',
'a'
]
B = ['h',
'w']
"""
GOOD_DOC = """A = ['hello', 'world']\n"""
def test_config_file(tmpdir, wor... | "A = [\n 'h', 'w',\n 'a'\n]\n\nB = ['h', 'w']\n" | assert | string_literal | test/plugins/test_yapf_format.py | test_config_file | 58 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
's',
(
pytest.param(
'# line 1\n# line 2\n# coding: utf-8\n',
id='only on first two lines',
),
),
)
def test_noop(s):
assert _fix_tokens(s) == | s | assert | variable | tests/features/encoding_cookie_test.py | test_noop | 18 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# renaming things for weird reasons
'from six import MAXSIZE as text_type\n'
'isinstance(s, text_type)\n',
# parenthe... | s | assert | variable | tests/features/six_simple_test.py | test_six_simple_noop | 31 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
's',
(
'""',
r'r"\d"', r"r'\d'", r'r"""\d"""', r"r'''\d'''",
r'rb"\d"',
# make sure we don't replace an already valid string
r'"\\d"',
# this is a... | s | assert | variable | tests/features/escape_sequences_test.py | test_fix_escape_sequences_noop | 27 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param("u''", "''", id='it removes u prefix'),
),
)
def test_unicode_literals(s, expected):
assert _fix_tokens(s) == | expected | assert | variable | tests/features/unicode_literals_test.py | test_unicode_literals | 32 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'import subprocess\n'
'subprocess.run(["foo"], stdout=subprocess.PIPE, '
'stde... | s | assert | variable | tests/features/capture_output_test.py | test_fix_capture_output_noop | 42 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
'str(1)',
'str("foo"\n"bar")', # creates a syntax error
'str(*a)', 'str("foo", *a)',
'str(**k)', 'str("foo", **k)',
... | s | assert | variable | tests/features/native_literals_test.py | test_fix_native_literals_noop | 25 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
('s', 'expected'),
(
('"foo".encode()', 'b"foo"'),
('"foo".encode("ascii")', 'b"foo"'),
('"foo".encode("utf-8")', 'b"foo"'),
('"\\xa0".encode("latin1")', 'b"\\xa0... | expected | assert | variable | tests/features/binary_literals_test.py | test_binary_literals | 56 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.open_mode import _permute
from pyupgrade._plugins.open_mode import _plus
@pytest.mark.parametrize(
('s', 'expected'),
(
('open("foo", "U")', 'open("fo... | expected | assert | variable | tests/features/open_mode_test.py | test_fix_open_mode | 92 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
pytest.param(
'class Text: ...\n'
'text = Text()\n',
id='not a type annotation',
),
),
)
def ... | s | assert | variable | tests/features/typing_text_test.py | test_fix_typing_text_noop | 20 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.open_mode import _permute
from pyupgrade._plugins.open_mode import _plus
def test_permute():
assert _permute('ab') == ('ab', 'ba')
assert _permute('abc') == | ('abc', 'acb', 'bac', 'bca', 'cab', 'cba') | assert | collection | tests/features/open_mode_test.py | test_permute | 18 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'class ExampleTests:\n'
' def test_something(self):\n'
' self.assertEquals(1, 1... | expected | assert | variable | tests/features/unittest_aliases_test.py | test_fix_unittest_aliases | 51 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'from shlex import quote\n'
'" ".join(quote(arg) for arg in cmd)\n',
(3, 8),
... | s | assert | variable | tests/features/shlex_join_test.py | test_shlex_join_noop | 33 | null | |
asottile/pyupgrade | from __future__ import annotations
import sys
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'from __future__ import annotations\n'
'def foo(var: "MyClass") -> "MyClass":... | expected | assert | variable | tests/features/typing_pep563_test.py | test_fix_typing_pep563 | 386 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'six.b("123")',
'b"123"',
),
(
'six.b(r"123")',
'br"123"',
... | expected | assert | variable | tests/features/six_b_test.py | test_six_b | 51 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'from __future__ import annotations\n'
'from typing import Generator\n'
'def ... | expected | assert | variable | tests/features/typing_pep696_typevar_defaults_test.py | test_fix_pep696_with_future_annotations | 99 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.open_mode import _permute
from pyupgrade._plugins.open_mode import _plus
def test_plus():
assert _plus(('a',)) == ('a', 'a+')
assert _plus(('a', 'b')) == | ('a', 'b', 'a+', 'b+') | assert | collection | tests/features/open_mode_test.py | test_plus | 13 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('src', 'expected'),
(
pytest.param(
'if isinstance(x, collections.Sized):\n'
' print(len(x))\n',
'if isinsta... | expected | assert | variable | tests/features/collections_abc_test.py | test_collections_abc_rewrite | 27 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
# dict of generator expression
('dict((a, b) for a, b in y)', '{a: b for a, b in y}'),
('dict((a, b,) for a, b ... | expected | assert | variable | tests/features/dict_literals_test.py | test_dictcomps | 89 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'isinstance(s, six.text_type)',
'isinstance(s, str)',
),
pytest.param(
'i... | expected | assert | variable | tests/features/six_simple_test.py | test_fix_six_simple | 99 | null | |
asottile/pyupgrade | from __future__ import annotations
import ast
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.legacy import _fields_same
from pyupgrade._plugins.legacy import _targets_same
@pytest.mark.parametrize(
's',
(
'def f():\n'
' ... | s | assert | variable | tests/features/yield_from_test.py | test_fix_yield_from_noop | 249 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'from typing import Union\n'
'x: Union[int, str]\n',
(3, 9),
id='<... | s | assert | variable | tests/features/typing_pep604_test.py | test_fix_pep604_types_noop | 68 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'type("")\n',
'str\n',
id='Empty string -> str',
),
pytest.... | expected | assert | variable | tests/features/type_of_primitive_test.py | test_fix_type_of_primitive | 80 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
('"asd".encode("utf-8")', '"asd".encode()'),
('f"asd".encode("utf-8")', 'f"asd".encode()'),
('f"{3}asd".encode(... | expected | assert | variable | tests/features/default_encoding_test.py | test_fix_encode | 50 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'x = lambda foo: None',
(3, 9),
id='lambdas do not have type annotations',
... | s | assert | variable | tests/features/typing_pep585_test.py | test_fix_generic_types_noop | 39 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._string_helpers import parse_format
from pyupgrade._string_helpers import unparse_parsed_string
@pytest.mark.parametrize(
('s', 'expected'),
(
('{:}', '{}'),
('{0:}', '{0}'),
('{0!r:}', '{0!r}'),
),
)
def test_intenti... | expected | assert | variable | tests/string_helpers_test.py | test_intentionally_not_round_trip | 39 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
def test_keep_runtime_typing_ignored_in_py310():
s = '''\
from __future__ import annotations
from typing import Union
def f(x: Union[int, str]) -> None: ...
'''
expected = '''\
from ... | expected | assert | variable | tests/features/typing_pep604_test.py | test_keep_runtime_typing_ignored_in_py310 | 92 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'import subprocess\n'
'subprocess.run(["foo"], universal_newlines=True)\n',
... | expected | assert | variable | tests/features/universal_newlines_to_text_test.py | test_fix_universal_newlines_to_text | 108 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'from collections.abc import Generator\n'
'def f() -> Generator[int, None, None]: yield 1\... | s | assert | variable | tests/features/typing_pep696_typevar_defaults_test.py | test_fix_pep696_noop | 36 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
def test_fix_io_open_noop():
src = '''\
from io import open
with open("f.txt") as f:
print(f.read())
'''
expected = '''\
with open("f.txt") as f:
print(f.read())
'''
ret ... | expected | assert | variable | tests/features/io_open_test.py | test_fix_io_open_noop | 20 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.percent_format import _parse_percent_format
from pyupgrade._plugins.percent_format import _percent_to_format
from pyupgrade._plugins.percent_format import _simplify_co... | s | assert | variable | tests/features/percent_format_test.py | test_percent_format_noop | 184 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
pytest.param(
'foo = [fn(x) for x in items]',
id='assignment to single variable',
),
pytest.param(
... | s | assert | variable | tests/features/unpack_list_comprehension_test.py | test_fix_typing_text_noop | 23 | null | |
asottile/pyupgrade | from __future__ import annotations
import sys
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.xfail(sys.version_info < (3, 12), reason='3.12+ feature')
def test_rewriting_in_fstring():
ret = _fix_plugins('f"{six.text_type}"', settings=Settings())
ass... | 'f"{str}"' | assert | string_literal | tests/features/six_test.py | test_rewriting_in_fstring | 467 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'min_version'),
(
pytest.param(
'from functools import lru_cache as lru_cache2\n\n'
'@lru_cache2()\n'
'def... | s | assert | variable | tests/features/lru_cache_test.py | test_fix_no_arg_decorators_noop | 54 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from tokenize_rt import src_to_tokens
from tokenize_rt import tokens_to_src
from pyupgrade._plugins.typing_pep604 import _fix_union
@pytest.mark.parametrize(
('s', 'arg_count', 'expected'),
(
('Union[a, b]', 2, 'a | b'),
('Union[(a, b)]', 2, 'a... | expected | assert | variable | tests/_plugins/typing_pep604_test.py | test_fix_union_edge_cases | 30 | null | |
asottile/pyupgrade | from __future__ import annotations
import io
import re
import sys
from unittest import mock
import pytest
from pyupgrade._main import main
def test_main_noop(tmpdir, capsys):
with pytest.raises(SystemExit):
main(('--help',))
out, err = capsys.readouterr()
version_options = sorted(set(re.findall(... | s | assert | variable | tests/main_test.py | test_main_noop | 35 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
('s', 'expected'),
(
# Simplest case
("'{0}'.format(1)", "'{}'.format(1)"),
("'{0:x}'.format(30)", "'{:x}'.format(30)"),
("x = '{0}'.format(1)", "x = '{}'.format(... | expected | assert | variable | tests/features/format_literals_test.py | test_format_literals | 86 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'import shlex\n'
'" ".join(shlex.quote(arg) for arg in cmd)\n',
'import shle... | expected | assert | variable | tests/features/shlex_join_test.py | test_shlex_join_fixes | 78 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
('str()', "''"),
('str("foo")', '"foo"'),
('str("""\nfoo""")', '"""\nfoo"""'),
('six.ensure_str("foo")'... | expected | assert | variable | tests/features/native_literals_test.py | test_fix_native_literals | 53 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
def test_collections_abc_noop():
src = 'if isinstance(x, collections.defaultdict): pass\n'
assert _fix_plugins(src, settings=Settings()) == | src | assert | variable | tests/features/collections_abc_test.py | test_collections_abc_noop | 11 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'import subprocess\n'
'subprocess.run(["foo"], stdout=subprocess.PIPE, '
'std... | expected | assert | variable | tests/features/capture_output_test.py | test_fix_capture_output | 146 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s',),
(
pytest.param(
'from collections import defaultdict as dd\n\n'
'dd(lambda: set())\n',
id='not following... | s | assert | variable | tests/features/defaultdict_lambda_test.py | test_fix_noop | 90 | null | |
asottile/pyupgrade | from __future__ import annotations
import io
import re
import sys
from unittest import mock
import pytest
from pyupgrade._main import main
def test_main_changes_a_file(tmpdir, capsys):
f = tmpdir.join('f.py')
f.write('x = set((1, 2, 3))\n')
assert main((f.strpath,)) == | 1 | assert | numeric_literal | tests/main_test.py | test_main_changes_a_file | 45 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.open_mode import _permute
from pyupgrade._plugins.open_mode import _plus
def test_permute():
assert _permute('ab') == | ('ab', 'ba') | assert | collection | tests/features/open_mode_test.py | test_permute | 17 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'import mock.mock\n'
'\n'
'mock.mock.patch("func1")\n'
'mock.patc... | expected | assert | variable | tests/features/mock_test.py | test_fix_mock | 37 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.open_mode import _permute
from pyupgrade._plugins.open_mode import _plus
def test_plus():
assert _plus(('a',)) == | ('a', 'a+') | assert | collection | tests/features/open_mode_test.py | test_plus | 12 | null | |
asottile/pyupgrade | from __future__ import annotations
import ast
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
from pyupgrade._plugins.legacy import _fields_same
from pyupgrade._plugins.legacy import _targets_same
@pytest.mark.parametrize(
('s', 'expected'),
(
(
... | expected | assert | variable | tests/features/yield_from_test.py | test_fix_yield_from | 178 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
('s', 'expected'),
(
# no valid escape sequences, make a raw literal
(r'"\d"', r'r"\d"'),
# when there are valid escape sequences, need to use backslashes
(r'"\n\... | expected | assert | variable | tests/features/escape_sequences_test.py | test_fix_escape_sequences | 56 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'from typing import NamedTuple\n'
'C = NamedTuple("C", [("a", int), ("b", str)])\n',
... | expected | assert | variable | tests/features/typing_classes_test.py | test_fix_typing_named_tuple | 226 | null | |
asottile/pyupgrade | from __future__ import annotations
import sys
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# syntax error
'x = (',
# unrelated
'from os import path',
'from six import moves',
'a[0]... | s | assert | variable | tests/features/six_test.py | test_fix_six_noop | 45 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# Don't touch irrelevant code
'x = 5',
'dict()',
# Don't touch syntax errors
'(',
# Don't touch stran... | s | assert | variable | tests/features/dict_literals_test.py | test_fix_dict_noop | 29 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'__metaclass__ = type',
'',
id='module-scope assignment',
),
... | expected | assert | variable | tests/features/metaclass_type_test.py | test_fix_metaclass_type_assignment | 67 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'min_version'),
(
pytest.param('from a import b', (3,), id='unrelated import'),
pytest.param(
'from .xml.etree.cElementTre... | s | assert | variable | tests/features/import_replaces_test.py | test_import_replaces_noop | 51 | null | |
asottile/pyupgrade |
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'if six.PY2:\n'
' print("py2")\n'
'else:\n'
' print("py3")\n',
'print("py3")\n',
id='six.PY2',
),
pytest.param(
'if six.PY2:\n'
... | expected | assert | variable | tests/features/versioned_branches_test.py | test_fix_py2_blocks | 654 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'@six.python_2_unicode_compatible\n'
'class C: pass',
'class C: pass',
),
... | expected | assert | variable | tests/features/six_remove_decorators_test.py | test_fix_six_remove_decorators | 46 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
def test_keep_runtime_typing_ignored_in_py39():
s = '''\
from __future__ import annotations
from typing import List
def f(x: List[str]) -> None: ...
'''
expected = '''\
from __future... | expected | assert | variable | tests/features/typing_pep585_test.py | test_keep_runtime_typing_ignored_in_py39 | 63 | null | |
asottile/pyupgrade | from __future__ import annotations
import io
import re
import sys
from unittest import mock
import pytest
from pyupgrade._main import main
def test_main_trivial():
assert main(()) == | 0 | assert | numeric_literal | tests/main_test.py | test_main_trivial | 14 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
'',
pytest.param(
'from typing import NamedTuple as wat\n'
'C = wat("C", ("a", int))\n',
id='cur... | s | assert | variable | tests/features/typing_classes_test.py | test_typing_named_tuple_noop | 63 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
's',
(
'print("hello world")',
'print((1, 2, 3))',
'print(())',
'print((\n))',
# don't touch parenthesized generators
'sum((block.code for block i... | s | assert | variable | tests/features/extra_parens_test.py | test_fix_extra_parens_noop | 23 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
('"{} {}".format(a, b)', 'f"{a} {b}"'),
('"{1} {0}".format(a, b)', 'f"{b} {a}"'),
('"{x.y}".format(x=z)', 'f"{z... | expected | assert | variable | tests/features/fstrings_test.py | test_fix_fstrings | 75 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# Don't touch empty set literals
'set()',
# Don't touch weird looking function calls -- use autopep8 or such
# first
... | s | assert | variable | tests/features/set_literals_test.py | test_fix_sets_noop | 28 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
pytest.param(
'x = type\n'
'__metaclass__ = x\n',
id='not rewriting "type" rename',
),
py... | s | assert | variable | tests/features/metaclass_type_test.py | test_metaclass_type_assignment_noop | 34 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
's',
(
pytest.param('(', id='syntax errors are unchanged'),
# Regression: string containing newline
pytest.param('"""with newline\n"""', id='string containing newline'),
... | s | assert | variable | tests/features/unicode_literals_test.py | test_unicode_literals_noop | 22 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
pytest.param(
'class ExampleTests:\n'
' def test_something(self):\n'
' self.assertEqual(1, 1)\n... | s | assert | variable | tests/features/unittest_aliases_test.py | test_fix_unittest_aliases_noop | 23 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'foo, bar, baz = [fn(x) for x in items]\n',
'foo, bar, baz = (fn(x) for x in items)\n',
... | expected | assert | variable | tests/features/unpack_list_comprehension_test.py | test_fix_typing_text | 60 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# non-utf-8 codecs should not be changed
'"asd".encode("unknown-codec")',
'"asd".encode("ascii")',
# only autofix st... | s | assert | variable | tests/features/default_encoding_test.py | test_fix_encode_noop | 69 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
'x is True',
'x is False',
'x is None',
'x is (not 5)',
'x is 5 + 5',
# pyupgrade is timid about cont... | s | assert | variable | tests/features/identity_equality_test.py | test_fix_is_compare_to_literal_noop | 26 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
# Take a set literal with an empty tuple / list and remove the arg
('set(())', 'set()'),
('set([])', 'set()'),
... | expected | assert | variable | tests/features/set_literals_test.py | test_sets | 116 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_tokens
@pytest.mark.parametrize(
('s', 'expected'),
(
('print(("hello world"))', 'print("hello world")'),
('print(("foo{}".format(1)))', 'print("foo{}".format(1))'),
('print((((1))))', 'print(1)'),
... | expected | assert | variable | tests/features/extra_parens_test.py | test_fix_extra_parens | 74 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'from collections import defaultdict\n\n'
'defaultdict(lambda: set())\n',
'fr... | expected | assert | variable | tests/features/defaultdict_lambda_test.py | test_fix_defaultdict | 220 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_plugins
from pyupgrade._main import Settings
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'class C(Base):\n'
' def f(self):\n'
' super(C, self).f()\n',
'clas... | expected | assert | variable | tests/features/super_test.py | test_fix_super | 163 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._string_helpers import parse_format
from pyupgrade._string_helpers import unparse_parsed_string
def test_parse_format_starts_with_named():
# technically not possible since our string always starts with quotes
assert parse_format(r'\N{snowman} h... | [ (r'\N{snowman} hi ', '0', '', None), (' hello', None, None, None), ] | assert | collection | tests/string_helpers_test.py | test_parse_format_starts_with_named | 22 | null | |
asottile/pyupgrade | from __future__ import annotations
import sys
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
(
'six.byte2int(b"f")',
'b"f"[0]',
),
(
'six.get_unbound_functi... | expected | assert | variable | tests/features/six_test.py | test_fix_six | 409 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# syntax error
'(',
# invalid format strings
"'{'.format(a)", "'}'.format(a)",
# weird syntax
'"{}" .... | s | assert | variable | tests/features/fstrings_test.py | test_fix_fstrings_noop | 44 | null | |
asottile/pyupgrade | from __future__ import annotations
import sys
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
pytest.param(
'from typing import Literal\n'
'x: "str"\n',
id='missing __future__ import',
... | s | assert | variable | tests/features/typing_pep563_test.py | test_fix_typing_pep563_noop | 67 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._string_helpers import parse_format
from pyupgrade._string_helpers import unparse_parsed_string
@pytest.mark.parametrize(
's',
(
'', 'foo', '{}', '{0}', '{named}', '{!r}', '{:>5}', '{{', '}}',
'{0!s:15}',
),
)
def test_roundt... | s | assert | variable | tests/string_helpers_test.py | test_roundtrip_text | 17 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
's',
(
# skip `if` without `else` as it could cause a SyntaxError
'if True:\n'
' if six.PY2:\n'
' pass\n',
... | s | assert | variable | tests/features/versioned_branches_test.py | test_fix_py2_block_noop | 54 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s',),
(
pytest.param(
'from typing import Unpack\n'
'foo(Unpack())',
id='Not a subscript',
),
... | s | assert | variable | tests/features/typing_pep646_unpack_test.py | test_fix_pep646_noop | 35 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'version'),
(
pytest.param(
'import subprocess\n'
'subprocess.run(["foo"], universal_newlines=True)\n',
(3... | s | assert | variable | tests/features/universal_newlines_to_text_test.py | test_fix_universal_newlines_to_text_noop | 53 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s',),
(
pytest.param(
'import datetime\n'
'print(datetime.timezone(-1))',
id='not rewriting timezone object t... | s | assert | variable | tests/features/datetime_utc_alias_test.py | test_fix_datetime_utc_alias_noop | 21 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'isinstance(x, (str, str, int))',
'isinstance(x, (str, int))',
id='isinstan... | expected | assert | variable | tests/features/constant_fold_test.py | test_constant_fold | 91 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._main import _fix_plugins
from pyupgrade._main import Settings
@pytest.mark.parametrize(
's',
(
# syntax error
'x(',
'class C(Base):\n'
' def f(self):\n'
' super().f()\n',
# super class... | s | assert | variable | tests/features/super_test.py | test_fix_super_noop | 77 | null | |
asottile/pyupgrade | from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'min_version', 'expected'),
(
('from __future__ import generators\n', (3,), ''),
('from __future__ import generators', (3,), ''),
... | expected | assert | variable | tests/features/import_removals_test.py | test_import_removals | 132 | null | |
fpgmaas/deptry | from __future__ import annotations
from importlib.metadata import PackageNotFoundError
from pathlib import Path
from typing import Any
from unittest.mock import patch
import pytest
from deptry.dependency import Dependency, parse_pep_508_dependency
def test_simple_dependency() -> None:
dependency = Dependency("c... | Path("pyproject.toml") | assert | func_call | tests/unit/test_dependency.py | test_simple_dependency | 16 | null | |
fpgmaas/deptry | from __future__ import annotations
from pathlib import Path
from deptry.dependency_getter.requirements_files import RequirementsTxtDependencyGetter
from tests.utils import run_within_dir
def test_parse_requirements_files(tmp_path: Path) -> None:
fake_requirements_files = """click==8.1.3 #123asd
colorama==0.4.5
i... | 0 | assert | numeric_literal | tests/unit/dependency_getter/test_requirements_txt.py | test_parse_requirements_files | 44 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.