diff --git a/doc/source/examples.rst b/doc/source/examples.rst index b918c5dc40..d7e749b557 100644 --- a/doc/source/examples.rst +++ b/doc/source/examples.rst @@ -54,10 +54,6 @@ Asynchronous server ^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../../examples/server_async.py -Build bcd Payload -^^^^^^^^^^^^^^^^^ -.. literalinclude:: ../../examples/build_bcd_payload.py - Callback Server example ^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../../examples/server_callback.py diff --git a/examples/message_parser.py b/examples/message_parser.py index 23a43ab91f..574c16efd6 100755 --- a/examples/message_parser.py +++ b/examples/message_parser.py @@ -82,13 +82,13 @@ def decode(self, message): print("-" * 80) try: decoder.addToFrame(message) - if decoder.checkFrame(): + if decoder.checkFrame(): # pragma no cover slave = decoder._header.get( # pylint: disable=protected-access "uid", 0x00 ) decoder.advanceFrame() decoder.processIncomingPacket(message, self.report, slave) - else: + else: # pragma no cover self.check_errors(decoder, message) except Exception: # pylint: disable=broad-except self.check_errors(decoder, message) @@ -98,7 +98,7 @@ def check_errors(self, decoder, message): txt = f"Unable to parse message - {message} with {decoder}" _logger.error(txt) - def report(self, message): + def report(self, message): # pragma no cover """Print the message information""" print( "%-15s = %s" # pylint: disable=consider-using-f-string @@ -146,7 +146,7 @@ def parse_messages(cmdline=None): """Do a helper method to generate the messages to parse""" args = get_commandline(cmdline=cmdline) _logger.setLevel(args.log.upper()) - if not args.message: + if not args.message: # pragma no cover _logger.error("Missing --message.") return @@ -162,5 +162,10 @@ def parse_messages(cmdline=None): decoder.decode(raw_message) +def main(cmdline=None): + """Run program""" + parse_messages(cmdline=cmdline) + + if __name__ == "__main__": - parse_messages() # pragma: no cover + main() # pragma: no cover diff --git a/examples/simulator.py b/examples/simulator.py index 820eaa4156..34d67bad2b 100755 --- a/examples/simulator.py +++ b/examples/simulator.py @@ -89,4 +89,4 @@ async def run_simulator(): if __name__ == "__main__": - asyncio.run(run_simulator(), debug=True) + asyncio.run(run_simulator(), debug=True) # pragma no cover diff --git a/test/sub_examples/test_examples.py b/test/sub_examples/test_examples.py index 4f217d2f18..8ca709e20e 100755 --- a/test/sub_examples/test_examples.py +++ b/test/sub_examples/test_examples.py @@ -19,7 +19,7 @@ from examples.client_payload import main as main_payload_calls from examples.datastore_simulator import main as main_datastore_simulator from examples.message_generator import generate_messages -from examples.message_parser import parse_messages +from examples.message_parser import main as main_parse_messages from examples.server_async import run_async_server, setup_server from examples.server_callback import run_callback_server from examples.server_payload import setup_payload_server @@ -57,8 +57,8 @@ def test_message_generator(self, framer): def test_message_parser(self): """Test message parser.""" - parse_messages(["--framer", "socket", "-m", "000100000006010100200001"]) - parse_messages(["--framer", "socket", "-m", "00010000000401010101"]) + main_parse_messages(["--framer", "socket", "-m", "000100000006010100200001"]) + main_parse_messages(["--framer", "socket", "-m", "00010000000401010101"]) @pytest.mark.parametrize( ("use_comm", "use_framer", "use_port"),