-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configuration and auxiliaries can be started and used in any py…
…thon script
- Loading branch information
1 parent
e344dfd
commit d2dbd9a
Showing
15 changed files
with
261 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ updates: | |
interval: "monthly" | ||
reviewers: | ||
- "sebastianpfischer" | ||
- "BKaDamien" | ||
- "Pog3k" | ||
- "sebclrsn" | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.. _pykiso_as_simulator: | ||
|
||
** NEW ** Pykiso as a simulator | ||
------------------------------- | ||
|
||
Introduction | ||
~~~~~~~~~~~~ | ||
|
||
Pykiso consists of two main components: | ||
|
||
* The testing framework | ||
* The test environment creation and management | ||
|
||
Together, these components enable embedded software engineers to efficiently test their software in a familiar manner. | ||
Pykiso's testing framework adopts an approach similar to popular embedded testing frameworks, | ||
such as Google Test, making it intuitive for engineers with experience in embedded systems. | ||
|
||
Over the years, we have identified two main groups of Pykiso users: | ||
|
||
* Those who embrace our opinionated approach to testing embedded software. | ||
* Those who appreciate the core principles and resources but prefer a different approach to testing. | ||
|
||
By decoupling the testing framework from the test environment creation, | ||
Pykiso now caters to both groups, offering flexibility while retaining the benefits of its robust structure. | ||
|
||
|
||
|
||
Workflow Overview | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
**Create a test environment** | ||
Begin by defining your test environment in a configuration file. (Refer to :ref:`basic_config_file` for more details.) | ||
|
||
**Strip the test suites section** | ||
If needed, you can remove the `Test Suites` section from the configuration file to simplify the setup. | ||
|
||
**Write your (test) script** | ||
Create a Python script, import the Pykiso library, import the test environment and use the auxiliaries to interact with the system under test. | ||
|
||
|
||
This workflow allows users to leverage Pykiso's testing capabilities while maintaining flexibility in how they define and manage their test environments. | ||
|
||
|
||
|
||
Example | ||
~~~~~~~ | ||
|
||
Definition of the test environment: | ||
|
||
.. literalinclude:: ../../examples/next_pykiso2/pykiso_as_simulator/serial.yaml | ||
:language: yaml | ||
|
||
Creation of the test script: | ||
|
||
.. literalinclude:: ../../examples/next_pykiso2/pykiso_as_simulator/serial_simulation.py | ||
:language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
.. include:: basic_config_file.rst | ||
|
||
.. include:: basic_tests.rst | ||
|
||
.. include:: pykiso_as_simulator.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
auxiliaries: | ||
com_aux_sender: | ||
connectors: | ||
com: loopback | ||
type: pykiso.lib.auxiliaries.communication_auxiliary:CommunicationAuxiliary | ||
com_aux_receiver: | ||
connectors: | ||
com: loopback | ||
type: pykiso.lib.auxiliaries.communication_auxiliary:CommunicationAuxiliary | ||
connectors: | ||
loopback: | ||
type: pykiso.lib.connectors.cc_raw_loopback:CCLoopback |
46 changes: 46 additions & 0 deletions
46
examples/next_pykiso2/pykiso_as_simulator/serial_simulation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pathlib import Path | ||
|
||
# Import pykiso | ||
import pykiso | ||
|
||
# Load the test environment configuration | ||
pykiso.load_config(Path(__file__).parent.resolve() / "serial.yaml") | ||
|
||
# From the pykiso library, import the type of auxiliary you defined in the configuration | ||
# Here, it would be the CommunicationAuxiliary class | ||
from pykiso.lib.auxiliaries.communication_auxiliary import CommunicationAuxiliary | ||
|
||
|
||
def first_test(): | ||
"""Ping-pong test between sender and receiver (with no context manager) | ||
""" | ||
# Get the instance of the sender and receiver defined in the configuration | ||
sender = CommunicationAuxiliary.get_instance('com_aux_sender') | ||
receiver = CommunicationAuxiliary.get_instance('com_aux_receiver') | ||
# Start the sender and receiver | ||
sender.start() | ||
receiver.start() | ||
# Use the auxiliaries for my test | ||
sender.send_message("Hello, World!") | ||
assert receiver.receive_message(timeout_in_s = 2) == "Hello, World!" | ||
print("Test passed!") | ||
# Stop the sender and receiver | ||
sender.stop() | ||
receiver.stop() | ||
|
||
def second_test(): | ||
"""Ping-pong test between sender and receiver (with context manager) | ||
""" | ||
# Get the instance of the sender and receiver defined in the configuration | ||
sender = CommunicationAuxiliary.get_instance('com_aux_sender') | ||
receiver = CommunicationAuxiliary.get_instance('com_aux_receiver') | ||
# Start the auxiliaries with a context manager | ||
with sender as sender, receiver as receiver: | ||
# Use the auxiliaries for my test | ||
sender.send_message("Hello, World!") | ||
assert receiver.receive_message(timeout_in_s = 2) == "Hello, World!" | ||
print("Second test passed!") | ||
|
||
if __name__ == "__main__": | ||
first_test() | ||
second_test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
auxiliaries: | ||
com_aux_sender: | ||
connectors: | ||
com: loopback | ||
type: pykiso.lib.auxiliaries.communication_auxiliary:CommunicationAuxiliary | ||
com_aux_receiver: | ||
connectors: | ||
com: loopback | ||
type: pykiso.lib.auxiliaries.communication_auxiliary:CommunicationAuxiliary | ||
connectors: | ||
loopback: | ||
type: pykiso.lib.connectors.cc_raw_loopback:CCLoopback |
Oops, something went wrong.