"""Tests for distutils.command.check."""
import os
import textwrap
from distutils.command.check import check
from distutils.errors import DistutilsSetupError
from distutils.tests import support
import pytest
try:
import pygments
except ImportError:
pygments = None
HERE = os.path.dirname(__file__)
@support.combine_markers
class TestCheck(support.TempdirManager):
def _run(self, metadata=None, cwd=None, **options):
if metadata is None:
metadata = {}
if cwd is not None:
old_dir = os.getcwd()
os.chdir(cwd)
pkg_info, dist = self.create_dist(**metadata)
cmd = check(dist)
cmd.initialize_options()
for name, value in options.items():
setattr(cmd, name, value)
cmd.ensure_finalized()
cmd.run()
if cwd is not None:
os.chdir(old_dir)
return cmd
def test_check_metadata(self):
# let's run the command with no metadata at all
# by default, check is checking the metadata
# should have some warnings
cmd = self._run()
assert cmd._warnings == 1
# now let's add the required fields
# and run it again, to make sure we don't get
# any warning anymore
metadata = {
'url': 'xxx',
'author': 'xxx',
'author_email': 'xxx',
'name': 'xxx',
'version': 'xxx',
}
cmd = self._run(metadata)
assert cmd._warnings == 0
# now with the strict mode, we should
# get an error if there are missing metadata
with pytest.raises(DistutilsSetupError):
self._run({}, **{'strict': 1})
# and of course, no error when all metadata are present
cmd = self._run(metadata, strict=True)
assert cmd._warnings == 0
# now a test with non-ASCII characters
metadata = {
'url': 'xxx',
'author': '\u00c9ric',
'author_email': 'xxx',
'name': 'xxx',
'version': 'xxx',
'description': 'Something about esszet \u00df',
'long_description': 'More things about esszet \u00df',
}
cmd = self._run(metadata)
assert cmd._warnings == 0
def test_check_author_maintainer(self):
for kind in ("author", "maintainer"):
# ensure no warning when author_email or maintainer_email is given
# (the spec allows these fields to take the form "Name