grug-test


Namegrug-test JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/jeff-hykin/grug_test_py
SummaryTests for lazy (smart) devs
upload_time2023-09-07 16:42:12
maintainer
docs_urlNone
authorJeff Hykin
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # What is this?

Simple automated tests; for [grug](https://grugbrain.dev/) devs like me who don't have time to test.

# How do I use this?

`pip install grug_test`


In your `main.py` equivlent:

```python
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=os.environ.get("RECORD")!=None,
)

# 2. slap @grug_test on any of your pure-functions
@grug_test(max_io=100)
def repeat(a,times):
    for _ in range(times):
        a += f"{a}"
    return a

```

3. That's all the setup!
- `RECORD=True         python ./main.py` will record tests for you
- `RUN_TEST_CASES=True python ./main.py` will check your functions
- `PROD=True           python ./main.py` will run with grug totally disabled
- Make sure to commit the generated tests to git
    - When you do `RUN_TEST_CASES=True`, the git-diff will show you any problems
    - If you like the changes, well ✨volia✨ the git changes 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
    - thats it

# 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) do `from grug_test import yaml` and make your class be yaml-seralizable (tutorial/example [here](https://github.com/jeff-hykin/ez_yaml/blob/8b4dce8bf495484feb50f84468ffc6f776c357d4/README.md#custom-yaml-tags-example))



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jeff-hykin/grug_test_py",
    "name": "grug-test",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jeff Hykin",
    "author_email": "jeff.hykin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5a/92/e1f035fbc2041509c4aca0b6d308eb9d06213efcdac715362db67cec69b7/grug_test-0.2.0.tar.gz",
    "platform": null,
    "description": "# What is this?\n\nSimple automated tests; for [grug](https://grugbrain.dev/) devs like me who don't have time to test.\n\n# How do I use this?\n\n`pip install grug_test`\n\n\nIn your `main.py` equivlent:\n\n```python\nfrom grug_test import GrugTest\nimport os\n\n# 1. say where the tests will be saved\ngrug_test = GrugTest(\n    project_folder=\".\",\n    test_folder=\"./tests/grug_tests\",\n    fully_disable=os.environ.get(\"PROD\")!=None,\n    replay_inputs=os.environ.get(\"RUN_TEST_CASES\")!=None,\n    record_io=os.environ.get(\"RECORD\")!=None,\n)\n\n# 2. slap @grug_test on any of your pure-functions\n@grug_test(max_io=100)\ndef repeat(a,times):\n    for _ in range(times):\n        a += f\"{a}\"\n    return a\n\n```\n\n3. That's all the setup!\n- `RECORD=True         python ./main.py` will record tests for you\n- `RUN_TEST_CASES=True python ./main.py` will check your functions\n- `PROD=True           python ./main.py` will run with grug totally disabled\n- Make sure to commit the generated tests to git\n    - When you do `RUN_TEST_CASES=True`, the git-diff will show you any problems\n    - If you like the changes, well \u2728volia\u2728 the git changes are your freshly-written test cases\n    - If you don't like the changes, well then it looks like you've got some dev work to do\n    - thats it\n\n# Q&A\n\nDoes this work with `@staticmethod`?\n\n- Yes but you have to put the decorator it on the line BELOW the `@staticmethod`\n\nDoes this work with ANY pure function?\n\n- 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) do `from grug_test import yaml` and make your class be yaml-seralizable (tutorial/example [here](https://github.com/jeff-hykin/ez_yaml/blob/8b4dce8bf495484feb50f84468ffc6f776c357d4/README.md#custom-yaml-tags-example))\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tests for lazy (smart) devs",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/jeff-hykin/grug_test_py"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6698a36a0dacc869ff7931b3a9f3371864f4e795dd1405742e1edab144169a37",
                "md5": "3e1f498029a6c1e08419e634a7da8f20",
                "sha256": "cdca7862bb9f3b0ed42c01d66fb8811afe032468798fc9a9c7b9cdaf3c7c191d"
            },
            "downloads": -1,
            "filename": "grug_test-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e1f498029a6c1e08419e634a7da8f20",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 647354,
            "upload_time": "2023-09-07T16:42:09",
            "upload_time_iso_8601": "2023-09-07T16:42:09.974538Z",
            "url": "https://files.pythonhosted.org/packages/66/98/a36a0dacc869ff7931b3a9f3371864f4e795dd1405742e1edab144169a37/grug_test-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a92e1f035fbc2041509c4aca0b6d308eb9d06213efcdac715362db67cec69b7",
                "md5": "068360e7b59285142ba5a27a148d7d2c",
                "sha256": "57fa1620799773b9c774fd870a8fd2c79f4a3091ffc0b7b274e728364b69a9e5"
            },
            "downloads": -1,
            "filename": "grug_test-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "068360e7b59285142ba5a27a148d7d2c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6613218,
            "upload_time": "2023-09-07T16:42:12",
            "upload_time_iso_8601": "2023-09-07T16:42:12.797275Z",
            "url": "https://files.pythonhosted.org/packages/5a/92/e1f035fbc2041509c4aca0b6d308eb9d06213efcdac715362db67cec69b7/grug_test-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-07 16:42:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jeff-hykin",
    "github_project": "grug_test_py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "grug-test"
}
        
Elapsed time: 0.24390s