From 05e00407c454560efb23bca3f7b5f73f687e4960 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 12 Apr 2022 16:53:37 +0200 Subject: [PATCH] More example-tests (#258) * 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 ... --- .github/workflows/ci.yml | 2 +- examples/compute_noop.py | 11 +++++++---- examples/screenshots/triangle_auto.png | Bin 0 -> 4405 bytes examples/triangle_auto.py | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 examples/screenshots/triangle_auto.png create mode 100644 examples/triangle_auto.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3910f273..9cba4f0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/examples/compute_noop.py b/examples/compute_noop.py index 57b6b266..c0795554 100644 --- a/examples/compute_noop.py +++ b/examples/compute_noop.py @@ -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 @@ -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)) diff --git a/examples/screenshots/triangle_auto.png b/examples/screenshots/triangle_auto.png new file mode 100644 index 0000000000000000000000000000000000000000..ac430851d09b1948ad37b4fd6c4a1d4ca056a12c GIT binary patch literal 4405 zcmeHKc{r8r*1z{)d(4k1l40|fRM>`)A@(*DugXww@ro2F5t)_Zu}MiG3R{v+9eF!1 zAt_VXiB#C+7>Wp?ZOV`#)43mS*SXHQuJ1e7IoEZ*|2}`&>sjl!e(S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OEU(MaRjwbG z<8!EBEJXrx>0`y1uji9#KRP47ymV9mwPg8%yY5Zed?MP&cS?Szo0Lyr4}&`jOzU-P z(M&Hb%Gyv(zPl@+P|%CXLP2ywgQT7P)gu9>g2yA^?Jq~*-vWi?QGUb zI|j#f$FiH0$>0hz1M>XUf!mxEryvzU1(Dl#%A19z#LD~-Cf##pphJK3<06;!8Ixuz8cKduoX< zycydj==6z@skTIM19(@)td?FMBfy_x;)YSqhwGe~%-nB_OhC?(uatxZ6S9>h@T`uH@vN>0^R7huycz?Pk}-q~ zaU{6Eii#j~*Fd7uq4tF_NChrgLX3nn^X*cjF9qJ_CwUP%CK`*c8oGa;6c^T(zDeCa zII0JdgCMYS3GN(Q7BVcW+4Zx}Oc-o3UQ-dZl+2gEh=*V4+PDHOfi@V_3>ZxEP6|Qo zOib^4>6HyaKyxaL$+8`((STdR`Wth96JBzN#p4L9VQ9gup4*`o`@3sVWn;D8$j~~7?7ms}+o7F4f6zg3t4e$o z3A)+LKiWZt?0?H#f9_VzTGerMytdeeV`vTsez1C^55kIRO8xEcTh_nYuFn1_kpDmH+?% literal 0 HcmV?d00001 diff --git a/examples/triangle_auto.py b/examples/triangle_auto.py new file mode 100644 index 00000000..bf567be1 --- /dev/null +++ b/examples/triangle_auto.py @@ -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()