Skip to main content

ParserKiosk: A Proof of Concept multi-lingual test generation suite intended for parsers

Coverage Status Downloads

Motivation

After reading this article and this one, I am now paranoid and under the assumption that implementations of data serialization and deserialization have a lot of quirks that differ from language to language, and implementation to implementation.

This could lead to serious security issues as applications, especially web applicatons usually utilize multiple services, written in multiple languages that use the same format to communicate.

Reference implementations usually provide tests, but translating them from language to language is tiresome and tedious. I wanted to compose a library to generate simple, functional tests for multiple languages with minimal repitition.

Usage

  1. Install
$ pip install parserkiosk
  1. Define a config.yaml
# config.yaml
---
import_string: "from my_parser import serialize, deserialize"
serialize_function: "serialize"
de_serialize_function: "deserialize"
assert_functions:
  - my_assert_function
  1. Define a yaml file prefixed with test_ in the same directory as config.yaml
# test_serialize.yaml
type: "SERIALIZE"
tests:
  test_something:
      info: "Example Test"
      input:
        type: "str"
        arg: "hello, world"
      assert:
        func: "my_assert_function"
        arg: "[\"hello\", \" world\"]"
  1. Run parserkiosk in the same directory as config.yaml and test_serialize.yaml
$ parserkiosk . --builtin python
  1. See output directory tests/
$ ls tests/
test_serialize.py

See HOWTO for a complete guide.

How does it work?

Parserkiosk uses jinja2 templates to generate test cases from yaml file(s). You can either expect something to fail(raise an "exception" or "error") or use a function that you define in a special file called commons to assert if the parsed data matches the expected internal representation.

Let's say you've written a reference implementation of your data de/serialization format in Go and I wanted to implement it in Python.
All I would need to do to implement your test-suite is:

  1. Write a commons.py file implementing the same assertion functions that you've written in your commons.go file
  2. Adapt your parserkiosk config to use my implementation
  3. Run $ parserkiosk folder_with_yaml_test_files/ --builtin python and voila I have your entire test suite implemented!

For more on this, see examples/json/

Languages supported

  • Python / pytest / python
  • NodeJS / jest (sync) / node_js
  • NodeJS / jest (async)
  • Lua
  • Go
  • Java
  • PHP
  • Perl
  • Ruby
  • ...

License

All work is licensed under GPL-3.0 excluding the example JSON test-suite which is licensed under MIT

Contributing

Issues, feedback and pull requests are welcome. I have tried my best to keep the code simple. Please keep in mind that I wish to limit features that we accomodate to keep it simple. Tests should be simple and readable.

Installing for development

$ git clone https://github.com/you/your-fork-of-parserkiosk.git
$ cd your-fork-of-parserkiosk
$ poetry install
$ poetry run pre-commit install
# do some changes
$ ./runtests.sh
# you are ready!

Thanks

Special thanks to nst for inspiring Parserkiosk. All test cases in examples/json come from his incredible work

Release files for parserkiosk 0.3.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 parserkiosk 0.3.0
File Size Uploaded
parserkiosk-0.3.0.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parserkiosk 0.3.0
File Interpreter ABI Platform
parserkiosk-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.6 kB

Release files / parserkiosk-0.3.0.tar.gz

Download URL parserkiosk-0.3.0.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6e7aa1ec92062c1952e1a63ed400484ead8d05613a4287bcc2183785e2235078
BLAKE2b-256 checksum
How to use checksums
367c1bb99dc59410a7628a983a3c747377b096fcdde313dd9e2130b4f0f8b6fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.10.0-13-amd64

Release files / parserkiosk-0.3.0-py3-none-any.whl

Download URL parserkiosk-0.3.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ceca6df705a8e24cb67e6de17730079ef3aebdcbe757444ae9a2e6982d5116b
BLAKE2b-256 checksum
How to use checksums
52ff5635ca1c882c8e555a3ede9522ad17f918ff67c9356a5133b423ec94e7df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.10.0-13-amd64

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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