Skip to main content

Gold testing toolkit

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

midastest-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

midastest-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file midastest-0.0.1.tar.gz.

File metadata

  • Download URL: midastest-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for midastest-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2e91fcd9547004893c39e1b99a49b4d3b6bf979a18b247e0e14927aa84e87025
MD5 bfbac75e90eee11efc24dc67ba0bacf4
BLAKE2b-256 e5b2a80a4c7e7ba3021ecbfa61075ce979cc66cfc5f54dbb4fa7344c5b701868

See more details on using hashes here.

File details

Details for the file midastest-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: midastest-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for midastest-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cadf1ed57d3ecabc0329294ac8d96446da0608b0c1a0dfc7f73250ee622b3673
MD5 4e9e6dd727afbb8e46896a1bd826758a
BLAKE2b-256 d192ebffbf2124d25a7c4e51fcc31f7cfe6778a6e5304d543d54ee16c8df5481

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page