From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitrii Korobeinikov Subject: Re: [Proposal] Source Blocks with Post-Extensions Date: Wed, 3 Jul 2019 22:02:31 +0600 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000cdc230058cc8fd64" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:55997) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hihik-0000KU-KK for emacs-orgmode@gnu.org; Wed, 03 Jul 2019 12:03:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hihii-0004SD-6l for emacs-orgmode@gnu.org; Wed, 03 Jul 2019 12:02:58 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:34544) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hihic-0004Lp-Cy for emacs-orgmode@gnu.org; Wed, 03 Jul 2019 12:02:51 -0400 Received: by mail-wm1-x334.google.com with SMTP id w9so3256721wmd.1 for ; Wed, 03 Jul 2019 09:02:44 -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: Martin Alsinet Cc: emacs-orgmode , "Berry, Charles" --000000000000cdc230058cc8fd64 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Dear Martin, Your approach to test cases is quite valuable for more structured projects and for automation. For something that's either quick&dirty or w/out much architectural certainty to it, I would still prefer the handy one-liners. Nonetheless, thanks for the example! Best, Dmitrii. =D1=87=D1=82, 27 =D0=B8=D1=8E=D0=BD. 2019 =D0=B3. =D0=B2 04:09, Martin Alsi= net : > 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 file= s. > > > * 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 ca= n >> solve the issue from the user side. Hopefully they will get some tractio= n. >> >> =D0=BF=D0=BD, 22 =D0=B0=D0=BF=D1=80. 2019 =D0=B3. =D0=B2 23:31, Berry, C= harles : >> >>> >>> >>> > 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 t= he >>> function with as many lines of code as you need. >>> >>> Chuck >>> >>> >>> >>> --000000000000cdc230058cc8fd64 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Dear Martin,

Your approach to test case= s is quite valuable for more structured projects and for automation. For so= mething that's either quick&dirty or w/out much architectural certa= inty to it, I would still prefer the handy one-liners. Nonetheless, thanks = for the example!

Best,
Dmitrii.

=D1= =87=D1=82, 27 =D0=B8=D1=8E=D0=BD. 2019 =D0=B3. =D0=B2 04:09, Martin Alsinet= <martin@alsinet.com.ar>= :
Dmit= rii,

I use a different approach, where I tangle the sour= ce into files in modules and then I import those modules from other blocks.=
This allows me to organize my document with different sections f= or the code and its tests, which then get exported into their corresponding= files.


* Square Function

This function receives a n= umber and returns its square

#+BEGIN_SRC python :tangle ./utils/math.= py :mkdirp yes
def square(x):
=C2=A0 =C2=A0 return x * x
<= font face=3D"courier new, monospace" color=3D"#000000">#+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 shou= ld be 0
3. The square of a negative number should be positive

=
#+BEGIN_S= RC python :tangle ./utils/test_square.py :mkdirp yes
<= font face=3D"courier new, monospace" color=3D"#000000">from utils.math impo= rt square

def test_square_of_five():<= /span>
=C2=A0 =C2=A0 assert square(5) =3D=3D 25=

def te= st_square_of_zero():
=C2=A0 =C2=A0 asser= t square(0) =3D=3D 0

<= /div>
def test_square_of_negative():
=C2=A0 =C2=A0 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 sessio= n 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 ... = =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 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 = <dim1212k@gmail.= com> wrote:
Sorry for not answering these two days.
<= div>
You are right, that's an option.
But I jus= t 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.
Espec= ially that the improvement might not seem that big.
So, I underst= and that.

I have proposed buffer lenses today and = they seem like something that can solve the issue from the user side. Hopef= ully 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



--000000000000cdc230058cc8fd64--