Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f59fb19

Browse filesBrowse files
committed
test offset and size
1 parent 5e1471e commit f59fb19
Copy full SHA for f59fb19

File tree

1 file changed

+19
-2
lines changed
Filter options

1 file changed

+19
-2
lines changed

‎tests/test_buffer_manager.py

Copy file name to clipboardExpand all lines: tests/test_buffer_manager.py
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def generate_slice_indices(kind: int):
4040
case 2:
4141
# positive continuous range
4242
s = slice(1, 5, None)
43-
indices = list(range(1, 5))
43+
indices = [1, 2, 3, 4]
4444

4545
case 3:
4646
# positive stepped range
@@ -114,7 +114,9 @@ def generate_slice_indices(kind: int):
114114

115115
others = [i for i in a if i not in indices]
116116

117-
return {"slice": s, "indices": indices, "others": others}
117+
offset, size = (min(indices), np.ptp(indices) + 1)
118+
119+
return {"slice": s, "indices": indices, "others": others, "offset": offset, "size": size}
118120

119121

120122
def make_colors_buffer() -> ColorFeature:
@@ -205,14 +207,29 @@ def test_slice(color_input, slice_method: dict):
205207
# slicing only first dim
206208
colors = make_colors_buffer()
207209

210+
# TODO: placeholder until I make a testing figure where we draw frames only on call
211+
colors.buffer._gfx_pending_uploads.clear()
212+
208213
s = slice_method["slice"]
209214
indices = slice_method["indices"]
215+
offset = slice_method["offset"]
216+
size = slice_method["size"]
210217
others = slice_method["others"]
211218

212219
colors[s] = color_input
213220
truth = np.repeat([pygfx.Color(color_input)], repeats=len(indices), axis=0)
214221
# check that correct indices are modified
215222
npt.assert_almost_equal(colors[s], truth)
223+
224+
upload_offset, upload_size = colors.buffer._gfx_pending_uploads[-1]
225+
# sometimes when slicing with step, it will over-estimate offset
226+
# but it overestimates to upload 1 extra point so it's fine
227+
assert (upload_offset == offset) or (upload_offset == offset - 1)
228+
229+
# sometimes when slicing with step, it will over-estimate size
230+
# but it overestimates to upload 1 extra point so it's fine
231+
assert (upload_size == size) or (upload_size == size + 1)
232+
216233
# check that others are not touched
217234
others_truth = np.repeat([[1., 1., 1., 1.]], repeats=len(others), axis=0)
218235
npt.assert_almost_equal(colors[others], others_truth)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.