File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555 pip install -e .
5656 pytest --doctest-modules --junitxml=junit/pytest-results-${{ matrix.python-version }}.xml --cov=$PROJECT_NAME --cov-report=xml tests/
5757
58- - name : Test examples
59- run : |
60- for f in ./examples/*.py; do echo "Processing $f file..." && python $f; done
61-
6258 - name : Run linters
6359 run : |
6460 echo "Running linters - if build fails here, please be patient!"
Original file line number Diff line number Diff line change 1+ """
2+ Generates a README.md file for the examples folder.
3+ """
4+
5+ import glob
6+ import importlib
7+ import sys
8+
9+ examples = [file for file in glob .glob ("./examples/*.py" )]
10+ examples .sort ()
11+ sys .path .append ("./examples" )
12+
13+ with open ("./examples/README.md" , mode = "wt" , encoding = "utf8 " ) as examples_readme :
14+ examples_readme .write (
15+ "<!-- generated file, to update use: python examples-summary.py -->\n \n "
16+ )
17+ examples_readme .write ("""# Examples""" )
18+
19+ for file_path in examples :
20+ if "__init__" in file_path :
21+ continue
22+
23+ module_name = file_path .replace ("./examples/" , "" ).replace (".py" , "" )
24+
25+ module = importlib .import_module (module_name )
26+
27+ if not module .__doc__ :
28+ continue
29+
30+ examples_readme .write (f"\n \n ## { module_name } .py\n " )
31+ examples_readme .write (str (module .__doc__ ))
Original file line number Diff line number Diff line change 1+ <!-- generated file, to update use: python examples-summary.py -->
2+
3+ # Examples
4+
5+ ## example-01.py
6+
7+ This example illustrates a basic usage of the Container class to register
8+ two types, and automatic resolution achieved through types inspection.
9+
10+ Two services are registered as "transient" services, meaning that a new instance is
11+ created whenever needed.
12+
13+
14+ ## example-02.py
15+
16+ This example illustrates a basic usage of the Container class to register
17+ a concrete type by base type, and its activation by base type.
18+
19+ This pattern helps writing code that is decoupled (e.g. business layer logic separated
20+ from exact implementations of data access logic).
21+
22+
23+ ## example-03.py
24+
25+ This example illustrates how to configure a singleton object.
Original file line number Diff line number Diff line change 11import glob
2- import subprocess
2+ import importlib
3+ import sys
34
45import pytest
56
67examples = [file for file in glob .glob ("./examples/*.py" )]
78
89
10+ sys .path .append ("./examples" )
11+
12+
913@pytest .mark .parametrize ("file_path" , examples )
1014def test_example (file_path : str ):
11- output = subprocess .run (["python" , file_path ])
12- assert output .returncode == 0
15+ module_name = file_path .replace ("./examples/" , "" ).replace (".py" , "" )
16+ # assertions are in imported
17+ importlib .import_module (module_name )
You can’t perform that action at this time.
0 commit comments