11import pytest
2+ import contextlib
3+ from dataclasses import dataclass
4+ from pathlib import Path
25import re
36from inspect import cleandoc
4- from unittest .mock import Mock , patch
7+ from unittest .mock import Mock , patch , call
58from exasol .toolbox .nox ._artifacts import copy_artifacts
69
710
8-
9- @pytest .fixture
10- def python_version ():
11- return "9.9"
12-
13-
14- @pytest .fixture
15- def project_config (python_version ):
11+ @contextlib .contextmanager
12+ def mock_session (path : Path , python_version : str , * files : str ):
1613 with patch ("exasol.toolbox.nox._artifacts.PROJECT_CONFIG" ) as config :
1714 config .python_versions = [python_version ]
18- yield config
15+ for rel in files :
16+ file = path / rel
17+ file .parent .mkdir (parents = True , exist_ok = True )
18+ file .write_text (rel )
19+ yield Mock (posargs = [str (path )])
1920
2021
21- def test_no_coverage ( project_config , tmp_path , capsys ):
22- session = Mock ( posargs = [ str ( tmp_path )])
23- copy_artifacts (session )
22+ def test_missing_files ( tmp_path , capsys ):
23+ with mock_session ( tmp_path , "9.9" ) as session :
24+ copy_artifacts (session )
2425 captured = capsys .readouterr ()
25- re .match (
26+ assert re .match (
2627 cleandoc (
2728 f"""
2829 Could not find any file .*/coverage-python9.9\\ */.coverage
@@ -33,5 +34,51 @@ def test_no_coverage(project_config, tmp_path, capsys):
3334 ),
3435 captured .err ,
3536 )
36- with capsys .disabled ():
37- print (captured .err )
37+ #with capsys.disabled():
38+ # print(captured.err)
39+
40+
41+ @dataclass
42+ class endswith :
43+ """
44+ Assert that the str representation of the argument ends with the
45+ specfied suffix.
46+ """
47+ suffix : str
48+
49+ def __eq__ (self , actual ):
50+ return str (actual ).endswith (self .suffix )
51+
52+
53+ def test_all_files (tmp_path , capsys ):
54+ with mock_session (
55+ tmp_path / "artifacts" ,
56+ "9.9" ,
57+ "coverage-python9.9-fast/.coverage" ,
58+ "coverage-python9.9-slow/.coverage" ,
59+ "lint-python9.9/.lint.txt" ,
60+ "lint-python9.9/.lint.json" ,
61+ "security-python9.9/.security.json"
62+ ) as session :
63+ copy_artifacts (session )
64+
65+ captured = capsys .readouterr ()
66+ assert session .run .call_args == call (
67+ "coverage" ,
68+ "combine" ,
69+ "--keep" ,
70+ endswith ("coverage-python9.9-fast/.coverage" ),
71+ endswith ("coverage-python9.9-slow/.coverage" ),
72+ )
73+ assert re .match (
74+ cleandoc (
75+ f"""
76+ Copying file .*/lint-python9.9/.lint.txt
77+ Copying file .*/lint-python9.9/.lint.json
78+ Copying file .*/security-python9.9/.security.json
79+ """
80+ ),
81+ captured .err ,
82+ )
83+ for f in [".lint.txt" , ".lint.json" , ".security.json" ]:
84+ assert (tmp_path / f ).exists ()
0 commit comments