1+ import pytest
2+ from unittest .mock import (
3+ MagicMock ,
4+ patch ,
5+ )
6+ from nox .command import CommandFailed
7+ import shutil
8+ from pathlib import Path
9+
10+ from exasol .toolbox .nox ._package import package_check , PROJECT_CONFIG
11+ from exasol .toolbox .config import BaseConfig
12+
13+ class TestDistributionCheck :
14+ @staticmethod
15+ def test_works_as_expected (nox_session ):
16+ package_check (nox_session )
17+
18+ @staticmethod
19+ def test_raises_non_zero_exist_with_readme_error (nox_session , tmp_path ):
20+ # TODOs
21+ # 1. copy package files to a temp directory
22+ # 2. mock/alter the path for the function you need to use for testing
23+ # 3. modify rst file to have a broken link like is in this commit:
24+ # - `Python <https://www.python.org/`__ >= 3.9
25+ package = Path (tmp_path )
26+ package_readme = package / "README.rst"
27+ shutil .copytree (PROJECT_CONFIG .root / "exasol" , package / "exasol" )
28+ shutil .copyfile (PROJECT_CONFIG .root / "README.rst" , package_readme )
29+ shutil .copytree (PROJECT_CONFIG .root / "doc/changes" , package / "doc/changes" )
30+ shutil .copyfile (PROJECT_CONFIG .root / "LICENSE" , package / "LICENSE" )
31+ shutil .copyfile (PROJECT_CONFIG .root / "pyproject.toml" , package / "pyproject.toml" )
32+ old = "- `Python <https://www.python.org/>`__ >= 3.9"
33+ error = "- `Python <https://www.python.org/>`__ >= 3.9"
34+ readme = package_readme .read_text ().splitlines ()
35+ error_readme = [error if old in line else line for line in readme ]
36+ package_readme .write_text ("/n" .join (error_readme ))
37+ config = BaseConfig ()
38+ mock = MagicMock (spec = BaseConfig , wraps = config )
39+ mock .root = package
40+ with pytest .raises (CommandFailed ) as e :
41+ with patch ("exasol.toolbox.nox._package.PROJECT_CONFIG" , mock ):
42+ print (PROJECT_CONFIG .root )
43+ package_check (nox_session )
44+ # verify broken with non-zero exit status
45+ assert str (e .value ) == "Returned code 1"
0 commit comments