I don't have much understanding of Leo's tests myself. I think that your
case 1 would be handled by opening a NullGui. This will give you a working
g, from which you can access a lot of Leo's functionality. I'm not sure
how to deal with getting a commander with a null gui. But there must be
some test in Leo's source tree that could be a model.
For example, in leo/unittests/core, I see a file *test_leoColorizer.py*. It
has a class *TestColorizer(LeoUnitTest)*, which includes:
from leo.core import leoGlobals as g
from leo.core.leoTest2 import LeoUnitTest
from leo.core.leoQt import Qt
import leo.core.leoColorizer as leoColorizer
# ...
"""Test cases for leoColorizer.py"""
def color(self, language_name, text):
"""Run the test by colorizing a node with the given text."""
c = self.c
c.p.b = text.replace('> >', '>>').replace('< <', '<<')
c.recolor_now()
Looking in LeoPyRef for the base class *LeoUnitTest,* I find it in
*leoTest2.py*. When I run py -m pytest in Leo's top directory, it runs all
these many tests but does I never see a visible Leo window. So in those
unit test files are all the techniques to do what you want.
On Tuesday, December 26, 2023 at 10:09:35 PM UTC-5 [email protected] wrote:
> Take a look in the *leo-editor\leo\unittests* directory. For example,
>> *test_gui.py* imports g. etc. Maybe that will be enough to get started.
>>
> My intuitive thought is that there are two types of tests in Leo,
>>>
>>>
>>> 1. Testing of common Python function script nodes,
>>>
>>>
>>> 2. Tests that require a Leo context, such as g, c, p, etc.
>>>
>>> 2.1 Test with Leo already open, because there are already g, c, p
>>>
>>> 2.2 Testing without Leo open. It is no different from a normal
>>> python program. e.g. 'python -m unittest'
>>>
>>>
>>> Thanks, Thomas, I checked, but failed to understand, that is for 2.2
> scene, right?
>
> My main question is about 1, and 2.1 scenarios. How to perform specific
> operations in Leo, not how the code should be written
>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/5d08771e-ff5f-4ba6-833d-0a4d5f04eb54n%40googlegroups.com.