A tool for running in-source unittests for Anwer Set Programming (ASP)
Project description
asp-selftest
In-source test runner for Answer Set Programming (ASP) with Clingo.
Status
This tools is still a work in progress.
This Test-Tool has been presented at (Declarative Amsterdam in November 2024)[https://declarative.amsterdam/program-2024]. All the materials, including the presentation, are online and can be found via the given link.
It is currently in transition from asp-test towards clingo-tests. The latter is a drop-in replacement for clingo with the added ability to activate plugins. The former is still around.
A plugin for running the in-source unit tests is active by default. A plugin translating clingo (syntax) errors to Python exceptions with ASP source snippets with exact error location is also active.
You can write you own plugins. I have one for reifying rules from theory atoms, for example.
About
With in-source testing, source and tests stay together in the same file, hence the tests are also expressed in ASP.
The tests are as non-obstrusive as possible and and many examples are idiomatic in nature and could have been written in another way. These idioms are merely ways to provide clearer code and avoid mistakes. As such, they have value in themselves.
RUNNING
After installation via pip, run it using:
$ asp-tests <file.lp> ...
Alternatively you can run it as a module, given that either the working directory of the PYTHONPATH are set to 'src':
$ python -m asp_selftest <file.lp> ...
There are options to silents the in-source Python tests etc, have a look:
$ asp-tests -h
TESTING
The code is equiped with in-source Python tests which always run. You can silence them with --silent.
TODO
To use the program without the tests: Not Yet Implemented. But you can use the base program anywhere of course, since all #programs are ignored by default.
IDEA
-
Use
#program's to identify units and their dependencies. Here we have a unit calledunitAwith a unit test for it calledtestunitA.#program unit_A. #program test_unit_A(unit_A).The implicit program
base(see Clingo Guide) must be referenced explicitly if needed. -
Extend the notion of
#programby allowing the use of functions instead of only constants. This allows#programunits with constants being tested. Here is a unitstepthat is tested with constantabeing substituted with2:#program step(a). #program test_step(step(2)). % this feature is no longer present in `clingo-tests`.Note that using this feature makes the program incompatible with Clingo. The test runner has an option to transform a extended program back to compatible Clingo without running the tests.
-
Within a test program, use
assertwith@allto ensure universal truths that must be in every model. We use@allto communicate to the runtime that this particular assert must be checked for presence in every model. Its argument is just a name for identification.#program step(n). fact(n). #program test_step(step(3)). assert(@all("step fact")) :- fact(3).Note that
"step fact"is just a way of distinquishing the assert. It can be an atom, a string, a number or anything else. Pay attention to the uniqueness in case of variables in the body. Take note of point 5 below.You can use
@anyinstead of@allto assert truths that must be present in at least one model. -
To enable testing constraints and to guard tests for empty model sets, we use
@modelsto check for the expected number of models. In the example above, we would add:assert(@models(1)). -
Care must be taken if variables in the body lead to expansion and conjunctions. See
duplicate_assert.lp. The system gives a warning for:assert(@all(id_uniq)) :- def_id(Id, _, _), { def_id(Id, _, _) } = 1.Instead you have to write:
assert(@all(id_uniq(Id))) :- def_id(Id, _, _), { def_id(Id, _, _) } = 1.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asp_selftest-0.0.21.tar.gz.
File metadata
- Download URL: asp_selftest-0.0.21.tar.gz
- Upload date:
- Size: 48.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3602ab3d1a978fc967482b37415a91ac41a17fa0b4a7c9c5a7a22ba40fd6457f
|
|
| MD5 |
c66b4207e800eea8f02a056935c44876
|
|
| BLAKE2b-256 |
360b89fe134171e0779780933891477fd961898ff94088fe33d0a72b03040ce9
|
File details
Details for the file asp_selftest-0.0.21-py3-none-any.whl.
File metadata
- Download URL: asp_selftest-0.0.21-py3-none-any.whl
- Upload date:
- Size: 53.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44983ec5e9ef5d67adb0714bb0ff5ed71ff0a2e9e66bbc541bc3044c4042704a
|
|
| MD5 |
c937bc77d4886c8d7ab01b9a26c7c71e
|
|
| BLAKE2b-256 |
9887765af55f98789672f9b519b225d67224cc54ea0ae80b7283c7a83eec4a9e
|