From: Robert Yang <liezhi.yang@windriver.com>
To: Christopher Larson <kergoth@gmail.com>
Cc: bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH v4 2/2] bitbake: tests/event: Add test_lineno_in_eventhandler
Date: Wed, 10 Jan 2024 17:45:47 +0800 [thread overview]
Message-ID: <2cdccfda-6306-4ab2-9ade-ef9fac787233@windriver.com> (raw)
In-Reply-To: <53989CDF-1F8C-4FD7-B2D7-45FD5629903A@gmail.com>
Hi Christop,
On 1/10/24 6:08 AM, Christop her Larson wrote:
> This does look like a good idea, though I wonder if injecting newlines is truly
> the best approach. SyntaxError is a bit of a special case, since it occurs
Injecting newlines are much simple, and it also can catch more errors such as
IndentationError, now the IndentationError can be reported correctly:
ERROR: Unable to register event handler 'defaultbase_eventhandler':
File "/path/to/poky/meta/classes-global/base.bbclass", line 259
d.setVar("ORIGNATIVELSBSTRING", d.getVar("NATIVELSBSTRING", False))
^
IndentationError: unindent does not match any outer indentation level
Such errors were very hard to debug. The _syntaxerror_offset may work, but it is
much more complicated than inject newlines.
// Robert
> before we have the ast to adjust the lineno, but it can be corrected without
> string manipulation if you catch and re-raise SyntaxError. Ex:
>
> def _syntaxerror_offset(value, lineoffset):
> """Adjust the line number in a SyntaxError exception"""
> if lineoffset:
> msg, (efname, elineno, eoffset, badline) = value.args
> value.args = (msg, (efname, elineno + lineoffset, eoffset, badline))
> value.lineno = elineno + lineoffset
>
> —
> Christopher Larson
> chris_larson@mentor.com, chris.larson@siemens.com, kergoth@gmail.com
> Principal Software Engineer, Embedded Linux Solutions, Siemens Digital
> Industries Software
>
>> On Jan 9, 2024, at 12:45 AM, Robert Yang via lists.openembedded.org
>> <https://urldefense.com/v3/__http://lists.openembedded.org__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNEMRXmNnO$> <liezhi.yang=windriver.com@lists.openembedded.org> wrote:
>>
>> From: Robert Yang <liezhi.yang@windriver.com>
>>
>> Add test_lineno_in_eventhandler to test lineno in eventhandler.
>>
>> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
>> ---
>> bitbake/lib/bb/tests/event.py
>> <https://urldefense.com/v3/__http://event.py__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENKyLym7$> | 24 ++++++++++++++++++++++++
>> 1 file changed, 24 insertions(+)
>>
>> diff --git a/bitbake/lib/bb/tests/event.py
>> <https://urldefense.com/v3/__http://event.py__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENKyLym7$> b/bitbake/lib/bb/tests/event.py <https://urldefense.com/v3/__http://event.py__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENKyLym7$>
>> index d959f2d95db..ef61891d302 100644
>> --- a/bitbake/lib/bb/tests/event.py
>> <https://urldefense.com/v3/__http://event.py__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENKyLym7$>
>> +++ b/bitbake/lib/bb/tests/event.py
>> <https://urldefense.com/v3/__http://event.py__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENKyLym7$>
>> @@ -13,6 +13,7 @@ import pickle
>> import threading
>> import time
>> import unittest
>> +import tempfile
>> from unittest.mock import Mock
>> from unittest.mock import call
>>
>> @@ -468,6 +469,8 @@ class EventClassesTest(unittest.TestCase):
>>
>> def setUp(self):
>> bb.event.worker_pid = EventClassesTest._worker_pid
>> + self.d = bb.data.init()
>> + bb.parse.siggen = bb.siggen.init(self.d)
>>
>> def test_Event(self):
>> """ Test the Event base class """
>> @@ -950,3 +953,24 @@ class EventClassesTest(unittest.TestCase):
>> event = bb.event.FindSigInfoResult(result)
>> self.assertEqual(event.result, result)
>> self.assertEqual(event.pid
>> <https://urldefense.com/v3/__http://event.pid__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNENhxad__$>, EventClassesTest._worker_pid)
>> +
>> + def test_lineno_in_eventhandler(self):
>> + # The error lineno is 5, not 4 since the first line is '\n'
>> + error_line = """
>> +# Comment line1
>> +# Comment line2
>> +python test_lineno_in_eventhandler() {
>> + This is an error line
>> +}
>> +addhandler test_lineno_in_eventhandler
>> +test_lineno_in_eventhandler[eventmask] = "bb.event.ConfigParsed"
>> +"""
>> +
>> + with self.assertLogs() as logs:
>> + f = tempfile.NamedTemporaryFile(suffix = '.bb')
>> + f.write(bytes(error_line, "utf-8"))
>> + f.flush()
>> + d = bb.parse.handle(f.name
>> <https://urldefense.com/v3/__http://f.name__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNEDC-ZnzD$>, self.d)['']
>> +
>> + output = "".join(logs.output)
>> + self.assertTrue(" line 5\n" in output)
>> --
>> 2.35.5
>>
>>
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#15756):
>> https://lists.openembedded.org/g/bitbake-devel/message/15756
>> <https://urldefense.com/v3/__https://lists.openembedded.org/g/bitbake-devel/message/15756__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNEHCVD821$>
>> Mute This Topic: https://lists.openembedded.org/mt/103616263/3617123
>> <https://urldefense.com/v3/__https://lists.openembedded.org/mt/103616263/3617123__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNEIbsb3Sa$>
>> Group Owner: bitbake-devel+owner@lists.openembedded.org
>> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub
>> <https://urldefense.com/v3/__https://lists.openembedded.org/g/bitbake-devel/unsub__;!!AjveYdw8EvQ!YGDlH3GcpHwxON5oeaacPDSvoRd4ElezyHIHZpb7-vl5gV_Ip6p6zmPaMM2MO9LWGJTKQza6t0DNEG8cswfl$> [kergoth@gmail.com]
>> -=-=-=-=-=-=-=-=-=-=-=-
>>
>
prev parent reply other threads:[~2024-01-10 9:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 7:45 [PATCH v4 0/2] event: Inject empty lines to make code match lineno in filename liezhi.yang
2024-01-09 7:45 ` [PATCH v4 1/2] bitbake: " liezhi.yang
2024-01-09 7:45 ` [PATCH v4 2/2] bitbake: tests/event: Add test_lineno_in_eventhandler liezhi.yang
2024-01-09 22:08 ` [bitbake-devel] " Christopher Larson
2024-01-10 9:45 ` Robert Yang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2cdccfda-6306-4ab2-9ade-ef9fac787233@windriver.com \
--to=liezhi.yang@windriver.com \
--cc=bitbake-devel@lists.openembedded.org \
--cc=kergoth@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.