removed sys.platform == 'mac' support in distutils.dist.parse_command_line and improved test coverage

This commit is contained in:
Tarek Ziadé 2009-05-17 10:44:12 +00:00
parent 50626db437
commit 016828d119
2 changed files with 39 additions and 25 deletions

View File

@ -414,11 +414,6 @@ Common commands: (see '--help-commands' for more)
# that allows the user to interactively specify the "command line". # that allows the user to interactively specify the "command line".
# #
toplevel_options = self._get_toplevel_options() toplevel_options = self._get_toplevel_options()
if sys.platform == 'mac':
import EasyDialogs
cmdlist = self.get_command_list()
self.script_args = EasyDialogs.GetArgv(
toplevel_options + self.display_options, cmdlist)
# We have to parse the command line a bit at a time -- global # We have to parse the command line a bit at a time -- global
# options, then the first command, then its options, and so on -- # options, then the first command, then its options, and so on --
@ -438,7 +433,6 @@ Common commands: (see '--help-commands' for more)
# for display options we return immediately # for display options we return immediately
if self.handle_display_options(option_order): if self.handle_display_options(option_order):
return return
while args: while args:
args = self._parse_command_opts(parser, args) args = self._parse_command_opts(parser, args)
if args is None: # user asked for help (and got it) if args is None: # user asked for help (and got it)

View File

@ -1,19 +1,19 @@
# -*- coding: latin-1 -*- # -*- coding: latin-1 -*-
"""Tests for distutils.dist.""" """Tests for distutils.dist."""
import distutils.cmd
import distutils.dist
import os import os
import StringIO import StringIO
import sys import sys
import unittest import unittest
import warnings import warnings
from test.test_support import TESTFN from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
from test.test_support import TESTFN, captured_stdout
from distutils.tests import support from distutils.tests import support
class test_dist(distutils.cmd.Command): class test_dist(Command):
"""Sample distutils extension command.""" """Sample distutils extension command."""
user_options = [ user_options = [
@ -24,7 +24,7 @@ class test_dist(distutils.cmd.Command):
self.sample_option = None self.sample_option = None
class TestDistribution(distutils.dist.Distribution): class TestDistribution(Distribution):
"""Distribution subclasses that avoids the default search for """Distribution subclasses that avoids the default search for
configuration files. configuration files.
@ -104,7 +104,7 @@ class DistributionTestCase(support.TempdirManager, unittest.TestCase):
# Check DistributionMetadata handling of Unicode fields # Check DistributionMetadata handling of Unicode fields
tmp_dir = self.mkdtemp() tmp_dir = self.mkdtemp()
my_file = os.path.join(tmp_dir, 'f') my_file = os.path.join(tmp_dir, 'f')
klass = distutils.dist.Distribution klass = Distribution
dist = klass(attrs={'author': u'Mister Café', dist = klass(attrs={'author': u'Mister Café',
'name': 'my.package', 'name': 'my.package',
@ -131,7 +131,7 @@ class DistributionTestCase(support.TempdirManager, unittest.TestCase):
def test_empty_options(self): def test_empty_options(self):
# an empty options dictionary should not stay in the # an empty options dictionary should not stay in the
# list of attributes # list of attributes
klass = distutils.dist.Distribution klass = Distribution
# catching warnings # catching warnings
warns = [] warns = []
@ -157,7 +157,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
def test_simple_metadata(self): def test_simple_metadata(self):
attrs = {"name": "package", attrs = {"name": "package",
"version": "1.0"} "version": "1.0"}
dist = distutils.dist.Distribution(attrs) dist = Distribution(attrs)
meta = self.format_metadata(dist) meta = self.format_metadata(dist)
self.assert_("Metadata-Version: 1.0" in meta) self.assert_("Metadata-Version: 1.0" in meta)
self.assert_("provides:" not in meta.lower()) self.assert_("provides:" not in meta.lower())
@ -168,7 +168,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
attrs = {"name": "package", attrs = {"name": "package",
"version": "1.0", "version": "1.0",
"provides": ["package", "package.sub"]} "provides": ["package", "package.sub"]}
dist = distutils.dist.Distribution(attrs) dist = Distribution(attrs)
self.assertEqual(dist.metadata.get_provides(), self.assertEqual(dist.metadata.get_provides(),
["package", "package.sub"]) ["package", "package.sub"])
self.assertEqual(dist.get_provides(), self.assertEqual(dist.get_provides(),
@ -179,8 +179,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assert_("obsoletes:" not in meta.lower()) self.assert_("obsoletes:" not in meta.lower())
def test_provides_illegal(self): def test_provides_illegal(self):
self.assertRaises(ValueError, self.assertRaises(ValueError, Distribution,
distutils.dist.Distribution,
{"name": "package", {"name": "package",
"version": "1.0", "version": "1.0",
"provides": ["my.pkg (splat)"]}) "provides": ["my.pkg (splat)"]})
@ -189,7 +188,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
attrs = {"name": "package", attrs = {"name": "package",
"version": "1.0", "version": "1.0",
"requires": ["other", "another (==1.0)"]} "requires": ["other", "another (==1.0)"]}
dist = distutils.dist.Distribution(attrs) dist = Distribution(attrs)
self.assertEqual(dist.metadata.get_requires(), self.assertEqual(dist.metadata.get_requires(),
["other", "another (==1.0)"]) ["other", "another (==1.0)"])
self.assertEqual(dist.get_requires(), self.assertEqual(dist.get_requires(),
@ -202,8 +201,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assert_("obsoletes:" not in meta.lower()) self.assert_("obsoletes:" not in meta.lower())
def test_requires_illegal(self): def test_requires_illegal(self):
self.assertRaises(ValueError, self.assertRaises(ValueError, Distribution,
distutils.dist.Distribution,
{"name": "package", {"name": "package",
"version": "1.0", "version": "1.0",
"requires": ["my.pkg (splat)"]}) "requires": ["my.pkg (splat)"]})
@ -212,7 +210,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
attrs = {"name": "package", attrs = {"name": "package",
"version": "1.0", "version": "1.0",
"obsoletes": ["other", "another (<1.0)"]} "obsoletes": ["other", "another (<1.0)"]}
dist = distutils.dist.Distribution(attrs) dist = Distribution(attrs)
self.assertEqual(dist.metadata.get_obsoletes(), self.assertEqual(dist.metadata.get_obsoletes(),
["other", "another (<1.0)"]) ["other", "another (<1.0)"])
self.assertEqual(dist.get_obsoletes(), self.assertEqual(dist.get_obsoletes(),
@ -225,8 +223,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assert_("Obsoletes: another (<1.0)" in meta) self.assert_("Obsoletes: another (<1.0)" in meta)
def test_obsoletes_illegal(self): def test_obsoletes_illegal(self):
self.assertRaises(ValueError, self.assertRaises(ValueError, Distribution,
distutils.dist.Distribution,
{"name": "package", {"name": "package",
"version": "1.0", "version": "1.0",
"obsoletes": ["my.pkg (splat)"]}) "obsoletes": ["my.pkg (splat)"]})
@ -251,7 +248,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
f.close() f.close()
try: try:
dist = distutils.dist.Distribution() dist = Distribution()
# linux-style # linux-style
if sys.platform in ('linux', 'darwin'): if sys.platform in ('linux', 'darwin'):
@ -269,6 +266,29 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
finally: finally:
os.remove(user_filename) 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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(DistributionTestCase)) suite.addTest(unittest.makeSuite(DistributionTestCase))