refactoring: Drop PY2 and PY3 flags

This commit is contained in:
Takeshi KOMIYA
2018-09-08 10:52:24 +09:00
parent 5ffce30d75
commit 3a2418a827
28 changed files with 228 additions and 522 deletions

View File

@@ -13,7 +13,6 @@ import sys
from textwrap import dedent
import pytest
from six import PY3
from sphinx.util import inspect
@@ -25,15 +24,11 @@ def test_getargspec():
spec = inspect.getargspec(func)
assert spec.args == ['a', 'b', 'c', 'd']
assert spec.varargs == 'e'
if PY3:
assert spec.varkw == 'f'
assert spec.defaults == (1, 2)
assert spec.kwonlyargs == []
assert spec.kwonlydefaults is None
assert spec.annotations == {}
else:
assert spec.keywords == 'f'
assert spec.defaults == [1, 2]
assert spec.varkw == 'f'
assert spec.defaults == (1, 2)
assert spec.kwonlyargs == []
assert spec.kwonlydefaults is None
assert spec.annotations == {}
def test_getargspec_partial():
@@ -42,19 +37,13 @@ def test_getargspec_partial():
partial = functools.partial(func1, 10, c=11)
spec = inspect.getargspec(partial)
if PY3:
assert spec.args == ['b']
assert spec.varargs is None
assert spec.varkw == 'f'
assert spec.defaults is None
assert spec.kwonlyargs == ['c', 'd']
assert spec.kwonlydefaults == {'c': 11, 'd': 2}
assert spec.annotations == {}
else:
assert spec.args == ['b', 'd']
assert spec.varargs == 'e'
assert spec.keywords == 'f'
assert spec.defaults == [2]
assert spec.args == ['b']
assert spec.varargs is None
assert spec.varkw == 'f'
assert spec.defaults is None
assert spec.kwonlyargs == ['c', 'd']
assert spec.kwonlydefaults == {'c': 11, 'd': 2}
assert spec.annotations == {}
def test_getargspec_partial2():
@@ -62,19 +51,8 @@ def test_getargspec_partial2():
pass
p = functools.partial(fun, 10, c=11)
if PY3:
# Python 3's partial is rather cleverer than Python 2's, and we
# have to jump through some hoops to define an equivalent function
# in a way that won't confuse Python 2's parser:
ns = {}
exec(dedent("""
def f_expected(b, *, c=11, d=2):
pass
"""), ns)
f_expected = ns["f_expected"]
else:
def f_expected(b, d=2):
pass
def f_expected(b, *, c=11, d=2):
pass
expected = inspect.getargspec(f_expected)
assert expected == inspect.getargspec(p)
@@ -367,37 +345,25 @@ def test_dictionary_sorting():
def test_set_sorting():
set_ = set("gfedcba")
description = inspect.object_description(set_)
if PY3:
assert description == "{'a', 'b', 'c', 'd', 'e', 'f', 'g'}"
else:
assert description == "set(['a', 'b', 'c', 'd', 'e', 'f', 'g'])"
assert description == "{'a', 'b', 'c', 'd', 'e', 'f', 'g'}"
def test_set_sorting_fallback():
set_ = set((None, 1))
description = inspect.object_description(set_)
if PY3:
assert description in ("{1, None}", "{None, 1}")
else:
assert description in ("set([1, None])", "set([None, 1])")
assert description in ("{1, None}", "{None, 1}")
def test_frozenset_sorting():
frozenset_ = frozenset("gfedcba")
description = inspect.object_description(frozenset_)
if PY3:
assert description == "frozenset({'a', 'b', 'c', 'd', 'e', 'f', 'g'})"
else:
assert description == "frozenset(['a', 'b', 'c', 'd', 'e', 'f', 'g'])"
assert description == "frozenset({'a', 'b', 'c', 'd', 'e', 'f', 'g'})"
def test_frozenset_sorting_fallback():
frozenset_ = frozenset((None, 1))
description = inspect.object_description(frozenset_)
if PY3:
assert description in ("frozenset({1, None})", "frozenset({None, 1})")
else:
assert description in ("frozenset([1, None])", "frozenset([None, 1])")
assert description in ("frozenset({1, None})", "frozenset({None, 1})")
def test_dict_customtype():