Message ID | 20240712121324.2200037-2-amikan@ilbers.de |
---|---|
State | Superseded, archived |
Headers | show |
Series | Python code style for the testsuite | expand |
Anton Mikanovich, Sent: Freitag, 12. Juli 2024 14:13: > Add some recomendations for testcase creators. Hi Anton, Thanks for this! I like clear rules for consistent code. Maybe one additional thing I see in the refactoring, and which could be stated explicitly: ## 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)). Plus few minor things below > > Signed-off-by: Anton Mikanovich <amikan@ilbers.de> > --- > testsuite/README.md | 45 > +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/testsuite/README.md b/testsuite/README.md > index cfcfb1bf..7cbacf99 100644 > --- a/testsuite/README.md > +++ b/testsuite/README.md > @@ -137,6 +137,51 @@ 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 preffered style is the following: *preferred > + > + - Single quotes for data and small symbol-like strings. > + - Double quotes for human-readable strings and string interpolation. > + > +## Line wrapping > + > +Argument lists don't fit in 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. Argument lists *that don't fit in *the 79 characters... > + > +## Function definition spacing > + > +Any function and class definition should done in the following way: should *be done Adriaan > + > + - 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. > -- > 2.34.1 > > -- > You received this message because you are subscribed to the Google Groups "isar- > users" group. > To unsubscribe from this group and stop receiving emails from it, send an email to > isar-users+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/isar- > users/20240712121324.2200037-2-amikan%40ilbers.de.
diff --git a/testsuite/README.md b/testsuite/README.md index cfcfb1bf..7cbacf99 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -137,6 +137,51 @@ 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 preffered 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 don't fit in 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. + +## Function definition spacing + +Any function and class definition should 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.
Add some recomendations for testcase creators. Signed-off-by: Anton Mikanovich <amikan@ilbers.de> --- testsuite/README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)