Aluode/PerceptionLabPortable
0
1"""Tests for distutils.command.config."""2 3import os4import sys5from distutils._log import log6from distutils.command.config import config, dump_file7from distutils.tests import missing_compiler_executable, support8 9import more_itertools10import path11import pytest12 13 14@pytest.fixture(autouse=True)15def info_log(request, monkeypatch):16 self = request.instance17 self._logs = []18 monkeypatch.setattr(log, 'info', self._info)19 20 21@support.combine_markers22class TestConfig(support.TempdirManager):23 def _info(self, msg, *args):24 for line in msg.splitlines():25 self._logs.append(line)26 27 def test_dump_file(self):28 this_file = path.Path(__file__).with_suffix('.py')29 with this_file.open(encoding='utf-8') as f:30 numlines = more_itertools.ilen(f)31 32 dump_file(this_file, 'I am the header')33 assert len(self._logs) == numlines + 134 35 @pytest.mark.skipif('platform.system() == "Windows"')36 def test_search_cpp(self):37 cmd = missing_compiler_executable(['preprocessor'])38 if cmd is not None:39 self.skipTest(f'The {cmd!r} command is not found')40 pkg_dir, dist = self.create_dist()41 cmd = config(dist)42 cmd._check_compiler()43 compiler = cmd.compiler44 if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():45 self.skipTest(46 'xlc: The -E option overrides the -P, -o, and -qsyntaxonly options'47 )48 49 # simple pattern searches50 match = cmd.search_cpp(pattern='xxx', body='/* xxx */')51 assert match == 052 53 match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')54 assert match == 155 56 def test_finalize_options(self):57 # finalize_options does a bit of transformation58 # on options59 pkg_dir, dist = self.create_dist()60 cmd = config(dist)61 cmd.include_dirs = f'one{os.pathsep}two'62 cmd.libraries = 'one'63 cmd.library_dirs = f'three{os.pathsep}four'64 cmd.ensure_finalized()65 66 assert cmd.include_dirs == ['one', 'two']67 assert cmd.libraries == ['one']68 assert cmd.library_dirs == ['three', 'four']69 70 def test_clean(self):71 # _clean removes files72 tmp_dir = self.mkdtemp()73 f1 = os.path.join(tmp_dir, 'one')74 f2 = os.path.join(tmp_dir, 'two')75 76 self.write_file(f1, 'xxx')77 self.write_file(f2, 'xxx')78 79 for f in (f1, f2):80 assert os.path.exists(f)81 82 pkg_dir, dist = self.create_dist()83 cmd = config(dist)84 cmd._clean(f1, f2)85 86 for f in (f1, f2):87 assert not os.path.exists(f)88 