11import os
22import subprocess
3+ from pathlib import Path
4+ from shutil import which
35from sys import platform
46from typing import Sequence
57
68import pytest
79
10+ IS_WINDOWS = platform .startswith ("win" )
11+ IS_WINDOWS_CI = IS_WINDOWS and os .environ .get ('CI' , False )
12+
813
914def test_project_folder (cookies ):
1015 project = cookies .bake ()
@@ -16,37 +21,46 @@ def test_project_folder(cookies):
1621
1722
1823def run (args : Sequence [str ], dirpath : os .PathLike ) -> subprocess .CompletedProcess :
19- return subprocess .run (args = args ,
20- stdout = subprocess .PIPE ,
21- stderr = subprocess .PIPE ,
22- cwd = dirpath ,
23- encoding = "utf-8" )
24+ completed_process = subprocess .run (args = args ,
25+ stdout = subprocess .PIPE ,
26+ stderr = subprocess .PIPE ,
27+ cwd = dirpath ,
28+ encoding = "utf-8" )
29+ print (completed_process .stdout )
30+ print (completed_process .stderr )
31+ return completed_process
2432
2533
2634@pytest .fixture
2735def baked_with_development_dependencies (cookies ):
2836 result = cookies .bake ()
29- env_output = run (['python3' , '-m' , 'venv' , 'env' ], result .project )
30- assert env_output .returncode == 0
31- env_bin = 'env/Scripts/' if platform .startswith ("win" ) else 'env/bin/'
32- latest_pip_output = run ([f'{ env_bin } pip3' , 'install' , '--upgrade' , 'pip' , 'setuptools' ], result .project )
37+ if IS_WINDOWS_CI :
38+ # Creating virtualenv does not work on Windows CI,
39+ # falling back to using current pip3 dir
40+ pip = Path (which ('pip3' ))
41+ bin_dir = str (pip .parent ) + '\\ '
42+ else :
43+ env_output = run (['python3' , '-m' , 'venv' , 'env' ], result .project )
44+ assert env_output .returncode == 0
45+ bin_dir = 'env/Scripts/' if IS_WINDOWS else 'env/bin/'
46+ latest_pip_output = run ([f'{ bin_dir } pip3' , 'install' , '--upgrade' , 'pip' , 'setuptools' ], result .project )
3347 assert latest_pip_output .returncode == 0
34- pip_output = run ([f'{ env_bin } pip3' , 'install' , '--editable' , '.[dev]' ], result .project )
48+ pip_output = run ([f'{ bin_dir } pip3' , 'install' , '--editable' , '.[dev]' ], result .project )
3549 assert pip_output .returncode == 0
36- return result .project , env_bin
50+ return result .project , bin_dir
3751
3852
3953def test_pytest (baked_with_development_dependencies ):
40- project_dir , env_bin = baked_with_development_dependencies
41- pytest_output = run ([f'{ env_bin } pytest' ], project_dir )
54+ project_dir , bin_dir = baked_with_development_dependencies
55+ pytest_output = run ([f'{ bin_dir } pytest' ], project_dir )
4256 assert pytest_output .returncode == 0
4357 assert '== 4 passed in' in pytest_output .stdout
4458 assert (project_dir / 'coverage.xml' ).exists ()
4559 assert (project_dir / 'htmlcov/index.html' ).exists ()
4660
4761
4862def test_subpackage (baked_with_development_dependencies ):
49- project_dir , env_bin = baked_with_development_dependencies
63+ project_dir , bin_dir = baked_with_development_dependencies
5064 subpackage = (project_dir / 'my_python_package' / 'mysub' )
5165 subpackage .mkdir ()
5266 (subpackage / '__init__.py' ).write_text ('FOO = "bar"' , encoding = "utf-8" )
@@ -55,7 +69,19 @@ def test_subpackage(baked_with_development_dependencies):
5569 subsubpackage .mkdir ()
5670 (subsubpackage / '__init__.py' ).write_text ('FOO = "bar"' , encoding = "utf-8" )
5771
58- build_output = run ([f'{ env_bin } python3' , 'setup.py' , 'build' ], project_dir )
72+ if IS_WINDOWS_CI :
73+ # On Windows CI python and pip executable are in different paths
74+ bin_dir = ''
75+ build_output = run ([f'{ bin_dir } python' , 'setup.py' , 'build' ], project_dir )
5976 assert build_output .returncode == 0
6077 assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py' ).exists ()
6178 assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py' ).exists ()
79+
80+
81+ def test_generate_api_docs (baked_with_development_dependencies ):
82+ project_dir , bin_dir = baked_with_development_dependencies
83+
84+ build_output = run ([f'{ bin_dir } sphinx-build' , '-b' , 'html' , 'docs' , 'docs/_build/html' ], project_dir )
85+ assert build_output .returncode == 0
86+ assert 'build succeeded' in build_output .stdout
87+ assert (project_dir / 'docs' / '_build' / 'html' / 'index.html' ).exists ()
0 commit comments