Coder Social home page Coder Social logo

pytest-asptest's Introduction

ASP test

pytest plugin to test ASP source code.

The principle is simple: you write inputs and outputs in a dedicated file, you run pytest, pytest tells you which outputs are missing or unexpected.

Installation

pip install pytest-asptest

Obviously, in order to run ASP, a solver must be installed. The only one handled for now is clingo from potassco labs.

simple example

Let's consider dumbasp.lp, an ASP code we want to be tested:

p(1..3).
q(X): p(X).

We want to test the rule in second line. We therefore put it into a block (consecutive lines without blank lines) and give it a tag, rule-q:

p(1..3).

% TEST: rule-q
q(X): p(X).

Now we fill test-rule-q.lp with multiple tests:

% INPUT
% empty test: no input, no output
% INSATISFIABLE

% INPUT
p(1).
% OUTPUT
q(1).
% OUTPUT
q(2).  % This will lead to an error : there is no such answer set.

Now, we can run again asptest:

pytest dumbasp.lp

It will report the testing process, indicating which tests are passed, and which are not.

More examples are available in the Makefile, or in examples/

features

  • multiple files support ; tags are shared
  • handle generation of multiple answer sets, and strict keyword

strict output

By default, the atoms given in output parts must be a subset of the atoms present in the answer set. However, if you want to explicitely give all atoms that must appear in a given answer set, you can write % STRICT OUTPUT instead of % OUTPUT in the test file.

file uid

The file uid is given by default to all blocks of a file, and is the basename of the file. You can therefore implement test-queens.lp to test all the blocks found in file queens.lp, without having to manually tag all your blocks with it.

CLI options

asptest add one option to pytest: --uid-tests-dir, allowing user to give to asptest the directory in which the test-*.lp files are. For instance, pytest . -vv --uid-tests-dir asp-test would allow you to test all ASP files in the current directory, using the test files in asp-test/ dir.

TODO

  • auto include input code into output with flag with-output on OUTPUT lines in test files

pytest-asptest's People

Contributors

aluriak avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

pytest-asptest's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.