Dear Leo Developer,
I am writing a script in Leo, it is located in the body of a @button node.
As adding more and more logic to the script, I feel I need to have some test case to make me confident on the development progress.
As the moment, I am adding test case as below:
def func1():
...
def func2():
...
def main():
.....
def test_scenario1():
func1()
func2()
def test_scenario2():
func2()
func1()
def test_main():
#test_scenario1()
test_scenario2()
c.redraw()
test_main()
#main()
I created a test_main() and put the test logic there. Using ctrl-b to see the result of test_main().
It's not a good way:
1) The test cases and production code are mixed
2) Need manually disable/enable for different test scenarios.
I'm thinking to use python unittest library, but the way I use unittest before was in command line, create a dedicated "test_button_body_code.py" and "import button_body_code" to test button_body_code.py.
How shall I do the similar thing for leo @button script?
Or any other best practice for testing the script in the body of @button?
Best Regards,
Austin
I am writing a script in Leo, it is located in the body of a @button node.
As adding more and more logic to the script, I feel I need to have some test case to make me confident on the development progress.
I created a test_main() and put the test logic there. Using ctrl-b to see the result of test_main().
It's not a good way:
1) The test cases and production code are mixed
2) Need manually disable/enable for different test scenarios.
I'm thinking to use python unittest library, but the way I use unittest before was in command line, create a dedicated "test_button_body_code.py" and "import button_body_code" to test button_body_code.py.
How shall I do the similar thing for leo @button script?
Or any other best practice for testing the script in the body of @button?
<< imports >>
class Controller:
@others
Controller(c).run()<< imports >>
@others # define all classes
Controller(c).run()<< imports >>
from x import Controller
Controller(c).run()g.cls()
import os
leo_editor_dir = os.path.join(g.app.loadDir, '..', '..')
os.chdir(leo_editor_dir) # must be done here.
file_ = 'leo.core.leoAst'
if 1: # Run all tests
commands = f"&python -m unittest {file_}"
g.execute_shell_commands(commands, trace=False)
else:
file_ = 'leo.core.leoAst'
class_, test = '.TestOrange', '.test_blank_lines_after_function'
commands = f"&python -m unittest {file_}{class_}{test}"
g.execute_shell_commands(commands, trace=False)if __name__ == '__main__':
unittest.main()pytest --cov-report html --cov-report term-missing --cov leo.core.leoAst leo/core/leoAst.pyin the console, as expected.----------------------------------------------------------------------Ran 1 test in 0.008sOK
text = p.hassert(text == "@test 2nd test")
..----------------------------------------------------------------------Ran 2 tests in 0.017sOK

--
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 leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/60f6e1c5-1023-4ae2-89e0-9c309baeea8d%40googlegroups.com.
Thanks Edward for the advice. I will try it later. For now, I'm starting from the basic one documented in unittest.leo
--
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 leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAMF8tS1ofKwjoE%2B%2BL6B__nk3j%2BSPbKBvosyWBuTpi-Bh0E5C_g%40mail.gmail.com.
is the issue I raised in my previous email a Leo bug regarding accessing position in the testcase?
No, I would not call a bug. I simply meant that it's a lot easier to create outlines in unitTest.leo.Within a Test class, called by g.run_unit_test_in_separate_process, there will always be difficulties creating outlines, traversing them, etc. These difficulties can be overcome, it just takes more work.
Edward
Start of Do @test..----------------------------------------------------------------------Ran 2 tests in 0.013sOKEnd of Do @test
--
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 leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAMF8tS3vWN2_BuP8KSau0pnFnTMyu%3D%3DaH4vTmOBOoS12QOidsg%40mail.gmail.com.
Strange...please find attached a mini outline file to reproduce.Click node "simple test cases collection" and then "Do-@test" button.Below is the output on my console.
Everything seems fine to me. Both tests pass, as I think they should.Within an @test node, p is the position of the @test node itself.What do you think the problem is?
text = p.hassert(text == "@test 2nd test")
Strange...please find attached a mini outline file to reproduce.Click node "simple test cases collection" and then "Do-@test" button.Below is the output on my console.Start of Do @test..----------------------------------------------------------------------Ran 2 tests in 0.013sOKEnd of Do @test
Edward K. Ream <edre...@gmail.com> 于2020年3月1日周日 下午6:56写道:
--On Sat, Feb 29, 2020 at 12:32 PM Xu Wang <xu4...@gmail.com> wrote:> I tried to use run-all-unit-tests-locally command to execute the two test cases, still got same result. The position read by the test case code is not the real current position.Are you sure? I've never had this kind of trouble.Please show the code that appears to have this problem.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 leo-e...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/1ad68899-ae32-4ad5-9a60-2a6ad72026e7%40googlegroups.com.
--
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 leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAMF8tS3GdSs6UD409MswrvpS5LHUsdF43DSaEwNM_ddiAvzt%3DQ%40mail.gmail.com.