>
> Any node, but @test or @button nodes are easiest to use.
>
> Is that defined somewhere?
>>
>
> Yes, in the next sentence.
>

The sentence can be parsed in two ways:

"This node (in the Leo outline) defines your development environment. You
can use an @test node, an @button node, or an @command node"

I read it as "There is something called a dev node" and "You can make a dev
node a @test, @button or @command node". It sounded like a dev node is a
node with a special property  (e.g. a cloned node is visually different
from a regular node), and then you can make THAT dev node a @test node. I
think a better phrasing would be:

"A dev node is defined as any node that is either a @test, @button or
@command node."

For the examples you gave (and your other comments in the group), it seems
like I cannot put the unit test in its own node (even as a sibling)?

On Fri, Oct 12, 2018 at 2:11 AM Edward K. Ream <[email protected]> wrote:

> On Thursday, October 11, 2018 at 4:17:07 PM UTC-5, MN wrote:
>
> > What is a dev node?
>
> Any node, but @test or @button nodes are easiest to use.​
>
> Is that defined somewhere?
>>
>
> Yes, in the next sentence.
>
> Suppose I have a node whose contents are:
>>
>> from operator import mul
>>
>> def factorial(number):
>>     if number < 0:
>>         raise ValueError
>>     if number == 0:
>>         return 1
>>     return reduce(mul, range(number+1), 1)
>>
>> It's a simple function. Imagine this is a helper function that will be
>> used by some other function that interacts with Leo. It is not saved to any
>> file (beyond the .leo file, of course). I would like to create a unit test
>> for this. What is the best way?
>>
>
> There are several ways.
>
>
> *1. Use Python doctests <https://docs.python.org/2/library/doctest.html>*
>
> Here is a tested code: Create a node, @test factorial, whose body is:
>
> import doctest
> from operator import mul
>
> def factorial(number):
>     """
>     >>> factorial(5)
>     120
>     """
>     if number < 0:
>         raise ValueError
>     if number == 0:
>         return 1
>     return reduce(mul, range(number+1), 1)
>
> doctest.run_docstring_examples(factorial, globals(), name='factorial')
>
> Execute the code with with Ctrl-B, or with one of the
> run-*-unit-tests-locally commands.
>
> This will fail, for different reasons, on both Python 2 and 3.
>
> *2. Define unit tests using UnitTest.TestCase*
>
> Alternatively, you can define explicit tests.  Here is tested code.
>
> import unittest
> from operator import mul
>
> def factorial(number):
>     if number < 0:
>         raise ValueError
>     if number == 0:
>         return 1
>     return reduce(mul, range(number+1), 1)
>
> class TestFactorial(unittest.TestCase):
>
>     def test1(self):
>         self.assertTrue(factorial(5)==120)
>
> suite = unittest.TestLoader().loadTestsFromTestCase(TestFactorial)
> unittest.TextTestRunner(verbosity=1).run(suite)
>
> Again, you can run this with Ctrl-B, or with one of Leo's unit test
> commands.
>
> Edward
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to