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!

Metadata

Release files for firefly-test 0.2.0

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.2.0
File Size Uploaded Provenance Actions
firefly_test-0.2.0.tar.gz 36.5 kB Without provenance Details for firefly_test-0.2.0.tar.gz

Built distributions (wheels)

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

Total release size: 14.0 MB

Release files / firefly_test-0.2.0.tar.gz

Download URL firefly_test-0.2.0.tar.gz
Size 36.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a8a1aec30e70b3b21ab3c7c15d37b6486cdb2c6e2b4f0a9b5d7d25968e0c1ec9
BLAKE2b-256 checksum
How to use checksums
4c06fd2b3b76c0106fa65ae9b3c4053f7650ef782ceee3f00608d75973f4ae5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / firefly_test-0.2.0-cp315-cp315-manylinux_2_38_x86_64.whl

Download URL firefly_test-0.2.0-cp315-cp315-manylinux_2_38_x86_64.whl
Size 1.8 MB
Tags CPython 3.15 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
e948d7aca9b0efe59b123d7da597d57e6ab5a2cc0afaebcdaf2aa25668ad196a
BLAKE2b-256 checksum
How to use checksums
a862284caf588b284a3e3d01641bf031b0e01ef4774a6296a751226a454db09c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / firefly_test-0.2.0-cp315-cp315-macosx_11_0_arm64.whl

Download URL firefly_test-0.2.0-cp315-cp315-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.15 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ef30d9d7e892d7d37bcdcc5c6c64030b1edaf22030ad19816cb8d9580f003507
BLAKE2b-256 checksum
How to use checksums
cd0ca04a7d03b688322a9bb7d84dccda9833731166548ec6dea21b123ae42f73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Release files / firefly_test-0.2.0-cp315-cp315-macosx_10_12_x86_64.whl

Download URL firefly_test-0.2.0-cp315-cp315-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags CPython 3.15 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e7ee173e4354598b1332366423223b226fa77a394ae32dd972020c42171c521e
BLAKE2b-256 checksum
How to use checksums
ac4b6735db5550db8b21a13675e8b921253fa5dad397228b70a573b61af4f102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp314-cp314-manylinux_2_38_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
d0eb36eb06cb1f34a2501410fed8e5664cf27938f102f8b0fbfeb13c2a5bb186
BLAKE2b-256 checksum
How to use checksums
92fec3cf98339fc12306dc5fb3b373cf4444aebd570f6733f022fde4691d9c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ceb77984ac9405cb6363e50854ca0b948de7886aa9ea418ef25e688d26548184
BLAKE2b-256 checksum
How to use checksums
1c074310122b983c66eb68fc85ca652fb10f403b68da915c2a85178650ee6505
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
96e25df6ef1cca6b5ad394f8cbf30e7fb59caf54d186243a1c710922214b3e4c
BLAKE2b-256 checksum
How to use checksums
1efb4b8f1b0be8a2e756694f85264326f11a1b8d70c893971ebd46fa658230ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp313-cp313-manylinux_2_38_x86_64.whl
Size 1.8 MB
Tags CPython 3.13 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
f722deadc8abe1b9b79218100aaa6b58a2e505988f68658e6a8e1303a017e45e
BLAKE2b-256 checksum
How to use checksums
b64a87412de076b26f3f19a3de176d3c9dde490abd14593c31c592757a0c105c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9d975abd6462b599accc29d06c01f454ca705eef45b820c20c59b685e0325403
BLAKE2b-256 checksum
How to use checksums
61926f0ca7435e4a839f1ccf61d670a717425c54c799863c05588db024b21135
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

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

Download URL firefly_test-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ebc48c70b0b5b9c60ae0313ca657f22e391a65760c5707c1415fc14701719383
BLAKE2b-256 checksum
How to use checksums
cc31dda56a0496ec843d25fc4461ebacdfb00098f8eacda852b6e5d349152a3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.16.0

Security for firefly-test 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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