Skip to content

Commit

Permalink
More example-tests (#258)
Browse files Browse the repository at this point in the history
* Add assertions to compute example

* add testable triangle example

* make importable

* fiz

* sigh - this is why I'm not a fan of pathlib...

* add ci-generated screenshot

* I wonder if this changes the order ...
  • Loading branch information
almarklein authored Apr 12, 2022
1 parent 77f62bd commit 05e0040
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
pytest -v wgpu/__pyinstaller
test-examples-build:
name: Test examples
name: Test Examples
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
11 changes: 7 additions & 4 deletions examples/compute_noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@

# The result is a dict matching the output types
# Select data from buffer at binding 1
result = out[1]
print(result.tolist())
result = out[1].tolist()
print(result)
assert result == list(range(20))


# %% The short version, using numpy
Expand Down Expand Up @@ -118,5 +119,7 @@

# Read result
# result = buffer2.read_data().cast("i")
result = device.queue.read_buffer(buffer2).cast("i")
print(result.tolist())
out = device.queue.read_buffer(buffer2).cast("i")
result = out.tolist()
print(result)
assert result == list(range(20))
Binary file added examples/screenshots/triangle_auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions examples/triangle_auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Import the viz from triangle.py and run it using the auto-gui.
"""
# test_example = true

import sys
from pathlib import Path

from wgpu.gui.auto import WgpuCanvas, run
import wgpu.backends.rs # noqa: F401, Select Rust backend

sys.path.insert(0, str(Path(__file__).parent))

from triangle import main # noqa: E402, The function to call to run the visualization


canvas = WgpuCanvas()
device = main(canvas)


if __name__ == "__main__":
run()

0 comments on commit 05e0040

Please sign in to comment.