From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Alsinet Subject: Re: [Proposal] Source Blocks with Post-Extensions Date: Wed, 26 Jun 2019 17:09:15 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006bd5a2058c414cc4" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:37316) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgG6c-00088B-Cz for emacs-orgmode@gnu.org; Wed, 26 Jun 2019 18:09:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgG6a-0000VP-7B for emacs-orgmode@gnu.org; Wed, 26 Jun 2019 18:09:29 -0400 Received: from mail-oi1-f170.google.com ([209.85.167.170]:36226) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hgG6Z-0000Ui-Vu for emacs-orgmode@gnu.org; Wed, 26 Jun 2019 18:09:28 -0400 Received: by mail-oi1-f170.google.com with SMTP id w7so34727oic.3 for ; Wed, 26 Jun 2019 15:09:27 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Dmitrii Korobeinikov Cc: emacs-orgmode , "Berry, Charles" --0000000000006bd5a2058c414cc4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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) =3D=3D 25 def test_square_of_zero(): assert square(0) =3D=3D 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: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D test session starts =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D 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%] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D 3 passed in 0.08 seconds =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D On Wed, Apr 24, 2019 at 2:19 PM Dmitrii Korobeinikov 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= . > > =D0=BF=D0=BD, 22 =D0=B0=D0=BF=D1=80. 2019 =D0=B3. =D0=B2 23:31, Berry, Ch= arles : > >> >> >> > On Apr 22, 2019, at 10:15 AM, Dmitrii Korobeinikov >> 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 th= e >> function with as many lines of code as you need. >> >> Chuck >> >> >> >> --0000000000006bd5a2058c414cc4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dmitrii,

I use a different approach, where I t= angle the source into files in modules and then I import those modules from= other blocks.
This allows me to organize my document with differ= ent 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):
=C2=A0 =C2=A0 return x * x
#+EN= D_SRC

** __init__.py (module setup)

#+begin_src python :tangle ./= utils/__init__.py :mkdirp yes
from utils.math import square
<= div>
#+end_src

** Test cases

1. The square of five should be 25=
2. The s= quare of zero should be 0
3. The square of a negative number should be positi= ve

#+BEGIN_SRC python :tangle ./utils/test_square.py :mkdirp yes
<= /font>
fr= om utils.math import square

def test_square_= of_five():
=C2=A0 =C2=A0 assert square(5= ) =3D=3D 25

def test_square_of_zero():
= =C2=A0 =C2=A0 assert square(0) =3D=3D 0
=
def test_square_of_negative():
=C2=A0 =C2=A0 assert square(-5) > 0
#+END_SRC
<= span style=3D"font-family:"courier new",monospace">
*** Run tests

#+begin_src sh :results output raw
pytest ./utils
#+end_src
=
#+RESULTS:
=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D test session starts =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
platform linux -- Python 3.7.3, py= test-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /app
collected 3 items

utils/test= _square.py ... =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 [100%]

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 3 passed in 0.08 second= s =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D



=



<= div dir=3D"ltr" class=3D"gmail_attr">On Wed, Apr 24, 2019 at 2:19 PM Dmitri= i 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 im= mediately clear if it's right or not.
Especially that the imp= rovement might not seem that big.
So, I understand that.

I have proposed buffer lenses today and they seem like som= ething that can solve the issue from the user side. Hopefully they will get= some traction.

=D0=BF=D0=BD, 22 =D0=B0=D0=BF=D1=80. 2019 =D0=B3. =D0= =B2 23:31, Berry, Charles <ccberry@ucsd.edu>:


> On Apr 22, 2019, at 10:15 AM, Dmitrii Korobeinikov <dim1212k@gmail.com> wrote:<= br> >
> Thank you!
> That's a handy technique and it does help.
> As I understand, there's no way to extend that to multiple lines?<= br>
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 functi= on with as many lines of code as you need.

Chuck



--0000000000006bd5a2058c414cc4--