File tree Expand file tree Collapse file tree 5 files changed +70
-3
lines changed
Expand file tree Collapse file tree 5 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 1+ name : CI
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Checkout repository
14+ uses : actions/checkout@v3
15+
16+ - name : Install Nix
17+ uses : cachix/install-nix-action@v17
18+ with :
19+ nix_path : nixpkgs=channel:nixos-25.05
20+
21+ - name : Update flake inputs
22+ run : nix flake update --recreate-lock-file
23+
24+ - name : Build Nix package
25+ run : nix build
Original file line number Diff line number Diff line change 2222
2323 # Define the Python version and the application package.
2424 python310 = pkgs . python310 ;
25+ hatchling = python310 . pkgs . hatchling ;
26+ pytest = python310 . pkgs . pytest ;
27+
28+
2529
2630 # Define the Python application package using hatchling for building.
2731 # This assumes you have a basic Python project structure with a pyproject.toml.
3034 version = "0.1.0" ;
3135 src = ./. ;
3236 format = "pyproject" ;
33- nativeBuildInputs = [ python310 . pkgs . hatchling ] ;
37+ nativeBuildInputs = [ hatchling pytest ] ;
38+ doCheck = true ;
39+ checkPhase = ''
40+ pytest tests
41+ '' ;
3442 } ;
3543 # End of let expression. We can now use the defined variables in let.
3644 # This is where we define the outputs of the flake.
6876 # This includes the Python interpreter and hatchling for building the application.
6977 buildInputs = [
7078 python310
71- python310 . hatchling
79+ hatchling
7280 ] ;
7381 } ;
7482 } ;
Original file line number Diff line number Diff line change @@ -17,4 +17,10 @@ basic_python_app = "basic_python_app.__main__:main"
1717
1818[project .optional-dependencies ]
1919dev = [
20- ]
20+ " pytest>=7.0.0" ,
21+ " pytest-cov>=4.0.0"
22+ ]
23+
24+ [tool .pytest .ini_options ]
25+ testpaths = [" tests" ]
26+ python_files = " test_*.py"
Original file line number Diff line number Diff line change 1+ """
2+ Package de tests pour basic_python_app.
3+ """
Original file line number Diff line number Diff line change 1+ """
2+ Tests pour le module __main__ de basic_python_app.
3+ """
4+ import pytest
5+ from unittest .mock import patch
6+ from io import StringIO
7+ from basic_python_app .__main__ import main
8+
9+ def test_main_output ():
10+ """
11+ Test que la fonction main() affiche correctement le message attendu.
12+ """
13+ with patch ('sys.stdout' , new = StringIO ()) as fake_out :
14+ main ()
15+ assert fake_out .getvalue ().strip () == "Hello from basic_python_app!"
16+
17+ def test_main_execution ():
18+ """
19+ Test que la fonction main() s'exécute sans erreur.
20+ """
21+ try :
22+ main ()
23+ assert True
24+ except Exception as e :
25+ pytest .fail (f"L'exécution de main() a levé une exception: { e } " )
You can’t perform that action at this time.
0 commit comments