|Subject:||Re: [O] [Proposal] Source Blocks with Post-Extensions|
|Date:||Wed, 3 Jul 2019 22:02:31 +0600|
Dmitrii,I use a different approach, where I tangle the source into files in modules and then I import those modules from other blocks.This allows me to organize my document with different sections for the code and its tests, which then get exported into their corresponding files.* Square FunctionThis function receives a number and returns its square#+BEGIN_SRC python :tangle ./utils/math.py :mkdirp yesdef square(x):return x * x#+END_SRC** __init__.py (module setup)#+begin_src python :tangle ./utils/__init__.py :mkdirp yesfrom utils.math import square#+end_src** Test cases1. The square of five should be 252. The square of zero should be 03. The square of a negative number should be positive#+BEGIN_SRC python :tangle ./utils/test_square.py :mkdirp yesfrom utils.math import squaredef test_square_of_five():assert square(5) == 25def test_square_of_zero():assert square(0) == 0def test_square_of_negative():assert square(-5) > 0#+END_SRC*** Run tests#+begin_src sh :results output rawpytest ./utils#+end_src#+RESULTS:============================= test session starts ==============================platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0rootdir: /appcollected 3 itemsutils/test_square.py ... [100%]=========================== 3 passed in 0.08 seconds ===========================On Wed, Apr 24, 2019 at 2:19 PM Dmitrii Korobeinikov <address@hidden> wrote:Sorry for not answering these two days.You are right, that's an option.But I just don't think that's the best possible one - for usability.Introducing this would imply architectural decisions, so it might not be immediately clear if it's right or not.Especially that the improvement might not seem that big.So, I understand that.I have proposed buffer lenses today and they seem like something that can solve the issue from the user side. Hopefully they will get some traction.пн, 22 апр. 2019 г. в 23:31, Berry, Charles <address@hidden>:
> On Apr 22, 2019, at 10:15 AM, Dmitrii Korobeinikov <address@hidden> wrote:
> Thank you!
> That's a handy technique and it does help.
> As I understand, there's no way to extend that to multiple lines?
AFAICS, no there is no way to split the :epilogue arg to multiple lines.
Of course, you can always follow a src block that provides a function with another src block that imports the code via noweb and then tests the function with as many lines of code as you need.
|[Prev in Thread]||Current Thread||[Next in Thread]|