tests: Format all Python code with black, except tests in basics subdir.

This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py.  The basics/ subdirectory is excluded for now so we
aren't changing too much at once.

In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
This commit is contained in:
David Lechner
2020-03-22 21:26:08 -05:00
committed by Damien George
parent 488613bca6
commit 3dc324d3f1
472 changed files with 4396 additions and 2891 deletions
+4 -4
View File
@@ -4,9 +4,9 @@
for i in ():
pass
a = None
b = 'str'
c = 'a very long str that will not be interned'
d = b'bytes'
e = b'a very long bytes that will not be interned'
b = "str"
c = "a very long str that will not be interned"
d = b"bytes"
e = b"a very long bytes that will not be interned"
f = 123456789012345678901234567890
g = 123
+1
View File
@@ -1,5 +1,6 @@
# cmdline: -v -v
# test printing of all bytecodes
# fmt: off
def f():
# constants
+13 -13
View File
@@ -7,7 +7,7 @@ arg names:
(N_EXC_STACK 0)
bc=0 line=1
########
bc=\\d\+ line=159
bc=\\d\+ line=160
00 MAKE_FUNCTION \.\+
\\d\+ STORE_NAME f
\\d\+ MAKE_FUNCTION \.\+
@@ -45,7 +45,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
(INIT_CELL 16)
bc=0 line=1
########
bc=\\d\+ line=126
bc=\\d\+ line=127
00 LOAD_CONST_NONE
01 LOAD_CONST_FALSE
02 BINARY_OP 27 __add__
@@ -320,7 +320,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
(N_EXC_STACK 0)
bc=0 line=1
########
bc=\\d\+ line=132
bc=\\d\+ line=133
00 LOAD_CONST_SMALL_INT 1
01 DUP_TOP
02 STORE_FAST 0
@@ -376,7 +376,7 @@ arg names: a
(N_EXC_STACK 0)
(INIT_CELL 0)
########
bc=\\d\+ line=138
bc=\\d\+ line=139
00 LOAD_CONST_SMALL_INT 2
01 BUILD_TUPLE 1
03 LOAD_NULL
@@ -393,9 +393,9 @@ arg names:
(N_STATE 2)
(N_EXC_STACK 0)
bc=0 line=1
bc=0 line=143
bc=3 line=144
bc=6 line=145
bc=0 line=144
bc=3 line=145
bc=6 line=146
00 LOAD_CONST_NONE
01 YIELD_VALUE
02 POP_TOP
@@ -418,7 +418,7 @@ arg names:
(N_EXC_STACK 0)
bc=0 line=1
########
bc=13 line=149
bc=13 line=150
00 LOAD_NAME __name__ (cache=0)
04 STORE_NAME __module__
07 LOAD_CONST_STRING 'Class'
@@ -433,7 +433,7 @@ arg names: self
(N_STATE 4)
(N_EXC_STACK 0)
bc=0 line=1
bc=0 line=156
bc=0 line=157
00 LOAD_GLOBAL super (cache=0)
\\d\+ LOAD_GLOBAL __class__ (cache=0)
\\d\+ LOAD_FAST 0
@@ -450,7 +450,7 @@ arg names: * * *
(N_STATE 9)
(N_EXC_STACK 0)
bc=0 line=1
bc=0 line=59
bc=0 line=60
########
00 LOAD_NULL
01 LOAD_FAST 2
@@ -474,7 +474,7 @@ arg names: * * *
(N_STATE 10)
(N_EXC_STACK 0)
bc=0 line=1
bc=0 line=60
bc=0 line=61
########
00 BUILD_LIST 0
02 LOAD_FAST 2
@@ -517,7 +517,7 @@ arg names: *
(N_EXC_STACK 0)
bc=0 line=1
########
bc=\\d\+ line=113
bc=\\d\+ line=114
00 LOAD_DEREF 0
02 LOAD_CONST_SMALL_INT 1
03 BINARY_OP 27 __add__
@@ -536,7 +536,7 @@ arg names: * b
(N_EXC_STACK 0)
bc=0 line=1
########
bc=\\d\+ line=139
bc=\\d\+ line=140
00 LOAD_FAST 1
01 LOAD_DEREF 0
03 BINARY_OP 27 __add__
+4 -2
View File
@@ -6,9 +6,11 @@ workaround: Unknown
"""
import gc
class Foo():
class Foo:
def __del__(self):
print('__del__')
print("__del__")
f = Foo()
del f
+4
View File
@@ -4,12 +4,16 @@ description: Method Resolution Order (MRO) is not compliant with CPython
cause: Depth first non-exhaustive method resolution order
workaround: Avoid complex class hierarchies with multiple inheritance and complex method overrides. Keep in mind that many languages don't support multiple inheritance at all.
"""
class Foo:
def __str__(self):
return "Foo"
class C(tuple, Foo):
pass
t = C((1, 2, 3))
print(t)
+6 -1
View File
@@ -4,24 +4,29 @@ description: When inheriting from multiple classes super() only calls one class
cause: See :ref:`cpydiff_core_class_mro`
workaround: See :ref:`cpydiff_core_class_mro`
"""
class A:
def __init__(self):
print("A.__init__")
class B(A):
def __init__(self):
print("B.__init__")
super().__init__()
class C(A):
def __init__(self):
print("C.__init__")
super().__init__()
class D(B,C):
class D(B, C):
def __init__(self):
print("D.__init__")
super().__init__()
D()
+5 -1
View File
@@ -4,15 +4,19 @@ description: Calling super() getter property in subclass will return a property
cause: Unknown
workaround: Unknown
"""
class A:
@property
def p(self):
return {"a":10}
return {"a": 10}
class AA(A):
@property
def p(self):
return super().p
a = AA()
print(a.p)
+3
View File
@@ -4,8 +4,11 @@ description: User-defined attributes for functions are not supported
cause: MicroPython is highly optimized for memory usage.
workaround: Use external dictionary, e.g. ``FUNC_X[f] = 0``.
"""
def f():
pass
f.x = 0
print(f.x)
+8 -2
View File
@@ -4,11 +4,15 @@ description: Context manager __exit__() not called in a generator which does not
cause: Unknown
workaround: Unknown
"""
class foo(object):
def __enter__(self):
print('Enter')
print("Enter")
def __exit__(self, *args):
print('Exit')
print("Exit")
def bar(x):
with foo():
@@ -16,9 +20,11 @@ def bar(x):
x += 1
yield x
def func():
g = bar(0)
for _ in range(3):
print(next(g))
func()
+2 -1
View File
@@ -12,6 +12,7 @@ except NameError as e:
print(e)
try:
from modules import foo
print('Should not get here')
print("Should not get here")
except NameError as e:
print(e)
@@ -5,6 +5,7 @@ cause: MicroPython's import system is highly optimized for simplicity, minimal m
workaround: Don't install modules belonging to the same namespace package in different directories. For MicroPython, it's recommended to have at most 3-component module search paths: for your current application, per-user (writable), system-wide (non-writable).
"""
import sys
sys.path.append(sys.path[1] + "/modules")
sys.path.append(sys.path[1] + "/modules2")
+3
View File
@@ -4,8 +4,11 @@ description: Local variables aren't included in locals() result
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name.
workaround: Unknown
"""
def test():
val = 2
print(locals())
test()
+2
View File
@@ -6,9 +6,11 @@ workaround: Unknown
"""
val = 1
def test():
val = 2
print(val)
eval("print(val)")
test()
+1 -1
View File
@@ -1,2 +1,2 @@
print('foo')
print("foo")
xxx
+2 -1
View File
@@ -5,4 +5,5 @@ cause: Unknown
workaround: Unknown
"""
import array
print(1 in array.array('B', b'12'))
print(1 in array.array("B", b"12"))
+2 -1
View File
@@ -5,6 +5,7 @@ cause: Unknown
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))
a = array.array("b", (1, 2, 3))
del a[1]
print(a)
+2 -1
View File
@@ -5,5 +5,6 @@ cause: Unknown
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))
a = array.array("b", (1, 2, 3))
print(a[3:2:2])
+1
View File
@@ -5,5 +5,6 @@ cause: Unknown
workaround: Use regular lists. micropython-lib has implementation of collections.deque.
"""
import collections
D = collections.deque()
print(D)
@@ -5,10 +5,11 @@ cause: Unknown
workaround: Unknown
"""
import json
a = bytes(x for x in range(256))
try:
z = json.dumps(a)
x = json.loads(z)
print('Should not get here')
print("Should not get here")
except TypeError:
print('TypeError')
print("TypeError")
+8 -7
View File
@@ -5,12 +5,13 @@ cause: Unknown
workaround: Use ``getenv``, ``putenv`` and ``unsetenv``
"""
import os
try:
print(os.environ.get('NEW_VARIABLE'))
os.environ['NEW_VARIABLE'] = 'VALUE'
print(os.environ['NEW_VARIABLE'])
print(os.environ.get("NEW_VARIABLE"))
os.environ["NEW_VARIABLE"] = "VALUE"
print(os.environ["NEW_VARIABLE"])
except AttributeError:
print('should not get here')
print(os.getenv('NEW_VARIABLE'))
os.putenv('NEW_VARIABLE', 'VALUE')
print(os.getenv('NEW_VARIABLE'))
print("should not get here")
print(os.getenv("NEW_VARIABLE"))
os.putenv("NEW_VARIABLE", "VALUE")
print(os.getenv("NEW_VARIABLE"))

Some files were not shown because too many files have changed in this diff Show More