mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Merged revisions 72721 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72721 | tarek.ziade | 2009-05-17 12:44:12 +0200 (Sun, 17 May 2009) | 1 line removed sys.platform == 'mac' support in distutils.dist.parse_command_line and improved test coverage ........
This commit is contained in:
parent
38e2d8e263
commit
d2dd51dae9
2 changed files with 38 additions and 25 deletions
|
@ -1,18 +1,18 @@
|
|||
"""Tests for distutils.dist."""
|
||||
|
||||
import distutils.cmd
|
||||
import distutils.dist
|
||||
import os
|
||||
import io
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from test.support import TESTFN
|
||||
from distutils.dist import Distribution, fix_help_options
|
||||
from distutils.cmd import Command
|
||||
|
||||
from test.support import TESTFN, captured_stdout
|
||||
from distutils.tests import support
|
||||
|
||||
|
||||
class test_dist(distutils.cmd.Command):
|
||||
class test_dist(Command):
|
||||
"""Sample distutils extension command."""
|
||||
|
||||
user_options = [
|
||||
|
@ -23,7 +23,7 @@ class test_dist(distutils.cmd.Command):
|
|||
self.sample_option = None
|
||||
|
||||
|
||||
class TestDistribution(distutils.dist.Distribution):
|
||||
class TestDistribution(Distribution):
|
||||
"""Distribution subclasses that avoids the default search for
|
||||
configuration files.
|
||||
|
||||
|
@ -99,11 +99,10 @@ class DistributionTestCase(unittest.TestCase):
|
|||
finally:
|
||||
os.unlink(TESTFN)
|
||||
|
||||
|
||||
def test_empty_options(self):
|
||||
# an empty options dictionary should not stay in the
|
||||
# list of attributes
|
||||
klass = distutils.dist.Distribution
|
||||
klass = Distribution
|
||||
|
||||
# catching warnings
|
||||
warns = []
|
||||
|
@ -129,7 +128,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
def test_simple_metadata(self):
|
||||
attrs = {"name": "package",
|
||||
"version": "1.0"}
|
||||
dist = distutils.dist.Distribution(attrs)
|
||||
dist = Distribution(attrs)
|
||||
meta = self.format_metadata(dist)
|
||||
self.assert_("Metadata-Version: 1.0" in meta)
|
||||
self.assert_("provides:" not in meta.lower())
|
||||
|
@ -140,7 +139,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
attrs = {"name": "package",
|
||||
"version": "1.0",
|
||||
"provides": ["package", "package.sub"]}
|
||||
dist = distutils.dist.Distribution(attrs)
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.metadata.get_provides(),
|
||||
["package", "package.sub"])
|
||||
self.assertEqual(dist.get_provides(),
|
||||
|
@ -151,8 +150,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assert_("obsoletes:" not in meta.lower())
|
||||
|
||||
def test_provides_illegal(self):
|
||||
self.assertRaises(ValueError,
|
||||
distutils.dist.Distribution,
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
{"name": "package",
|
||||
"version": "1.0",
|
||||
"provides": ["my.pkg (splat)"]})
|
||||
|
@ -161,7 +159,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
attrs = {"name": "package",
|
||||
"version": "1.0",
|
||||
"requires": ["other", "another (==1.0)"]}
|
||||
dist = distutils.dist.Distribution(attrs)
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.metadata.get_requires(),
|
||||
["other", "another (==1.0)"])
|
||||
self.assertEqual(dist.get_requires(),
|
||||
|
@ -174,8 +172,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assert_("obsoletes:" not in meta.lower())
|
||||
|
||||
def test_requires_illegal(self):
|
||||
self.assertRaises(ValueError,
|
||||
distutils.dist.Distribution,
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
{"name": "package",
|
||||
"version": "1.0",
|
||||
"requires": ["my.pkg (splat)"]})
|
||||
|
@ -184,7 +181,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
attrs = {"name": "package",
|
||||
"version": "1.0",
|
||||
"obsoletes": ["other", "another (<1.0)"]}
|
||||
dist = distutils.dist.Distribution(attrs)
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.metadata.get_obsoletes(),
|
||||
["other", "another (<1.0)"])
|
||||
self.assertEqual(dist.get_obsoletes(),
|
||||
|
@ -197,8 +194,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
self.assert_("Obsoletes: another (<1.0)" in meta)
|
||||
|
||||
def test_obsoletes_illegal(self):
|
||||
self.assertRaises(ValueError,
|
||||
distutils.dist.Distribution,
|
||||
self.assertRaises(ValueError, Distribution,
|
||||
{"name": "package",
|
||||
"version": "1.0",
|
||||
"obsoletes": ["my.pkg (splat)"]})
|
||||
|
@ -223,7 +219,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
f.close()
|
||||
|
||||
try:
|
||||
dist = distutils.dist.Distribution()
|
||||
dist = Distribution()
|
||||
|
||||
# linux-style
|
||||
if sys.platform in ('linux', 'darwin'):
|
||||
|
@ -241,6 +237,29 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
finally:
|
||||
os.remove(user_filename)
|
||||
|
||||
def test_fix_help_options(self):
|
||||
help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
|
||||
fancy_options = fix_help_options(help_tuples)
|
||||
self.assertEquals(fancy_options[0], ('a', 'b', 'c'))
|
||||
self.assertEquals(fancy_options[1], (1, 2, 3))
|
||||
|
||||
def test_show_help(self):
|
||||
# smoke test, just makes sure some help is displayed
|
||||
dist = Distribution()
|
||||
old_argv = sys.argv
|
||||
sys.argv = []
|
||||
try:
|
||||
dist.help = 1
|
||||
dist.script_name = 'setup.py'
|
||||
with captured_stdout() as s:
|
||||
dist.parse_command_line()
|
||||
finally:
|
||||
sys.argv = old_argv
|
||||
|
||||
output = [line for line in s.getvalue().split('\n')
|
||||
if line.strip() != '']
|
||||
self.assert_(len(output) > 0)
|
||||
|
||||
def test_suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.makeSuite(DistributionTestCase))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue