[v2,1/2] testsuite: Provide code style documentation

Message ID 20240719062940.2601132-2-amikan@ilbers.de
State Accepted, archived
Headers show
Series Python code style for the testsuite | expand

Commit Message

Anton Mikanovich July 19, 2024, 6:29 a.m. UTC
Add some recomendations for testcase creators.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 testsuite/README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

Patch

diff --git a/testsuite/README.md b/testsuite/README.md
index cfcfb1bf..3b2be5af 100644
--- a/testsuite/README.md
+++ b/testsuite/README.md
@@ -137,6 +137,56 @@  avocado so that isar testsuite files could be found:
 export PYTHONPATH=${PYTHONPATH}:${TESTSUITEDIR}
 ```
 
+# Code style for testcases
+
+Recommended Python code style for the testcases is based on
+[PEP8 Style Guide for Python Code](https://peps.python.org/pep-0008) with
+several additions described below.
+
+## Using quotes
+
+Despite [PEP8](https://peps.python.org/pep-0008) doesn't have any string quote
+usage recommendations, Isar preferred style is the following:
+
+ - Single quotes for data and small symbol-like strings.
+ - Double quotes for human-readable strings and string interpolation.
+
+## Line wrapping
+
+Argument lists that don't fit in the 79 characters line limit should be placed
+on the new line, keeping them on the same line if possible. Otherwise every
+single argument should be placed in separate line.
+
+## String formatting
+
+Use format strings (f"The value is {x}") instead of printf-style formatting
+("The value is %d" % x) or string concatenations ("The value is " + str(x)).
+
+## Function definition spacing
+
+Any function and class definition should be done in the following way:
+
+ - One line before and after inner functions.
+ - Two lines before and after module-level functions and classes.
+
+## Tools for checking code style
+
+To check the compliance with PEP8 standards:
+
+```
+$ flake8 sample.py
+```
+
+To format the code to recommended code style:
+
+```
+$ black -S -l 79 sample.py
+```
+
+Black use it's own [code style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html)
+based on [PEP8](https://peps.python.org/pep-0008), so some options should be
+used to set non-default style checking behaviour.
+
 # Example of the downstream testcase
 
 See `meta-isar/test` for an example of the testcase for kas-based downstream.