Commit f24a0504 authored by Éric Araujo's avatar Éric Araujo

Minor code reorganization in one packaging test file

parent 0d58ff9f
"""Tests for packaging.command.sdist.""" """Tests for packaging.command.sdist."""
import os import os
import zipfile
import tarfile import tarfile
import zipfile
from packaging.tests.support import requires_zlib
try: try:
import grp import grp
...@@ -12,16 +10,16 @@ try: ...@@ -12,16 +10,16 @@ try:
except ImportError: except ImportError:
UID_GID_SUPPORT = False UID_GID_SUPPORT = False
from shutil import get_archive_formats
from os.path import join from os.path import join
from packaging.tests import captured_stdout
from packaging.command.sdist import sdist
from packaging.command.sdist import show_formats
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.tests import unittest
from packaging.errors import PackagingOptionError
from packaging.util import find_executable from packaging.util import find_executable
from packaging.tests import support from packaging.errors import PackagingOptionError
from shutil import get_archive_formats from packaging.command.sdist import sdist, show_formats
from packaging.tests import support, unittest
from packaging.tests import captured_stdout
from packaging.tests.support import requires_zlib
MANIFEST = """\ MANIFEST = """\
...@@ -88,7 +86,6 @@ class SDistTestCase(support.TempdirManager, ...@@ -88,7 +86,6 @@ class SDistTestCase(support.TempdirManager,
# creating VCS directories with some files in them # creating VCS directories with some files in them
os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx') self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
os.mkdir(join(self.tmp_dir, 'somecode', '.hg')) os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
...@@ -216,12 +213,14 @@ class SDistTestCase(support.TempdirManager, ...@@ -216,12 +213,14 @@ class SDistTestCase(support.TempdirManager,
# testing the `check-metadata` option # testing the `check-metadata` option
dist, cmd = self.get_cmd(metadata={'name': 'xxx', 'version': 'xxx'}) dist, cmd = self.get_cmd(metadata={'name': 'xxx', 'version': 'xxx'})
# this should raise some warnings # this should cause the check subcommand to log two warnings:
# with the check subcommand # version is invalid, home-page and author are missing
cmd.ensure_finalized() cmd.ensure_finalized()
cmd.run() cmd.run()
warnings = self.get_logs() warnings = self.get_logs()
self.assertEqual(len(warnings), 4) check_warnings = [msg for msg in warnings if
not msg.startswith('sdist:')]
self.assertEqual(len(check_warnings), 2, warnings)
# trying with a complete set of metadata # trying with a complete set of metadata
self.loghandler.flush() self.loghandler.flush()
...@@ -244,7 +243,6 @@ class SDistTestCase(support.TempdirManager, ...@@ -244,7 +243,6 @@ class SDistTestCase(support.TempdirManager,
self.assertEqual(len(output), num_formats) self.assertEqual(len(output), num_formats)
def test_finalize_options(self): def test_finalize_options(self):
dist, cmd = self.get_cmd() dist, cmd = self.get_cmd()
cmd.finalize_options() cmd.finalize_options()
...@@ -263,6 +261,18 @@ class SDistTestCase(support.TempdirManager, ...@@ -263,6 +261,18 @@ class SDistTestCase(support.TempdirManager,
cmd.formats = 'supazipa' cmd.formats = 'supazipa'
self.assertRaises(PackagingOptionError, cmd.finalize_options) self.assertRaises(PackagingOptionError, cmd.finalize_options)
@requires_zlib
def test_template(self):
dist, cmd = self.get_cmd()
dist.extra_files = ['include yeah']
cmd.ensure_finalized()
self.write_file((self.tmp_dir, 'yeah'), 'xxx')
cmd.run()
with open(cmd.manifest) as f:
content = f.read()
self.assertIn('yeah', content)
@requires_zlib @requires_zlib
@unittest.skipUnless(UID_GID_SUPPORT, "requires grp and pwd support") @unittest.skipUnless(UID_GID_SUPPORT, "requires grp and pwd support")
@unittest.skipIf(find_executable('tar') is None or @unittest.skipIf(find_executable('tar') is None or
...@@ -367,18 +377,6 @@ class SDistTestCase(support.TempdirManager, ...@@ -367,18 +377,6 @@ class SDistTestCase(support.TempdirManager,
self.assertEqual(manifest, ['README.manual']) self.assertEqual(manifest, ['README.manual'])
@requires_zlib
def test_template(self):
dist, cmd = self.get_cmd()
dist.extra_files = ['include yeah']
cmd.ensure_finalized()
self.write_file((self.tmp_dir, 'yeah'), 'xxx')
cmd.run()
with open(cmd.manifest) as f:
content = f.read()
self.assertIn('yeah', content)
@requires_zlib @requires_zlib
def test_manifest_builder(self): def test_manifest_builder(self):
dist, cmd = self.get_cmd() dist, cmd = self.get_cmd()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment