Skip to content

Commit 097ee40

Browse files
authored
Merge pull request #39 from MASTERS-Y2Q1-ISEP/cicd/autopep8-JFoedererPR
Add CI/CD checks and CONTRIBUTING.md
2 parents 84e9f5f + 5f67137 commit 097ee40

33 files changed

Lines changed: 436 additions & 173 deletions

.github/workflows/autopep8.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: autopep8 Check
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
autopep8-check:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Set up Python
12+
uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.10"
15+
16+
- name: Install autopep8
17+
run: pip install autopep8
18+
19+
- name: Check formatting with autopep8
20+
id: check
21+
run: |
22+
# Check if autopep8 would make changes
23+
formatting_issues=$(autopep8 --diff --recursive --max-line-length 120 .)
24+
if [[ formatting_issues ]] then
25+
echo "Formatting issues found:"
26+
printf "%s\n" "$formatting_issues"
27+
echo "------------------------------"
28+
echo "-- Formatting issues found! --"
29+
echo "------------------------------"
30+
exit 1
31+
else
32+
echo "No formatting issues found."
33+
fi
34+

.github/workflows/run-demo.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow installs required Python dependencies and then runs the demo.
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Run Demo
5+
6+
on:
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
permissions:
11+
contents: read
12+
13+
defaults:
14+
run:
15+
working-directory: ./demo/Titanic
16+
17+
jobs:
18+
build:
19+
20+
runs-on: windows-latest # Deliberately different OS compared to the test run.
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Python
25+
uses: actions/setup-python@v3
26+
with:
27+
python-version: "3.14" # Deliberately different Python version compared to the test run.
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip # upgrade pip to latest version
31+
pip install -r requirements.txt # install demo dependencies
32+
- name: Run basic demo (no repeating scenarios)
33+
run: python run_demo.py miss
34+
- name: Run extended demo
35+
run: python run_demo.py extended

.github/workflows/run-tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow installs required Python dependencies and then runs the available tests.
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Run Acceptance and Unit tests
5+
6+
on:
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: "3.10" # Only the oldest supported Python version is included here
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip # upgrade pip to latest version
27+
pip install . # install pyproject.toml dependencies - excludes optional dependencies (such as visualisation)
28+
- name: Run tests
29+
run: |
30+
python run_tests.py

CONTRIBUTING.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Contribution guidelines RobotMBT
2+
3+
Welcome! Thank you for considering to contribute to this project. If you haven't already, because your contribution already starts when you use this software and share your experiences with the people around you. These guidelines will help you to further connect with the online community.
4+
5+
## Communication channels
6+
7+
### Slack
8+
9+
If you want to ask or answer questions and participate in discussions, then the [Robot Framework Slack](http://slack.robotframework.org/) channels are a good place to do so.
10+
11+
### GitHub
12+
13+
If you want to get involved on GitHub, you can so by submitting issues or offering code improvements. These guidelines will help you to find your way. These guidelines expect readers to have a basic knowledge about open source as well as why and how to contribute to an open source project. If you are new to these topics, please have a look at the generic [Open Source Guides](https://opensource.guide/) first.
14+
15+
## Code of Conduct
16+
17+
If you want to be part of this community, then we expect you to respect our norms and values. These are in line with the [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-community-code-of-conduct) and the [Slack Code of Conduct](https://docs.slack.dev/community-code-of-conduct/). In short, we expect you to:
18+
19+
- Be welcoming.
20+
- Be kind.
21+
- Look out for each other.
22+
23+
## Submitting issues
24+
25+
Defects and enhancements are tracked in [GitHub Issues](https://github.com/JFoederer/robotframeworkMBT/issues). Before submitting an issue here, please make sure the issue is caused by this project in particular. If you are unsure if something is worth submitting, you can first ask on [Slack](http://slack.robotframework.org/). Before submitting a new issue, it is always a good idea to check if something similar was already reported. If it is, please add your comments to the existing issue instead of creating a new one. Communication in issues on GitHub is done in English.
26+
27+
Take notice that issues do not get resolved by themselves. Someone will need to spend time on the topic. Be prepared to wait, contribute yourself or arrange budget to hire someone for the job.
28+
29+
### Reporting defects
30+
31+
When reporting a defect, be precise and concise in your description. Write in way that helps others understand and reproduce the issue. Screenshots can be very helpful, but when adding logging or other textual information, please keep the textual form.
32+
33+
Note that all information in the issue tracker is public. *Do not include any confidential information there*.
34+
35+
Be sure to add information about:
36+
37+
- The applicable version(s) of RobotMBT (use `pip list` and check for `robotframework-mbt`)
38+
- Your Robot Framework version (use `pip list` and check for `robotframework`)
39+
- Your Python version (check using `python --version`)
40+
- Your operating system
41+
- Your custom settings for RobotMBT (at the library and test suite level)
42+
43+
Version information about Robot Framework, Python and the operating system are also reported at the start of Robot's `output.xml` file.
44+
45+
### Enhancement requests
46+
47+
When proposing an enhancement, a feature request, be clear about the use cases. Who will benefit from the enhancement and in what way? Describe the expected behaviour and use concrete examples to illustrate the intent.
48+
49+
## Code contributions
50+
51+
If you have fixed a defect or implemented an enhancement, you can contribute your changes via a [GitHub Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). This is not restricted to implementation code: on the contrary, fixes and enhancements to documentation and tests alone are also very valuable!
52+
53+
### First steps
54+
55+
- [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) and/or [Fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks) the RobotMBT repo. If you are not a fan of command line tools, [GitHub Desktop](https://github.com/apps/desktop) can help you.
56+
- [Run the tests](#running-tests) to check your starting point.
57+
- Write new failing tests to cover your intended changes.
58+
- Implement your changes.
59+
- Verify that your tests pass with your implementation.
60+
61+
### Definition of Done
62+
63+
The Definition of Done for RobotMBT is when a pull request is merged. This is to ensure that pull requests are fully self-contained, and leave no open ends.
64+
65+
In other words: when the pull request is merged, it is 100% done. This keeps the main branch ready for release at all times.
66+
67+
This means that for each pull request you need to ensure that:
68+
69+
- [No regression](#non-regression-criteria) is introduced.
70+
- New functionality is covered by [tests](#guidelines-for-writing-new-tests).
71+
- [Code style](#code-style) follows the standard.
72+
- Documentation is up to date.
73+
- The PR branch is 0 commits behind the main branch.
74+
75+
### Running tests
76+
77+
Tests can be executed from the command line by running `python run_tests.py`. This will run all unit tests, followed by the Robot acceptance tests. Use `--help` for additional info.
78+
79+
### Non-regression criteria
80+
81+
The criteria for proving non-regression are:
82+
83+
- All automated regression tests pass
84+
- All supported Python, Robot Framework and OS versions still work (see `pyproject.toml` for supported versions).
85+
- The [demo](https://github.com/JFoederer/robotframeworkMBT/tree/main/demo/Titanic) still works.
86+
- Manual checks are executed to cover the automation's blind spots and subjective elements (e.g. some visual inspection on layout and assessing overall look and feel).
87+
88+
### Guidelines for writing new tests
89+
90+
For this project, we are not maintaining separate requirements documentation. The user documentation explains the software's purpose and scope, while tests further specify its concrete behaviour. Keep this in mind when writing tests and pay extra attention to documenting your test cases: they are more than just bug catchers. If code exists due to a technical limitation rather than a requirement, be sure to document your design decision.
91+
92+
Tests are located in the `atest` and `utest` folders, which stands for _acceptance test_ and _unit test_ respectively. The acceptance tests are Robot tests that cover user-visible behaviour using black-box testing techniques. They typically do not cover all details, unless some Robot Framework interaction is involved. The unit tests go more in-depth, including white box techniques to cover the _dark corners_ of the code. Choose the right type of test for what you are covering.
93+
94+
A specific challenge for this project is that there is a lot of test case generation going on. Be wary that variations in the generation process do not alter the intended coverage of a test and do not yield false positives (passing results without proof for passing), such as checking "_all_" results in an empty list. Lastly: keep the resulting total number of test cases in a run deterministic. This allows for a quick check that all test cases are still being generated.
95+
96+
### Code style
97+
98+
Maintainability is the main driver for coding style. Always write your code with the mindset that you are writing it for someone else, and that this person's experience level is slightly below the average in the project. Code is written following the [PEP 8](https://peps.python.org/pep-0008) Style guide and [SOLID](https://en.wikipedia.org/wiki/SOLID) principles.
99+
100+
#### Formatting
101+
102+
Formatting follows the default rules of [autopep8](https://pypi.org/project/autopep8/) with the exception of the maximum line length (see https://github.com/JFoederer/robotframeworkMBT/tree/main/.github/workflows/autopep8.yml). Note however, that the extended line length is not an invite to always write long lines.
103+
104+
Researchers have suggested that longer lines are better suited for cases when the information will likely be scanned, while shorter lines (45-75 characters) are appropriate when the information is meant to be read thoroughly [[ref.](https://www.academia.edu/6232736/The_influence_of_font_type_and_line_length_on_visual_search_and_information_retrieval_in_web_pages)]. Keep this in mind when writing code and documentation, taking the current indentation level into account.
105+
106+
#### Docstrings, comments and logging
107+
108+
- Docstrings are written using a black-box approach. One should not need to know the inside of a class or function in order to use it.
109+
- Use comments to annotate code for maintainers.
110+
- Prevent trivial comments and use descriptive names to make your code self-explanatory.
111+
- When documenting external interfaces, also check whether the user documentation requires an update.
112+
- Log useful information that is runtime-dependent.
113+
- Information that is useful after a passing test run is logged at info-level.
114+
- Information that is useful for analysing failed tests is logged at debug-level.
115+
116+
- Be careful not to make assumptions in what you log: Recheck log statements if your changes affect the context in which the code is run, and only report about what you know to be true.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ If you want to set configuration options for use in multiple test suites without
205205

206206
Tip: [Robot dictionaries](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#dictionary-variable) (`&{ }`) can be used to group related options and pass them as one set.
207207

208+
## Contributing
209+
210+
If you have feedback, ideas, or want to get involved in coding, then check out the [Contribution guidelines](https://github.com/JFoederer/robotframeworkMBT/blob/main/CONTRIBUTING.md).
211+
208212
## Disclaimer
209213

210214
Please note that this library is in a premature state and hasn't reached its first official (1.0) release yet. Developments are ongoing within the context of the [TiCToC](https://tictoc.cs.ru.nl/) research project. Interface changes are still frequent, and no deprecation warnings are being issued yet.

atest/robotMBT tests/03__parse_model_info/MyProcessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def _fail_on_step_errors(self):
1515
if self.in_suite.has_error():
1616
msg = "\n".join(["Error(s) detected in at least one step"] +
1717
[f"{step.kw_wo_gherkin} FAILED: {step.model_info['error']}"
18-
for step in self.in_suite.steps_with_errors()])
18+
for step in self.in_suite.steps_with_errors()])
1919
raise Exception(msg)

atest/robotMBT tests/07__processor_options/option_handling/suiterepeater.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
from robot.api.deco import library
44

5+
56
@library(auto_keywords=None, listener=True)
67
class SuiteRepeater:
78
"""
89
Given a test suite, repeats all scenarios 'repeat' times (default=1)
910
Setting bonus_scenario=${True} repeats 1 additional time
1011
sub-suites are ignored
1112
"""
13+
1214
def process_test_suite(self, in_suite, repeat=1, **kwargs):
1315
n_repeats = int(repeat)
1416
if kwargs.get('bonus_scenario', False):
15-
n_repeats +=1
17+
n_repeats += 1
1618
out_suite = copy.deepcopy(in_suite)
1719
out_suite.scenarios = n_repeats*out_suite.scenarios
1820
for i in range(len(out_suite.scenarios)):

atest/robotMBT tests/07__processor_options/random_seeds/01__generating_random_traces/traces.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from robot.api.deco import keyword
22

3+
34
class traces:
45
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
6+
57
def reset_traces(self):
68
self.traces = {}
79

810
@keyword("Trace '${trace}', scenario number ${test_id} is executed")
9-
def add_test(self, trace, test_id:str):
11+
def add_test(self, trace, test_id: str):
1012
"""*model info*
1113
:IN: None
1214
:OUT: None

demo/Titanic/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# robotMBT Titanic demo
1+
# RobotMBT Titanic demo
22

33
## What is it?
44

5-
The purpose of this demo is to showcase the Model-Based Testing concepts available from the [robotMBT](https://github.com/JFoederer/robotframeworkMBT) library using a [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) style project. It is based on the principle of [specification by example](https://en.wikipedia.org/wiki/Specification_by_example), using _given-when-then_ style scenarios.
5+
The purpose of this demo is to showcase the Model-Based Testing concepts available from the [RobotMBT](https://github.com/JFoederer/robotframeworkMBT) library using a [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) style project. It is based on the principle of [specification by example](https://en.wikipedia.org/wiki/Specification_by_example), using _given-when-then_ style scenarios.
66

7-
Given-steps typically describe preconditions, i.e. state, but classically given-steps are implemented as actions to get to that desired precondition. Now, consider using [specification by example](https://en.wikipedia.org/wiki/Specification_by_example). If your specification is complete, and your examples are consistent, then any given-state must be reachable by operating the system within specification, following the examples. In this demo we use [robotMBT](https://github.com/JFoederer/robotframeworkMBT) to specify a complete story, on varying levels of detail, using small consise scenarios. Then we let [robotMBT](https://github.com/JFoederer/robotframeworkMBT) construct a complete storyline, so we don't have to worry about how to reach all the correct preconditions.
7+
Given-steps typically describe preconditions, i.e. state, but classically given-steps are implemented as actions to get to that desired precondition. Now, consider using [specification by example](https://en.wikipedia.org/wiki/Specification_by_example). If your specification is complete, and your examples are consistent, then any given-state must be reachable by operating the system within specification, following the examples. In this demo we use [RobotMBT](https://github.com/JFoederer/robotframeworkMBT) to specify a complete story, on varying levels of detail, using small consise scenarios. Then we let [RobotMBT](https://github.com/JFoederer/robotframeworkMBT) construct a complete storyline, so we don't have to worry about how to reach all the correct preconditions.
88

99
Please keep in mind that the library and this demo are still in the early development phases and offered functionality is still limited. However, in good agile spirit, we still wanted to publish the results.
1010

@@ -18,7 +18,7 @@ There are a total of 7 scenarios in this demo, 10 if you use the extended varian
1818

1919
It might seem odd at first, seeing the [story of Titanic](https://en.wikipedia.org/wiki/Sinking_of_the_Titanic) in a context that is typically used in more technical environments. However, the [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) process is mostly non-technical and using a topic like Titanic helps to prevent technical bias. Another important point is that we want to stick to writing and maintaining short, to-the-point scenarios. From these, we want to compose larger scenarios, describing behaviour of complex systems, start to end, like telling a story. What better use for that than a well known story?
2020

21-
The [story of Titanic](https://en.wikipedia.org/wiki/Sinking_of_the_Titanic) fits these criteria and, since it already happened, there should be little discussion on the specification. It will be interesting to see if the test case generation mechanism from [robotMBT](https://github.com/JFoederer/robotframeworkMBT) can reconstruct the familiar story, and then some variations thereof. After all, the maiden voyage of Titanic was just one example of what could have happened...
21+
The [story of Titanic](https://en.wikipedia.org/wiki/Sinking_of_the_Titanic) fits these criteria and, since it already happened, there should be little discussion on the specification. It will be interesting to see if the test case generation mechanism from [RobotMBT](https://github.com/JFoederer/robotframeworkMBT) can reconstruct the familiar story, and then some variations thereof. After all, the maiden voyage of Titanic was just one example of what could have happened...
2222

2323
## Running the demo
2424

demo/Titanic/domain_lib/JourneyLib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from simulation.titanic_in_ocean import TitanicInOcean
1111
from simulation.journey import Journey
1212

13+
1314
class JourneyLib:
1415
_journey = None
1516

0 commit comments

Comments
 (0)