Skip to main content

Midas - Python Gold Testing Toolkit

If you're tired of writing assertions like assert my_func('input') == 'output', just tell midas your inputs and it will automate all the rest!

Installation

pip install midastest

Usage

Write a test using your favorite testing framework. You can use any framework as long as it's pytest:

import midas

@midas.test(format='lines')
def test_length(line):
    return str(len(line))

Create a file test_length.in with a few examples:

Hello
Foo

What a wonderful world

Run your testing tool:

pytest
# TODO: show complaining output

After inspecting the output, move it to a file called test_length.gold:

mv test_length.actual test_length.gold

Run your testing tool again:

pytest

It succeeds!

What happened is that test_length.gold contains the expected inputs and outputs of the tests, and running the tests compares actual outputs with expected outputs:

cat test_length.gold
{
  "Hello": "'5'",
  "Foo": "'3'",
  "": "'0'",
  "What a wonderful world": "'22'"
}

Try changing the code:

import pytest

@midas.test(format='lines')
def test_length(line):
    return str(len(line) * 2)

Run pytest again and watch your tests fail:

==================================================================== test session starts =====================================================================
platform darwin -- Python 3.8.9, pytest-7.0.1, pluggy-1.0.0
rootdir: /Users/aursaraf/dev/dojo/midas
collected 4 items                                                                                                                                            

tests/test_api.py FF.F                                                                                                                                 [100%]

[..]
__________________________________________________________ test_length[What a wonderful world-'22'] __________________________________________________________

[..]
expected = "'22'", actual = "'44'"

    def midas_assert(expected, actual):
>       assert expected == actual
E       AssertionError

midas/__init__.py:12: AssertionError
================================================================== short test summary info ===================================================================
FAILED tests/test_api.py::test_length[Hello-'5'] - AssertionError
FAILED tests/test_api.py::test_length[Foo-'3'] - AssertionError
FAILED tests/test_api.py::test_length[What a wonderful world-'22'] - AssertionError
================================================================ 3 failed, 1 passed in 0.03s =================================================================

License

midas is distributed under the MIT license.

Metadata

Release files for midastest 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for midastest 0.0.1
File Size Uploaded
midastest-0.0.1.tar.gz 4.5 kB Details

Built distribution (wheel)

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

Total release size: 9.5 kB

Release files / midastest-0.0.1.tar.gz

Download URL midastest-0.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2e91fcd9547004893c39e1b99a49b4d3b6bf979a18b247e0e14927aa84e87025
BLAKE2b-256 checksum
How to use checksums
e5b2a80a4c7e7ba3021ecbfa61075ce979cc66cfc5f54dbb4fa7344c5b701868
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

Release files / midastest-0.0.1-py3-none-any.whl

Download URL midastest-0.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cadf1ed57d3ecabc0329294ac8d96446da0608b0c1a0dfc7f73250ee622b3673
BLAKE2b-256 checksum
How to use checksums
d192ebffbf2124d25a7c4e51fcc31f7cfe6778a6e5304d543d54ee16c8df5481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.0.1 This release

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