Skip to content

Commit 7724ce3

Browse files
committed
Test using an IO adapter; remove redundant BytesIO tests
1 parent c27d5ad commit 7724ce3

File tree

2 files changed

+50
-100
lines changed

2 files changed

+50
-100
lines changed

tests/circuitpython/jpegio_decompress.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ def test(jpeg_input, scale, fill=0xFFFF, **position_and_crop):
9191
print(f"{memoryview(refb) == memoryview(b)=}")
9292

9393

94+
class IOAdapter(io.IOBase):
95+
def __init__(self, content):
96+
self._content = memoryview(content).cast("b")
97+
self._pos = 0
98+
99+
def readinto(self, buf):
100+
pos = self._pos
101+
data = self._content[pos : pos + len(buf)]
102+
len_data = len(data)
103+
buf[:len_data] = data
104+
self._pos = pos + len_data
105+
return len_data
106+
107+
94108
print("bytes")
95109
test(content, scale=0)
96110
test(content, scale=1)
@@ -100,9 +114,10 @@ def test(jpeg_input, scale, fill=0xFFFF, **position_and_crop):
100114
bytesio = io.BytesIO(content)
101115

102116
print("BytesIO")
103-
test(io.BytesIO(content), scale=0)
104-
test(io.BytesIO(content), scale=1)
105-
test(io.BytesIO(content), scale=2)
117+
test(io.BytesIO(content), scale=3)
118+
119+
ioadapter = IOAdapter(content)
120+
print("IOAdapter")
106121
test(io.BytesIO(content), scale=3)
107122

108123
print("crop & move")

tests/circuitpython/jpegio_decompress.py.exp

Lines changed: 32 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -132,105 +132,40 @@ bytes
132132
...
133133

134134
BytesIO
135-
240x240
136-
...
137-
...
138-
...
139-
...
140-
...
141-
...
142-
...
143-
...
144-
...
145-
...
146-
...
147-
...
148-
...
149-
...
150-
...
151-
...
152-
...
153-
...
154-
...
155-
...
156-
###### ...
157-
###### ...
158-
###### ...
159-
###### ...
160-
# ###### ...
161-
###### ...
162-
...
163-
##...
164-
## #### ...
165-
### #...
166-
...
167-
168-
120x120
169-
#### ...
170-
### ...
171-
...
172-
### ...
173-
### # ...
174-
### ### ##### ## ...
175-
# ######### # ## ...
176-
# ########### # ## ...
177-
# # ############## # ### ...
178-
##### ######## ## ### ...
179-
### # #### ## # ###### # ## ...
180-
### # ## # ## # # ###### # # ...
181-
### # ## # # # # # ######## # ...
182-
## ## # ## ############ # ...
183-
## # ## # #### ########### # ...
184-
######## ## ### ## ########### ...
185-
# ## ############# ### ## ###### # #...
186-
## ############### # ### # # ## ###### # #...
187-
#### ########### # ### ## ####### # #...
188-
# # ############ ### # ########## #...
189-
##### ############## #### ########### #...
190-
# ###################################### #...
191-
# ### ################################### #...
192-
######################################### #...
193-
## # ######### ################## # ...
194-
## ### ## #################### # ...
195-
## ######## ######################## # ...
196-
## #### ########################## ...
197-
# # ### ###################### ...
198-
# # ## ### ##################### ...
199-
...
200-
201-
60x60
202-
##
203-
#
204-
# ##### #
205-
# ##### # #
206-
# ####### # ##
207-
## ### # # ### #
208-
# # ### # # ####
209-
# ### # ######
210-
# ###### # # # ###
211-
######### # ####
212-
# # ####### #########
213-
###################
214-
# # ### #########
215-
### #############
216-
## ### ############
217-
# # # # ##########
218-
# ##########
219-
# ######## #
220-
# ######### #
221-
######## ##
222-
# #######
223-
# ########
224-
#########
225-
# ####### #
226-
# #######
227-
##### #
228-
##########
229-
######## #
230-
########## ####
231-
####
135+
30x30
136+
137+
###
138+
## ##
139+
#### ###
140+
#### ## #
141+
#### ## #
142+
## #### #
143+
#### ######
144+
#####
145+
####
146+
####
147+
###
148+
## # #
149+
### #
150+
# ####
151+
###
152+
## ## ## ## #
153+
# # ## #####
154+
# ##### #### ## ##
155+
# # ## ## ### ###
156+
# #### ##### ##
157+
## ##### ####### # #
158+
# # ## ######## ####
159+
##### ######
160+
## # ## ##############
161+
# ##### ########## # #
162+
####### ### ## ####
163+
# ### ##### ##
164+
## ##
165+
232166
...
233167

168+
IOAdapter
234169
30x30
235170

236171
###

0 commit comments

Comments
 (0)