But, what is a quail? That's a quail. So cute 🥺
- The purpose of Quail is to be an easy to use, expandable and developper friendly framework to write unit tests for the Flyable compiler. It is built on top of pytest to have access to its vast set of tools and to integrate elegantly with IDEs
Quail Tests are the meat and bones of the Quail unit testing utility.
- Open your terminal, and enter the command
python -m venv venv
to create a new python envrionment - In the same terminal enter the command
venv\Scripts\activate.bat
if you have a Windows andvenv/Scripts/activate
if you have a Mac or a Linux distro to enter the virtual environment - In the same terminal, enter the command
pip install --editable .
- If all went well, you should now be able to use the Quail cli from your terminal. Try entering the command
quail
- If it worked, enter the command
quail run
for the first time and it should have created a configuration file for you. - Change the configuration file depending on your machine and installation directories
- Done! 🥳
Running Quail tests is really simple. You can use the Quail CLI to do so.
Running all the unit tests: quail run -u
Running a specific test suite: quail run -u <test_suite>
Running all the integration tests:
quail run -i
Running a specific integration test:
quail run -i <test_name>
They operate, in their most basic form, by:
- Using the python interpreter to:
- Compile the lines of code in the test
- Running the test and saving the output of the
stdout
(standard out)
- Using the flyable compiler to:
- Compile the lines of code in the test
- Running the test and saving the output of the
stdout
(standard out)
- Comparing those outputs
First, let's look a typical Quail Test and analyse it:
# Quail-test:new
"""
Name: basic_addition
Flyable-version: v0.1a1
Description: Test the addition operator on int
"""
# Quail-test:start
0 + 0 # Quail-assert: eq 0
0 + 1 # Quail-assert: eq 1
1 + 1 # Quail-assert: eq 2
-10 + 23 # Quail-assert: eq 13
# Quail-test:end
For now, let's ignore the weird comments starting with # Quail-...
and focus on their content and overall structure.
Quail tests are separated in multiple sections:
- The information section
- The test body section
Let's look at them in further details
This section is the first section of every Quail test and contains all the metadata related to the test.
In our example, it's this part:
"""
Name: basic_addition
Flyable-version: v0.1a1
Description: Test the addition operator on int
"""
As we can see, this section is placed in a python multiline string and contains the following:
- The
Name
tag followed by the name of the test (ex:basic_addition
) - The
Flyable-version
followed by the version of the Flyable compiler it's testing (ex:v0.1a1
) - A
Description
tag followed by the description of the what the Quail Test is, well... testing ( ex:Test the addition operator on int
) - --Optional-- The
Timeout
tag followed by the amount of seconds to wait after compiling the test using flyable - --Optional-- The
No-Wrap
tag followed by a boolean to indicate if Quail should by default wrap the test in a test_flyable function
This section contains what really matters, the lines of code to test ! In our example, it's this part:
0 + 0 # Quail-assert: eq 0
0 + 1 # Quail-assert: eq 1
1 + 1 # Quail-assert: eq 2
-10 + 23 # Quail-assert: eq 13
It's the content of this section that will be compiled and ran by the python interpreter and the flyable compiler to see
if their outputs match at runtime. But how can we compare the stdout if there's no print calls? And, most of all, what's
up with those # Quail-assert:...
anyway? Those are really good questions and I feel like it's time to address them!
Let's come back to those weird comments that start with # Quail-...
. They are called Quail tags and are part of what
makes Quail so flexible. Each Quail tag follow a specific syntax:
# Quail-<tag_type>:<tag_name> [value]
Currently, they come in one of two types, Quail-test tags and Quail-assert tags.
Quail-test
tags allow the Quail Parser to know how the test is divided and parse the correct sections at the correct
time. In our example, it's those:
# Quail-test:new
# Quail-test:start
# Quail-test:end
To see every Quail-test tag and its effect, see The list of Quail-test tags
Quail-assert
tags tell the Quail Parser how to modify the current line to test something in particular. They also help
to remove boilerplate code and make the test more readable. In our example, it's those:
# Quail-assert: eq 0
# Quail-assert: eq 1
# Quail-assert: eq 2
# Quail-assert: eq 13
To see every Quail-assert tag and its effect, see The list of Quail-assert tags
They are in Flyable/tests/unit_tests
Quail tests are in the quailt*.py files (quailt stands for quail test)
In the same folder as this file must be a test*.py file from which the tests will be ran
Let's say I want to write a new test suite to test how Flyable handles lists with Quail.
First, we will see how to add a new quail test suite
Second, we will see how to add a new quail test to a quail test suite
- For example, I'm going to make a new quail test suite nammed 'list' by typing
Quail new list
- I answer the prompts Quail shows me (you can also directly put your values in the command, see
Quail new --help
) - Done! 🥳
- For example, I'm going to add a new test called 'creating_lists' by
typing
Quail add list --test_name creating_lists
- I answer the prompts Quail shows me (you can also directly put your values in the command, see
Quail add --help
) - Done! 🥳