Skip to main content

firefly-test

Framework for writing tests for Firefly Zero apps. This is a Python library, so the tests using it are writtten in Pytohn as well. However, you can test a Firefly Zero app or game written in any language, not just Python.

If you don't know Python, don't panic: it's a simple language for simple tasks, and you can learn it good enoug to write your first tests in a matter of minutes. And this documentation will help you.

Installation

python3 -m pip install firefly-test

Installation from the source is currently not possible: the project depends on firefly-runtime which is not open-sourced yet (but will be soon). The wheel distributions on PyPI contain the compiled binaries for the runtime.

Writing tests in Python

The most popular and simple tool for running Python tests is pytest. Make sure you have it installed:

python3 -m pip install --break-system-packages pytest

Tests should be placed in the tests directory in the root of the project. Each file with tests should start with test_. And each test function also should start with test_. For example, create tests/test_math.py:

import math

def test_cos():
    assert math.cos(0.0) == 1.0

Now, run the tests:

pytest

You can read more in the pytest documentation: docs.pytest.org.

Installing your app

The framework tests not your source code but a compiled and installed app. So, make sure to build and install your project:

firefly_cli build

In the examples below, we'll be using sys.input-test as our test target. If you want to follow along, make sure you have it installed:

firefly_cli import sys.input-test

Using firefly-test

The App class accepts the ID of the app you want to test and provides methods and attributes for interacting with the app:

from firefly_test import App
app = App('sys.input-test')

The first thing you should do is start your app. It will initialize the app memory, call the boot callback, etc.

app.start()

Now each time you call update, it will run one update cycle: call the update and render app callbacks, read inputs, flash the image from the frame buffer on the fake screen, etc.

app.update()

After the update, you can access the frame buffer using the frame attribute. The frame has a lot of helpful methods for checking the image it contains. For example, you can use the at method to get the color value of the pixel at the given coordinates:

from firefly_test import Color
assert app.frame.at(x=0, y=0) == Color.WHITE

we can iterate over all pixels and, for example, check that every pixel is one of the 3 expected colors:

allowed_colors = {Color.WHITE, Color.LIGHT_GRAY, Color.GRAY}
for color in app.frame:
    assert color in allowed_colors

The update method may also accept Input. This is the input value that this and all subsequent colors will receive (until overwritten). For example, check that pressing the S button changes the color fo the pixel (x=185, y=100) from white to light blue:

assert app.frame.at(185, 100) == Color.WHITE
app.update(Input(s=True))
assert app.frame.at(185, 100) == Color.LIGHT_BLUE

You can find this test (and the others covered below) in the tests/test_integration.py file.

Pattern testing

You can assert that a subregion of a frame matches a pattern. A pattern is an ASCII where each symbols represent an expected color:

  • .: any color.
  • K: black.
  • P: purple.
  • R: red.
  • O: orange.
  • Y: yellow.
  • G: green.
  • g: light green.
  • D: dark green.
  • B: blue.
  • d: dark blue.
  • b: light blue.
  • C: cyan.
  • W: white.
  • ◔: light gray.
  • ◑: gray.
  • ◕: dark gray.

Take a frame subregion:

circle = app.frame.get_sub(
    x=160, y=100, width=20, height=5,
)

Assert that it matches a pattern:

circle.assert_match("""
    WWWW◑◑◑◑◑◑◑◑◑◑◑◑WWWW
    WWW◑◑◑◑WWWWWW◑◑◑◑WWW
    WW◑◑◑WWWWWWWWWW◑◑◑WW
    W◑◑◑WWWWWWWWWWWW◑◑◑W
    ◑◑◑WWWWWWWWWWWWWW◑◑◑
""")

In this example, we checked that the selected region is a gray circle's top on a white background.

Snapshot testing

You can compare a frame or frame region to a snapshot:

from pathlib import Path
snapshots = Path(__file__).parent / '.snapshots'
app.update()
app.frame.assert_match(snapshots / 'default')

On the first run, the test will save the frame in the .snapshots/default file. When you run it the next time, it will read the old frame from the file and compare it to the current one. If they mismatch, even by one pixel, the test will fail. You can use to_png method of the frame to save it into a PNG file and see how it looks like. If the change is desirable, you can remove the old snapshot and the next run will save the new snapshot.

License

MIT License. You can freely use it for testing any apps and games, free or commercial, open-source or proprietary. Happy hacking!

Release files for firefly-test 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for firefly-test 0.1.5
File Size Uploaded
firefly_test-0.1.5.tar.gz 40.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for firefly-test 0.1.5
File
firefly_test-0.1.5-cp314-cp314-manylinux_2_38_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.38+ x86-64 Details
firefly_test-0.1.5-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
firefly_test-0.1.5-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details
firefly_test-0.1.5-cp313-cp313-manylinux_2_38_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.38+ x86-64 Details
firefly_test-0.1.5-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
firefly_test-0.1.5-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
firefly_test-0.1.5-cp312-cp312-manylinux_2_38_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.38+ x86-64 Details
firefly_test-0.1.5-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
firefly_test-0.1.5-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 14.4 MB

Release files / firefly_test-0.1.5.tar.gz

Download URL firefly_test-0.1.5.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d64a3d32bda4d3e8c9e4bf70fa9d68078898eaa68f14bf35cee463bbcae2af50
BLAKE2b-256 checksum
How to use checksums
666cfb3b41e8d06e9f30ee4c76e72595f274f274b6801e1a14069afda5e2fc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp314-cp314-manylinux_2_38_x86_64.whl

Download URL firefly_test-0.1.5-cp314-cp314-manylinux_2_38_x86_64.whl
Size 2.1 MB
Tags CPython 3.14 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
52ceb206cad72ab9731db3cfce28a7ec27e51b82c942ba7525a0c7b38d8f6987
BLAKE2b-256 checksum
How to use checksums
b967747c835e31fc03a54a8dfa4a941cbbf5bd76d38403c8595586afd7494474
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp314-cp314-macosx_11_0_arm64.whl

Download URL firefly_test-0.1.5-cp314-cp314-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bae8bc2963f850f4e392f638b559c7549cec803bf6597fd66b0e631b91a8f648
BLAKE2b-256 checksum
How to use checksums
fcbbc3c9ac45dee8b3bef76b732de3ef27729ed2f2e2871014e9269ad24bb88d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp314-cp314-macosx_10_12_x86_64.whl

Download URL firefly_test-0.1.5-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e0798352534ed18a330a60f59174b72fc1aeb2a42b722e7290e68a5093ec9d80
BLAKE2b-256 checksum
How to use checksums
25d27c78aada736ea524c84d20df22fdab7e83b880226317e4cddb4b20391f77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp313-cp313-manylinux_2_38_x86_64.whl

Download URL firefly_test-0.1.5-cp313-cp313-manylinux_2_38_x86_64.whl
Size 2.1 MB
Tags CPython 3.13 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
97e08814becda06c965c69adab0555153320cd695ef83c9e5227ac0230a13091
BLAKE2b-256 checksum
How to use checksums
4c8cb4c51ed6df10276fd64dc1be0fb41bd414f70ea702068031e91e12bc8205
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp313-cp313-macosx_11_0_arm64.whl

Download URL firefly_test-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d2a2148469e14f8d93eb9eed0ff0fef33db860ba490b897e72d05f0686841278
BLAKE2b-256 checksum
How to use checksums
597352d14630dfea62f82122cc7c73d6282357f86324d0bdf888562a221afc6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp313-cp313-macosx_10_12_x86_64.whl

Download URL firefly_test-0.1.5-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8f378d58188718c6a003cfe523434b07397fb1569062a91b284ff41f647cb6d3
BLAKE2b-256 checksum
How to use checksums
8aab436ba063508cfdb91ca11eb7ccc479f63ee2f1dafd170f4908d810c36f80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp312-cp312-manylinux_2_38_x86_64.whl

Download URL firefly_test-0.1.5-cp312-cp312-manylinux_2_38_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
7385006d3d2e763148a3c329c487e62e9c4ae27e0610200d7e87aaf9ea0bd0d0
BLAKE2b-256 checksum
How to use checksums
d544db1c6f516a2ccf7a8979de9c246d3d2993071644f638244282632a4ffcf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp312-cp312-macosx_11_0_arm64.whl

Download URL firefly_test-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
35ad61d6a6b76d3210ad4ab0a534d8e9ec6122d4579aba074a926d6d5a1bdf39
BLAKE2b-256 checksum
How to use checksums
9f48182cc623aa87a758c05fedbc45f453815c5b8c8ae79a7957be3e601045f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release files / firefly_test-0.1.5-cp312-cp312-macosx_10_12_x86_64.whl

Download URL firefly_test-0.1.5-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.4 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
685ef2292bf2ebe7f60e8dfa06c7f1ac926be22db44c8f309a96121f5b4df572
BLAKE2b-256 checksum
How to use checksums
7f5c6edbd45eaa73ecd064c0c949d7b864dcca6a39f4e1f22c7408f0b144467c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.1

Release history Release notifications | RSS feed

This release

0.1.5 This release

10 release files

0.1.4

4 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page