Tests for lazy (smart) devs
Project description
What is this?
Simple automated tests; for grug devs like me who don't have time to test.
How do I use this?
pip install grug_test
from grug_test import GrugTest
import os
# 1. say where the tests will be saved
grug_test = GrugTest(
project_folder=".",
test_folder="./tests/grug_tests",
fully_disable=os.environ.get("PROD")!=None,
replay_inputs=os.environ.get("RUN_TEST_CASES")!=None,
record_io=True, # set to false when want a faster runtime while debugging
# NOTE: fully_disable does override this setting
)
# 2. slap @grug_test on any of your pure-functions
@grug_test
def repeat(a,times):
for _ in range(times):
a += f"{a}"
return a
- That's all the setup!
- The "test cases" are generated when you set
GrugTest(record_io=True)
and run your normal workflow - Commit your generated "test cases" (input/output files) to git
- Then when you want to test, run your normal workflow with
GrugTest(replay_inputs=True)
. Once its done git-diff will show you all the changes.- If you like the changes, well volia, those are your freshly-written test cases
- If you don't like the changes, well then it looks like you've got some dev work to do
Q&A
Does this work with @staticmethod
?
- Yes but you have to put the decorator it on the line BELOW the
@staticmethod
Does this work with ANY pure function?
- Almost, the arguments need to be seralizable. For example, if you pass a lambda function as an argument then grug_test can't really save/load that lambda function when
replay_inputs=True
. However, you can make almost any normal class seralizable, just checkout a tutorial on making a class work with python-pickle, or (even better) dofrom grug_test import yaml
and make your class be yaml-seralizable (tutorial/example here)
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
grug_test-0.0.5.tar.gz
(6.6 MB
view hashes)
Built Distribution
grug_test-0.0.5-py3-none-any.whl
(644.2 kB
view hashes)
Close
Hashes for grug_test-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b390620fd6e4b9555289c0e7c21c482d2013d682c2bb294334816917ecb9fa6 |
|
MD5 | 36fb29fa84ba98443c163f86a309826d |
|
BLAKE2b-256 | b26c99d9af5d0fd6beddabe8e2a62ca02c338f7ecfdf79c94b3cdb8d7d4cb38e |