You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A \bash\ script for executing test cases with \pytest, which prints the command line and the exit code; see \cref{ut:pytest}.}%
14
+
%
12
15
Here we provide some scripts that are used within this book.
13
16
These scripts are written for the \bash\ shell, which is the default interpreter running in \ubuntu\ \linux\ \pglspl{terminal}.
14
17
Therefore, they will not work under \windows\ or other operating systems.
15
18
Now, our book focuses on \python\ programming, so \bash\ shell scripts are not in the center of our attention.
16
19
We here cannot explain how \bash\ scripts work or what their syntax is.
17
20
There exist plenty of books and resources on this interesting topic, such as~\cite{NR2005LTBSUSPCB3,Z2017MB,BN2018BC} or \url{https://www.gnu.org/software/bash/}.
21
+
18
22
If we would include the scripts in the places where we use them in this book, then this would lead to confusion or tangents in the text which would mess up the flow of the chapters.
19
23
Nevertheless, the book would be incomplete if these scripts were not provided at all.
20
-
So we put them here, at the end of the book, where they do not hurt anyone and where the interested reader may check them out.%
24
+
So we put them here, at the end of the book, where they do not hurt anyone and where the interested reader may check them out.
25
+
26
+
In the scripts, we install tools if they are not yet installed.
27
+
We then apply the tools to whatever the parameters of the scripts state.
28
+
Now, in a real environment, a tool can either succeed or fail.
29
+
A unit test executed with \pytest\ will fail and exit with a non-zero exit code if the test, well, fails.
30
+
A static code analysis tool like \ruff\ will fail with a non-zero exit code if it discovers any issue with the code.
31
+
However, our scripts invoking these tools will \emph{not} fail in such cases.
32
+
They will collect the exit code of the tool they are invoking and print it.
33
+
Then they will exit with exit code~0.
34
+
This is necessary for our book building process, which invokes these scripts to construct the outputs of the examples.
35
+
If any of them would fail with non-zero exit code, the book building would fail as well.
36
+
However, to illustrate that the tools are useful, we must apply them to cases where they would fail.
37
+
So for our book, it is necessary that the scripts just print the exit codes while still returning successfully.
38
+
For a real productive environment, this is usually not what we want:
39
+
We apply the tools to source code precisely to get them to fail on error, because if nothing fails, we know that everything seems to be OK.
40
+
In such a practical environment, you would thus not want to use \emph{our} scripts, but you could use the same comments that we use.
41
+
Anyway, here is the list of tool scripts.
21
42
22
43
\Cref{lst:bash:mypy} is a \bash\ script which first checks whether \mypy\ is installed.
23
44
If \mypy\ is not installed, it silently installs it.
@@ -40,7 +61,18 @@
40
61
\Cref{lst:bash:pylint} offers exactly the same functionality for \pylint.
41
62
It checks if this tool is installed and installs it if not.
42
63
It then applies \pylint\ to a the selected set of files, using a reasonable default configuration.
43
-
\Cref{exec:loops:for_loop_no_enumerate:pylint} is an example for the output of this \pgls{linter}.%
64
+
\Cref{exec:loops:for_loop_no_enumerate:pylint} is an example for the output of this \pgls{linter}.
65
+
66
+
\Cref{lst:bash:pytest} is similarly structured, but instead of performing \emph{static} code analysis, it executes unit test cases.
67
+
The directory and list of \python\ files with the test cases are provided as command line arguments.
68
+
This script checks if \pytest\ and its plugin \textil{pytest-timeout} are installed and, if not, installs them.
69
+
It then executes the tests with a fixed ten second timeout that we use in this book.
70
+
Of course, in practical scenarios, you would use a larger timeout, but within the context of this book, ten seconds are enough.
71
+
Either way, the script executes the test cases, prints the results as well as potential errors.
72
+
Notice that we select some options to make the output less verbose, because for this book, we do want listings that are not too long.
73
+
In practical scenarios, you may use different options.
74
+
Either way, the script also prints the command that was executed at the beginning and the \pytest\ version used and the program's exit code at the end of the output.
75
+
\Cref{exec:functions:test_my_math:pytest,exec:functions:test_my_math_2:pytest,exec:functions:test_my_math_3:pytest} are examples for the output of \pytest.%
Copy file name to clipboardExpand all lines: text/main/basics/simpleDataTypesAndOperations/int/int.tex
+2-2
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@
11
11
The draft for the \softwareStyle{C17} standard for the \pgls{C}~programming language lists five signed and five unsigned integer types, plus several ways to extend them~\cite{ISOIEC98892017PLCWDOS}.
12
12
The different integer types of both languages have different ranges and sizes, and the programmer must carefully choose which she needs to use in which situation.
13
13
14
-
\python\only has one integer type, called \pythonilIdx{int}.
14
+
\python~3 only has one integer type, called \pythonilIdx{int}.
15
15
This type has basically an unbounded range.
16
-
The \python\interpreter will allocate as much memory as is needed to store the number you want.\footnote{%
16
+
The \python~3 interpreter will allocate as much memory as is needed to store the number you want.\footnote{%
17
17
Ok, the range is not actually \emph{unbounded}, it is bounded by the amount of memory available on your computer{\dots} {\dots}but for all intents and purposes within this book, we can assume that~$\pythonilIdx{int}\equiv\integerNumbers$.}%
Copy file name to clipboardExpand all lines: text/main/basics/variables/assignment/assignment.tex
+1-1
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,7 @@
190
190
But we can never really write it down.
191
191
192
192
Well, we I say \inQuotes{we can compute it}, then the question \inQuotes{How?} immediately arises.
193
-
One particularly ingenious answer was given by the Chinese mathematician LIU Hui~\cnPdf{liuHui} somewhere in the third century~AD~\cite{CR2003LH} in his commentary to the famous Chinese mathematics book \emph{Jiu Zhang Suanshu}~\cnPdf{jiuZhangSuanShu}~\cite{CR2003LH,SCL1999TNCOTMACAC,S1998LHATFGAOCM,D2010AALHOCAS,C2002LFLHADWTDM}.
193
+
One particularly ingenious answer was given by the Chinese mathematician LIU Hui~\cnPdf{liuHui} somewhere in the third century~AD~\cite{OR2003LH} in his commentary to the famous Chinese mathematics book \emph{Jiu Zhang Suanshu}~\cnPdf{jiuZhangSuanShu}~\cite{OR2003LH,SCL1999TNCOTMACAC,S1998LHATFGAOCM,D2010AALHOCAS,C2002LFLHADWTDM}.
194
194
In \cref{fig:liuHuiCircle}, we show how~\numberPi, i.e., the ratio of the circumference and the diameter of a circle can be approximated by inscribing regular~$e$\nobreakdash-gons into a circle.
195
195
The corners of the $e$\nobreakdash-gons lie on the circle.
0 commit comments