forked from DAGWorks-Inc/burr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The idea is that someone is in the tracker and wants to fix/create a test around some part of the application. They can then use the command line to bootstrap it. We could do this in the UI too eventually. We assume they want to then have a JSON file with input state and expected output state to validate against. I think this is a nice way to do it. Then it's all checked in and they can run it in CI easily... This command assumes a local tracker for now. In the future we can add a yaml/config file that can instantiate a persister to load data instead. Otherwise we assume pytest, we could create a unittest stub too, and also that users will like the file drive approach.
- Loading branch information
1 parent
6f2df6d
commit 97a3ea5
Showing
12 changed files
with
263 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
==================== | ||
Creating Test Cases | ||
==================== | ||
|
||
With Burr tracking state is part of the framework. This means creating a realistic test case | ||
for an action involves turning a persister or tracker on and then pulling that state out | ||
for a test case. The following example demonstrates how to create a test case | ||
using the `burr-test-case` command. | ||
|
||
|
||
Test Case Creation Example | ||
-------------------------- | ||
|
||
See `github repository example <https://github.com/DAGWorks-Inc/burr/tree/main/examples/test-case-creation>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Usage: burr-test-case create [OPTIONS]\n", | ||
"\n", | ||
" Create a test case from a persisted state.\n", | ||
"\n", | ||
" Prints a pytest test case to the console assuming you have a\n", | ||
" `pytest_generate_tests` function set up.\n", | ||
"\n", | ||
" See examples/test-case-creation/test_application.py for details.\n", | ||
"\n", | ||
"Options:\n", | ||
" --project-name TEXT Name of the project [required]\n", | ||
" --partition-key TEXT Partition key to look at [required]\n", | ||
" --app-id TEXT App ID to pull from. [required]\n", | ||
" --sequence-id TEXT Sequence ID to pull. [required]\n", | ||
" --target-file-name TEXT What file to write the data to. Else print to\n", | ||
" console.\n", | ||
" --help Show this message and exit.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%sh \n", | ||
"burr-test-case create --help\n" | ||
], | ||
"metadata": { | ||
"collapsed": false, | ||
"ExecuteTime": { | ||
"end_time": "2024-04-01T05:29:38.960440Z", | ||
"start_time": "2024-04-01T05:29:37.926490Z" | ||
} | ||
}, | ||
"id": "5cc77bd80999b2a2", | ||
"execution_count": 7 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# Create a test case\n", | ||
"\n", | ||
"Find the data you want to create a test case with in the UI." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"id": "944a988132d19779" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Found data for action: plan_cot\n", | ||
"\n", | ||
"Writing data to file /tmp/test-case.json\n", | ||
"\n", | ||
"Add the following to your test file assuming you've got `pytest_generate_tests` set up:\n", | ||
"\n", | ||
"import pytest\n", | ||
"# TODO: import the action you're testing\n", | ||
"@pytest.mark.file_name(\"/tmp/test-case.json\")\n", | ||
"def test_plan_cot(input_state, expected_state):\n", | ||
" \"\"\"Function for testing the action\"\"\"\n", | ||
" input_state = state.State(input_state)\n", | ||
" expected_state = state.State(expected_state)\n", | ||
" _, output_state = plan_cot(input_state) # exercise the action\n", | ||
" assert output_state == expected_state\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%sh\n", | ||
"burr-test-case create --project-name \"oa:determine_params\" --partition-key \"\" --app-id \"3350dd68-bcfd-48a1-85c5-dd72186382ef\" --sequence-id 0 --target-file-name /tmp/test-case.json\n" | ||
], | ||
"metadata": { | ||
"collapsed": false, | ||
"ExecuteTime": { | ||
"end_time": "2024-04-01T05:33:01.015032Z", | ||
"start_time": "2024-04-01T05:33:00.146352Z" | ||
} | ||
}, | ||
"id": "586bcb0bdb5dde8b", | ||
"execution_count": 11 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# What's next?\n", | ||
" \n", | ||
"## See `test_application.py` for code that enables you to run the test case like this.\n", | ||
"\n", | ||
"## Fill in the expected state part of the JSON\n", | ||
"The expected state part of the JSON is empty. You need to fill it in with the expected state of the application after the test case has been run. Once you've\n", | ||
"done that, you've got your test case!\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"id": "3ac9d600d0807fc8" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"outputs": [], | ||
"source": [], | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"id": "a727cdc01303cd39" | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters