Commit 9db9509f authored by Stefan Behnel's avatar Stefan Behnel

Clean up some test code.

parent 4736e009
from libc cimport stdlib
from libc cimport stdio
cimport cpython.buffer
import sys
......@@ -34,7 +33,7 @@ cdef class MockBuffer:
cdef Py_ssize_t x, s, cumprod, itemsize
self.label = label
self.release_ok = True
self.log = ""
self.log = u""
self.offset = offset
self.itemsize = itemsize = self.get_itemsize()
self.writable = writable
......@@ -138,7 +137,7 @@ cdef class MockBuffer:
self.received_flags.append(name)
if flags & cpython.buffer.PyBUF_WRITABLE and not self.writable:
raise BufferError("Writable buffer requested from read-only mock: %s" % ' | '.join(self.received_flags))
raise BufferError(f"Writable buffer requested from read-only mock: {' | '.join(self.received_flags)}")
buffer.buf = <void*>(<char*>self.buffer + (<int>self.offset * self.itemsize))
buffer.obj = self
......@@ -152,29 +151,29 @@ cdef class MockBuffer:
buffer.itemsize = self.itemsize
buffer.internal = NULL
if self.label:
msg = "acquired %s" % self.label
print msg
self.log += msg + "\n"
msg = f"acquired {self.label}"
print(msg)
self.log += msg + u"\n"
def __releasebuffer__(MockBuffer self, Py_buffer* buffer):
if buffer.suboffsets != self.suboffsets:
self.release_ok = False
if self.label:
msg = "released %s" % self.label
print msg
self.log += msg + "\n"
msg = f"released {self.label}"
print(msg)
self.log += msg + u"\n"
def printlog(self):
print self.log[:-1]
print(self.log[:-1])
def resetlog(self):
self.log = ""
self.log = u""
cdef int write(self, char* buf, object value) except -1: raise Exception()
cdef get_itemsize(self):
print "ERROR, not subclassed", self.__class__
print(f"ERROR, not subclassed: {self.__class__}")
cdef get_default_format(self):
print "ERROR, not subclassed", self.__class__
print(f"ERROR, not subclassed {self.__class__}")
cdef class CharMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1:
......@@ -246,10 +245,10 @@ cdef class ErrorBuffer:
self.label = label
def __getbuffer__(ErrorBuffer self, Py_buffer* buffer, int flags):
raise Exception("acquiring %s" % self.label)
raise Exception(f"acquiring {self.label}")
def __releasebuffer__(ErrorBuffer self, Py_buffer* buffer):
raise Exception("releasing %s" % self.label)
raise Exception(f"releasing {self.label}")
#
# Structs
......@@ -336,13 +335,12 @@ cdef class LongComplexMockBuffer(MockBuffer):
def print_offsets(*args, size, newline=True):
sys.stdout.write(' '.join([str(item // size) for item in args]))
if newline:
sys.stdout.write('\n')
sys.stdout.write(' '.join([str(item // size) for item in args]) + ('\n' if newline else ''))
def print_int_offsets(*args, newline=True):
print_offsets(*args, size=sizeof(int), newline=newline)
shape_5_3_4_list = [[list(range(k * 12 + j * 4, k * 12 + j * 4 + 4))
for j in range(3)]
for k in range(5)]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment