From 6e2e815291cf9976eae6ddc2b4d46bae2ca93e9f Mon Sep 17 00:00:00 2001 From: Llewellyn Falco Date: Sun, 7 Apr 2024 18:39:47 +0000 Subject: [PATCH] . td improved inline parsing documentation Co-Authored-By: Kody Fintak <15849743+kodyfintak@users.noreply.github.com> Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com> Co-Authored-By: Nazee Hajebi <2491283+NazeeHajebi@users.noreply.github.com> Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com> Co-Authored-By: blade290 <43077216+blade290@users.noreply.github.com> --- .../inline_approvals_with_parse_input.md | 19 ++++++++++++++++- tests/test_parse_inputs.py | 21 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/how_to/inline_approvals_with_parse_input.md b/docs/how_to/inline_approvals_with_parse_input.md index 0f91f99..5d9750b 100644 --- a/docs/how_to/inline_approvals_with_parse_input.md +++ b/docs/how_to/inline_approvals_with_parse_input.md @@ -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 @@ -39,8 +50,14 @@ Kody -> 0 snippet source | anchor -### 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. diff --git a/tests/test_parse_inputs.py b/tests/test_parse_inputs.py index d30db77..09306fd 100644 --- a/tests/test_parse_inputs.py +++ b/tests/test_parse_inputs.py @@ -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