From: Martin Alsinet <martin@alsinet.com.ar>
To: Dmitrii Korobeinikov <dim1212k@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>,
"Berry, Charles" <ccberry@ucsd.edu>
Subject: Re: [Proposal] Source Blocks with Post-Extensions
Date: Wed, 26 Jun 2019 17:09:15 -0500 [thread overview]
Message-ID: <CABUJmkCy3acXFkM5dbUJxfvp1eLmC82wDMR9qnDfBdSnkUfjtg@mail.gmail.com> (raw)
In-Reply-To: <CA+Yh0SQwm0dv_HppyoAB7oy=bpED+42z-TEyHT+4gNDnoKMKZQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2704 bytes --]
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 Function
This function receives a number and returns its square
#+BEGIN_SRC python :tangle ./utils/math.py :mkdirp yes
def square(x):
return x * x
#+END_SRC
** __init__.py (module setup)
#+begin_src python :tangle ./utils/__init__.py :mkdirp yes
from utils.math import square
#+end_src
** Test cases
1. The square of five should be 25
2. The square of zero should be 0
3. The square of a negative number should be positive
#+BEGIN_SRC python :tangle ./utils/test_square.py :mkdirp yes
from utils.math import square
def test_square_of_five():
assert square(5) == 25
def test_square_of_zero():
assert square(0) == 0
def test_square_of_negative():
assert square(-5) > 0
#+END_SRC
*** Run tests
#+begin_src sh :results output raw
pytest ./utils
#+end_src
#+RESULTS:
============================= test session starts
==============================
platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /app
collected 3 items
utils/test_square.py ...
[100%]
=========================== 3 passed in 0.08 seconds
===========================
On Wed, Apr 24, 2019 at 2:19 PM Dmitrii Korobeinikov <dim1212k@gmail.com>
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 <ccberry@ucsd.edu>:
>
>>
>>
>> > On Apr 22, 2019, at 10:15 AM, Dmitrii Korobeinikov <dim1212k@gmail.com>
>> 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.
>>
>> Chuck
>>
>>
>>
>>
[-- Attachment #2: Type: text/html, Size: 7912 bytes --]
next prev parent reply other threads:[~2019-06-26 22:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 9:00 [Proposal] Source Blocks with Post-Extensions Dmitrii Korobeinikov
2019-04-22 16:51 ` Berry, Charles
2019-04-22 17:15 ` Dmitrii Korobeinikov
2019-04-22 17:31 ` Berry, Charles
2019-04-24 19:05 ` Dmitrii Korobeinikov
2019-06-26 22:09 ` Martin Alsinet [this message]
2019-07-03 16:02 ` Dmitrii Korobeinikov
2019-07-26 12:02 ` Ken Mankoff
2019-07-26 12:58 ` Martin Alsinet
2019-07-26 15:18 ` Ken Mankoff
2019-07-26 15:52 ` Martin Alsinet
2019-04-22 20:59 ` Tim Cross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABUJmkCy3acXFkM5dbUJxfvp1eLmC82wDMR9qnDfBdSnkUfjtg@mail.gmail.com \
--to=martin@alsinet.com.ar \
--cc=ccberry@ucsd.edu \
--cc=dim1212k@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).