Skip to content

Commit

Permalink
. td improved inline parsing documentation
Browse files Browse the repository at this point in the history
Co-Authored-By: Kody Fintak <[email protected]>
Co-Authored-By: 4dsherwood <[email protected]>
Co-Authored-By: Nazee Hajebi <[email protected]>
Co-Authored-By: T. E. Green <[email protected]>
Co-Authored-By: blade290 <[email protected]>
  • Loading branch information
6 people committed Apr 7, 2024
1 parent cdaf75a commit 6e2e815
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/how_to/inline_approvals_with_parse_input.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# How to have tight feedback loops with inline approvals and parse_input

toc

## Problem
You are doing TDD on a pure function that takes some parameters and returns a result.
You want to just program and see the results of running it with as little in the way of that as possible.

## Solution
Use a combination of:
1. Inline Approvals
2. Parse Input
3. Auto-Approver

This allows you to easily give inputs and see the output.
This will remove the repoter and diff tools and feel more like a REPL.

## Handling 1 Parameter

### Scenario - Counting Vowels
Expand Down Expand Up @@ -39,8 +50,14 @@ Kody -> 0
<sup><a href='/tests/test_parse_inputs.py#L49-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-parse_input_step_2' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Step 3: Implement the Function
### Step 3: Implement and rerun
Everytime you run the tests, you automatically see the result at the top in the docstring.
As you want more test cases just add more lines to the docstring.
Here's an exmaple of where we have handled O, E, & A.
snippet: parse_input_step_3

### Step 4: Commit

When you finally get the answer you want, remove the `auto_approve=True` and commit the code.


Expand Down
21 changes: 21 additions & 0 deletions tests/test_parse_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ def test_count_vowels():

# end-snippet
test_count_vowels()
def test_example_step_2():
"""
Kody -> 1
Teresa -> 3
Green -> 2
"""
# begin-snippet: parse_input_step_3
def count_vowels(s: str) -> int:
return sum(1 for c in s if c in "aeo")

def test_count_vowels():
"""
Kody -> 1
Teresa -> 3
Green -> 2
"""
parse = Parse.doc_string(auto_approve=True)
parse.verify_all(count_vowels)

# end-snippet
test_count_vowels()


# begin-snippet: parse_input_transformation
Expand Down

0 comments on commit 6e2e815

Please sign in to comment.