Skip to content

Commit

Permalink
tests: Format all Python code with black, except tests in basics subdir.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlech authored and dpgeorge committed Mar 30, 2020
1 parent 488613b commit 3dc324d
Show file tree
Hide file tree
Showing 472 changed files with 4,352 additions and 2,847 deletions.
8 changes: 4 additions & 4 deletions tests/cmdline/cmd_parsetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions tests/cmdline/cmd_showbc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cmdline: -v -v
# test printing of all bytecodes
# fmt: off

def f():
# constants
Expand Down
26 changes: 13 additions & 13 deletions tests/cmdline/cmd_showbc.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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 \.\+
Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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__
Expand All @@ -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__
Expand Down
6 changes: 4 additions & 2 deletions tests/cpydiff/core_class_delnotimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"""
import gc

class Foo():

class Foo:
def __del__(self):
print('__del__')
print("__del__")


f = Foo()
del f
Expand Down
4 changes: 4 additions & 0 deletions tests/cpydiff/core_class_mro.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
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)
7 changes: 6 additions & 1 deletion tests/cpydiff/core_class_supermultiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
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()
6 changes: 5 additions & 1 deletion tests/cpydiff/core_class_superproperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
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 changes: 3 additions & 0 deletions tests/cpydiff/core_function_userattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
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)
10 changes: 8 additions & 2 deletions tests/cpydiff/core_generator_noexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
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():
while True:
x += 1
yield x


def func():
g = bar(0)
for _ in range(3):
print(next(g))


func()
3 changes: 2 additions & 1 deletion tests/cpydiff/core_import_prereg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
print(e)
try:
from modules import foo
print('Should not get here')

print("Should not get here")
except NameError as e:
print(e)
1 change: 1 addition & 0 deletions tests/cpydiff/core_import_split_ns_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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")

Expand Down
3 changes: 3 additions & 0 deletions tests/cpydiff/core_locals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
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 changes: 2 additions & 0 deletions tests/cpydiff/core_locals_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"""
val = 1


def test():
val = 2
print(val)
eval("print(val)")


test()
2 changes: 1 addition & 1 deletion tests/cpydiff/modules/foo.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
print('foo')
print("foo")
xxx
3 changes: 2 additions & 1 deletion tests/cpydiff/modules_array_containment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
workaround: Unknown
"""
import array
print(1 in array.array('B', b'12'))

print(1 in array.array("B", b"12"))
3 changes: 2 additions & 1 deletion tests/cpydiff/modules_array_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))

a = array.array("b", (1, 2, 3))
del a[1]
print(a)
3 changes: 2 additions & 1 deletion tests/cpydiff/modules_array_subscrstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
workaround: Unknown
"""
import array
a = array.array('b', (1, 2, 3))

a = array.array("b", (1, 2, 3))
print(a[3:2:2])
1 change: 1 addition & 0 deletions tests/cpydiff/modules_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
workaround: Use regular lists. micropython-lib has implementation of collections.deque.
"""
import collections

D = collections.deque()
print(D)
5 changes: 3 additions & 2 deletions tests/cpydiff/modules_json_nonserializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
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")
15 changes: 8 additions & 7 deletions tests/cpydiff/modules_os_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
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"))
7 changes: 4 additions & 3 deletions tests/cpydiff/modules_os_getenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
workaround: Unknown
"""
import os
print(os.getenv('NEW_VARIABLE'))
os.putenv('NEW_VARIABLE', 'VALUE')
print(os.getenv('NEW_VARIABLE'))

print(os.getenv("NEW_VARIABLE"))
os.putenv("NEW_VARIABLE", "VALUE")
print(os.getenv("NEW_VARIABLE"))
7 changes: 4 additions & 3 deletions tests/cpydiff/modules_os_getenv_argcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
workaround: Test that the return value is ``None``
"""
import os

try:
print(os.getenv('NEW_VARIABLE', 'DEFAULT'))
print(os.getenv("NEW_VARIABLE", "DEFAULT"))
except TypeError:
print('should not get here')
print("should not get here")
# this assumes NEW_VARIABLE is never an empty variable
print(os.getenv('NEW_VARIABLE') or 'DEFAULT')
print(os.getenv("NEW_VARIABLE") or "DEFAULT")
7 changes: 4 additions & 3 deletions tests/cpydiff/modules_struct_fewargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
workaround: Unknown
"""
import struct

try:
print(struct.pack('bb', 1))
print('Should not get here')
print(struct.pack("bb", 1))
print("Should not get here")
except:
print('struct.error')
print("struct.error")
Loading

0 comments on commit 3dc324d

Please sign in to comment.