summaryrefslogtreecommitdiff
path: root/tests/unix
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2020-03-22 21:26:08 -0500
committerDamien George <damien.p.george@gmail.com>2020-03-30 13:21:58 +1100
commit3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch)
tree94ff44f8eabba0039582c245b901173597edd11e /tests/unix
parent488613bca6c460340ed2995ae5cafafe22d0bfff (diff)
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.
Diffstat (limited to 'tests/unix')
-rw-r--r--tests/unix/extra_coverage.py54
-rw-r--r--tests/unix/ffi_callback.py7
-rw-r--r--tests/unix/ffi_float.py13
-rw-r--r--tests/unix/ffi_float2.py7
-rw-r--r--tests/unix/time.py25
5 files changed, 67 insertions, 39 deletions
diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py
index 09bb48f0f..36105f6ba 100644
--- a/tests/unix/extra_coverage.py
+++ b/tests/unix/extra_coverage.py
@@ -13,33 +13,33 @@ data = extra_coverage()
print(data[0], data[1])
print(hash(data[0]))
print(hash(data[1]))
-print(hash(bytes(data[0], 'utf8')))
-print(hash(str(data[1], 'utf8')))
+print(hash(bytes(data[0], "utf8")))
+print(hash(str(data[1], "utf8")))
# test streams
-stream = data[2] # has set_error and set_buf. Write always returns error
-stream.set_error(uerrno.EAGAIN) # non-blocking error
-print(stream.read()) # read all encounters non-blocking error
-print(stream.read(1)) # read 1 byte encounters non-blocking error
-print(stream.readline()) # readline encounters non-blocking error
-print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error
-print(stream.write(b'1')) # write encounters non-blocking error
-print(stream.write1(b'1')) # write1 encounters non-blocking error
-stream.set_buf(b'123')
-print(stream.read(4)) # read encounters non-blocking error after successful reads
-stream.set_buf(b'123')
-print(stream.read1(4)) # read1 encounters non-blocking error after successful reads
-stream.set_buf(b'123')
-print(stream.readline(4)) # readline encounters non-blocking error after successful reads
+stream = data[2] # has set_error and set_buf. Write always returns error
+stream.set_error(uerrno.EAGAIN) # non-blocking error
+print(stream.read()) # read all encounters non-blocking error
+print(stream.read(1)) # read 1 byte encounters non-blocking error
+print(stream.readline()) # readline encounters non-blocking error
+print(stream.readinto(bytearray(10))) # readinto encounters non-blocking error
+print(stream.write(b"1")) # write encounters non-blocking error
+print(stream.write1(b"1")) # write1 encounters non-blocking error
+stream.set_buf(b"123")
+print(stream.read(4)) # read encounters non-blocking error after successful reads
+stream.set_buf(b"123")
+print(stream.read1(4)) # read1 encounters non-blocking error after successful reads
+stream.set_buf(b"123")
+print(stream.readline(4)) # readline encounters non-blocking error after successful reads
try:
- print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError
+ print(stream.ioctl(0, 0)) # ioctl encounters non-blocking error; raises OSError
except OSError:
- print('OSError')
+ print("OSError")
stream.set_error(0)
-print(stream.ioctl(0, bytearray(10))) # successful ioctl call
+print(stream.ioctl(0, bytearray(10))) # successful ioctl call
-stream2 = data[3] # is textio
-print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream
+stream2 = data[3] # is textio
+print(stream2.read(1)) # read 1 byte encounters non-blocking error with textio stream
# test BufferedWriter with stream errors
stream.set_error(uerrno.EAGAIN)
@@ -48,33 +48,41 @@ print(buf.write(bytearray(16)))
# test basic import of frozen scripts
import frzstr1
+
print(frzstr1.__file__)
import frzmpy1
+
print(frzmpy1.__file__)
# test import of frozen packages with __init__.py
import frzstr_pkg1
+
print(frzstr_pkg1.__file__, frzstr_pkg1.x)
import frzmpy_pkg1
+
print(frzmpy_pkg1.__file__, frzmpy_pkg1.x)
# test import of frozen packages without __init__.py
from frzstr_pkg2.mod import Foo
+
print(Foo.x)
from frzmpy_pkg2.mod import Foo
+
print(Foo.x)
# test raising exception in frozen script
try:
import frzmpy2
except ZeroDivisionError:
- print('ZeroDivisionError')
+ print("ZeroDivisionError")
# test loading a resource from a frozen string
import uio
-buf = uio.resource_stream('frzstr_pkg2', 'mod.py')
+
+buf = uio.resource_stream("frzstr_pkg2", "mod.py")
print(buf.read(21))
# test for MP_QSTR_NULL regression
from frzqstr import returns_NULL
+
print(returns_NULL())
diff --git a/tests/unix/ffi_callback.py b/tests/unix/ffi_callback.py
index 23b058bce..21bfccf25 100644
--- a/tests/unix/ffi_callback.py
+++ b/tests/unix/ffi_callback.py
@@ -15,16 +15,19 @@ def ffi_open(names):
err = e
raise err
-libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib'))
+
+libc = ffi_open(("libc.so", "libc.so.0", "libc.so.6", "libc.dylib"))
qsort = libc.func("v", "qsort", "piip")
+
def cmp(pa, pb):
a = ffi.as_bytearray(pa, 1)
b = ffi.as_bytearray(pb, 1)
- #print("cmp:", a, b)
+ # print("cmp:", a, b)
return a[0] - b[0]
+
cmp_c = ffi.callback("i", cmp, "pp")
s = bytearray(b"foobar")
diff --git a/tests/unix/ffi_float.py b/tests/unix/ffi_float.py
index 317436855..d03939896 100644
--- a/tests/unix/ffi_float.py
+++ b/tests/unix/ffi_float.py
@@ -16,7 +16,8 @@ def ffi_open(names):
err = e
raise err
-libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib'))
+
+libc = ffi_open(("libc.so", "libc.so.0", "libc.so.6", "libc.dylib"))
try:
strtof = libc.func("f", "strtof", "sp")
@@ -26,14 +27,14 @@ except OSError:
print("SKIP")
raise SystemExit
-print('%.6f' % strtof('1.23', None))
+print("%.6f" % strtof("1.23", None))
strtod = libc.func("d", "strtod", "sp")
-print('%.6f' % strtod('1.23', None))
+print("%.6f" % strtod("1.23", None))
# test passing double and float args
-libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib'))
-tgamma = libm.func('d', 'tgamma', 'd')
+libm = ffi_open(("libm.so", "libm.so.6", "libc.so.0", "libc.so.6", "libc.dylib"))
+tgamma = libm.func("d", "tgamma", "d")
for fun in (tgamma,):
for val in (0.5, 1, 1.0, 1.5, 4, 4.0):
- print('%.6f' % fun(val))
+ print("%.6f" % fun(val))
diff --git a/tests/unix/ffi_float2.py b/tests/unix/ffi_float2.py
index 721eb4d19..bbed69666 100644
--- a/tests/unix/ffi_float2.py
+++ b/tests/unix/ffi_float2.py
@@ -16,16 +16,17 @@ def ffi_open(names):
err = e
raise err
-libm = ffi_open(('libm.so', 'libm.so.6', 'libc.so.0', 'libc.so.6', 'libc.dylib'))
+
+libm = ffi_open(("libm.so", "libm.so.6", "libc.so.0", "libc.so.6", "libc.dylib"))
# Some libc's implement tgammaf as header macro with tgamma(), so don't assume
# it'll be in library.
try:
- tgammaf = libm.func('f', 'tgammaf', 'f')
+ tgammaf = libm.func("f", "tgammaf", "f")
except OSError:
print("SKIP")
raise SystemExit
for fun in (tgammaf,):
for val in (0.5, 1, 1.0, 1.5, 4, 4.0):
- print('%.6f' % fun(val))
+ print("%.6f" % fun(val))
diff --git a/tests/unix/time.py b/tests/unix/time.py
index 35eddbe09..55a4b18aa 100644
--- a/tests/unix/time.py
+++ b/tests/unix/time.py
@@ -7,12 +7,14 @@ DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
tzseconds = -time.mktime((1970, 1, 1, 14, 0, 0, 0, 0, 0))
+
def is_leap(year):
return (year % 4) == 0
+
def test():
seconds = 0
- wday = 3 # Jan 1, 1970 was a Thursday
+ wday = 3 # Jan 1, 1970 was a Thursday
for year in range(1970, 2038):
print("Testing %d" % year)
yday = 1
@@ -24,21 +26,34 @@ def test():
for day in range(1, DAYS_PER_MONTH[month] + 1):
secs = time.mktime((year, month, day, 14, 0, 0, 0, 0, 0)) + tzseconds
if secs != seconds:
- print("mktime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ print(
+ "mktime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
return
tuple = time.localtime(seconds)
secs = time.mktime(tuple)
if secs != seconds:
- print("localtime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ print(
+ "localtime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
return
seconds += 86400
if yday != tuple[7]:
- print("locatime for %d-%02d-%02d got yday %d, expecting %d" % (year, month, day, tuple[7], yday))
+ print(
+ "locatime for %d-%02d-%02d got yday %d, expecting %d"
+ % (year, month, day, tuple[7], yday)
+ )
return
if wday != tuple[6]:
- print("locatime for %d-%02d-%02d got wday %d, expecting %d" % (year, month, day, tuple[6], wday))
+ print(
+ "locatime for %d-%02d-%02d got wday %d, expecting %d"
+ % (year, month, day, tuple[6], wday)
+ )
return
yday += 1
wday = (wday + 1) % 7
+
test()