I just imported a Python file using the current devel branch (so not 
Vitaije's new code).  The file has a if __name__ == '__main__': section.  
This section is located at the end of the imported file.  I have no problem 
with that location even though the older importer put it near the top.  But 
it is not in its own node, it's just at the end of the last def node. I 
would like it to be in its own node tree, which might have the top node 
headline of  *__main__* or similar.  Also, a *__main__* section can 
sometimes be longish, and if so it should be decomposed into nodes like any 
other part of the file.

On Monday, December 6, 2021 at 4:36:59 PM UTC-5 vitalije wrote:

> Sorry, I've missed your two posts.
>
> I've been working on new branch `importers` today.
>
> While looking at the importer pipeline, I've noticed several conversion 
> text to lines and backwards. First split is in checking tabs and spaces, if 
> there are mixed tabs and spaces, again text is turned into lines, and back 
> to text. Finally in gen_lines the same input text is once again divided in 
> lines. So, I've changed all methods to accept lines as input argument 
> instead of text. There were several places to change, in almost all 
> importers that override gen_lines, but changes were minimal.
>
> All unit tests passed except two related to leoAst that fail.
>
> After that I've marked all test methods in test_leoImport.TestPython for 
> skipping and I've started to add my own tests.
> The old tests were checking only on headlines. Using new utility method 
> for checking outline:
>
> def check_outline(self, p, nodes):
>     it = iter(nodes)
>     zlev = p.level()
>     for p1 in p.self_and_subtree():
>         lev, h, b = next(it)
>         assert p1.level()-zlev == lev, f'lev:{p1.level()-zlev} != {lev}'
>         if lev > 0:
>             assert p1.h == h, f'"{p1.h}" != "{h}"'
>         assert p1.b == b, f'\n{repr(p1.b)} !=\n{repr(b)}'
>     try:
>         next(it)
>         return False, 'extra nodes'
>     except StopIteration:
>         return True, 'ok'
>
> Now, both structure and content are checked.
> After I've added 6 new tests with some corner cases that I've found to be 
> interesting, I've deleted all other old tests in TestPython class.
>
> You can check the tests and suggest any new test case. If you just provide 
> Leo outline for interesting cases, I can easily turn them into test methods.
> From outline it is easy to get source text, and expected node structure. 
> All new tests have same form:
>
> def test_something(self):
>     txt = '''sourcecode'''
>     exp_nodes = [(lev, h, b),...]
>     p = self.run_test(txt)
>     ok, msg = self.check_outline(p, exp_nodes)
>     assert ok, msg
>
> Look at the branch `importers` and we can discus what I've accomplished so 
> far. I don't think there will be any serious problems in the future. 
> Function split_root, should have some more comments and perhaps better var 
> names, before PR is ready, but all remaining tweaks should be easy.
>
> Let me know what do you think about the results of new python importer.
> Vitalije
> On Monday, December 6, 2021 at 10:01:02 PM UTC+1 Edward K. Ream wrote:
>
>> On Monday, December 6, 2021 at 10:35:03 AM UTC-6 Edward K. Ream wrote:
>>
>> > I shall soon convert all tests so that they use check_headlines rather 
>> than the more verbose equivalent.
>>
>> Done in devel at rev c65459. In the tests I have marked headlines that 
>> should not be generated, or have poor headlines.  Vitalije, feel free to 
>> adjust the arguments so the call passes.
>>
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/d9e7f9c5-1dd3-496c-a66e-1723fca1e959n%40googlegroups.com.

Reply via email to