summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_dist.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/tests/test_dist.py')
-rw-r--r--Lib/distutils/tests/test_dist.py183
1 files changed, 38 insertions, 145 deletions
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index 4b7bbeb..8aaae88 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -1,8 +1,6 @@
-# -*- coding: utf8 -*-
-
"""Tests for distutils.dist."""
import os
-import StringIO
+import io
import sys
import unittest
import warnings
@@ -10,8 +8,8 @@ import textwrap
from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
-import distutils.dist
-from test.test_support import TESTFN, captured_stdout, run_unittest
+
+from test.support import TESTFN, captured_stdout, run_unittest
from distutils.tests import support
@@ -38,8 +36,7 @@ class TestDistribution(Distribution):
return self._config_files
-class DistributionTestCase(support.TempdirManager,
- support.LoggingSilencer,
+class DistributionTestCase(support.LoggingSilencer,
support.EnvironGuard,
unittest.TestCase):
@@ -60,27 +57,6 @@ class DistributionTestCase(support.TempdirManager,
d.parse_command_line()
return d
- def test_debug_mode(self):
- with open(TESTFN, "w") as f:
- f.write("[global]\n")
- f.write("command_packages = foo.bar, splat")
-
- files = [TESTFN]
- sys.argv.append("build")
-
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
- distutils.dist.DEBUG = True
- try:
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
- finally:
- distutils.dist.DEBUG = False
-
def test_command_packages_unspecified(self):
sys.argv.append("build")
d = self.create_distribution()
@@ -106,8 +82,8 @@ class DistributionTestCase(support.TempdirManager,
self.addCleanup(os.unlink, TESTFN)
f = open(TESTFN, "w")
try:
- print >> f, "[global]"
- print >> f, "command_packages = foo.bar, splat"
+ print("[global]", file=f)
+ print("command_packages = foo.bar, splat", file=f)
finally:
f.close()
@@ -127,33 +103,6 @@ class DistributionTestCase(support.TempdirManager,
d = self.create_distribution([TESTFN])
self.assertEqual(d.get_command_packages(), ["distutils.command"])
- def test_write_pkg_file(self):
- # Check DistributionMetadata handling of Unicode fields
- tmp_dir = self.mkdtemp()
- my_file = os.path.join(tmp_dir, 'f')
- klass = Distribution
-
- dist = klass(attrs={'author': u'Mister Café',
- 'name': 'my.package',
- 'maintainer': u'Café Junior',
- 'description': u'Café torréfié',
- 'long_description': u'Héhéhé'})
-
- # let's make sure the file can be written
- # with Unicode fields. they are encoded with
- # PKG_INFO_ENCODING
- dist.metadata.write_pkg_file(open(my_file, 'w'))
-
- # regular ascii is of course always usable
- dist = klass(attrs={'author': 'Mister Cafe',
- 'name': 'my.package',
- 'maintainer': 'Cafe Junior',
- 'description': 'Cafe torrefie',
- 'long_description': 'Hehehe'})
-
- my_file2 = os.path.join(tmp_dir, 'f2')
- dist.metadata.write_pkg_file(open(my_file2, 'w'))
-
def test_empty_options(self):
# an empty options dictionary should not stay in the
# list of attributes
@@ -203,35 +152,6 @@ class DistributionTestCase(support.TempdirManager,
kwargs = {'level': 'ok2'}
self.assertRaises(ValueError, dist.announce, args, kwargs)
- def test_find_config_files_disable(self):
- # Ticket #1180: Allow user to disable their home config file.
- temp_home = self.mkdtemp()
- if os.name == 'posix':
- user_filename = os.path.join(temp_home, ".pydistutils.cfg")
- else:
- user_filename = os.path.join(temp_home, "pydistutils.cfg")
-
- with open(user_filename, 'w') as f:
- f.write('[distutils]\n')
-
- def _expander(path):
- return temp_home
-
- old_expander = os.path.expanduser
- os.path.expanduser = _expander
- try:
- d = distutils.dist.Distribution()
- all_files = d.find_config_files()
-
- d = distutils.dist.Distribution(attrs={'script_args':
- ['--no-user-cfg']})
- files = d.find_config_files()
- finally:
- os.path.expanduser = old_expander
-
- # make sure --no-user-cfg disables the user cfg file
- self.assertEqual(len(all_files)-1, len(files))
-
class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
unittest.TestCase):
@@ -245,34 +165,10 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
sys.argv[:] = self.argv[1]
super(MetadataTestCase, self).tearDown()
- def test_classifier(self):
- attrs = {'name': 'Boa', 'version': '3.0',
- 'classifiers': ['Programming Language :: Python :: 3']}
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- self.assertIn('Metadata-Version: 1.1', meta)
-
- def test_download_url(self):
- attrs = {'name': 'Boa', 'version': '3.0',
- 'download_url': 'http://example.org/boa'}
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- self.assertIn('Metadata-Version: 1.1', meta)
-
- def test_long_description(self):
- long_desc = textwrap.dedent("""\
- example::
- We start here
- and continue here
- and end here.""")
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": long_desc}
-
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- meta = meta.replace('\n' + 8 * ' ', '\n')
- self.assertIn(long_desc, meta)
+ def format_metadata(self, dist):
+ sio = io.StringIO()
+ dist.metadata.write_pkg_file(sio)
+ return sio.getvalue()
def test_simple_metadata(self):
attrs = {"name": "package",
@@ -348,10 +244,34 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
"version": "1.0",
"obsoletes": ["my.pkg (splat)"]})
- def format_metadata(self, dist):
- sio = StringIO.StringIO()
- dist.metadata.write_pkg_file(sio)
- return sio.getvalue()
+ def test_classifier(self):
+ attrs = {'name': 'Boa', 'version': '3.0',
+ 'classifiers': ['Programming Language :: Python :: 3']}
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ self.assertIn('Metadata-Version: 1.1', meta)
+
+ def test_download_url(self):
+ attrs = {'name': 'Boa', 'version': '3.0',
+ 'download_url': 'http://example.org/boa'}
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ self.assertIn('Metadata-Version: 1.1', meta)
+
+ def test_long_description(self):
+ long_desc = textwrap.dedent("""\
+ example::
+ We start here
+ and continue here
+ and end here.""")
+ attrs = {"name": "package",
+ "version": "1.0",
+ "long_description": long_desc}
+
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ meta = meta.replace('\n' + 8 * ' ', '\n')
+ self.assertIn(long_desc, meta)
def test_custom_pydistutils(self):
# fixes #2166
@@ -407,33 +327,6 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
if line.strip() != '']
self.assertTrue(output)
- def test_read_metadata(self):
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": "desc",
- "description": "xxx",
- "download_url": "http://example.com",
- "keywords": ['one', 'two'],
- "requires": ['foo']}
-
- dist = Distribution(attrs)
- metadata = dist.metadata
-
- # write it then reloads it
- PKG_INFO = StringIO.StringIO()
- metadata.write_pkg_file(PKG_INFO)
- PKG_INFO.seek(0)
- metadata.read_pkg_file(PKG_INFO)
-
- self.assertEqual(metadata.name, "package")
- self.assertEqual(metadata.version, "1.0")
- self.assertEqual(metadata.description, "xxx")
- self.assertEqual(metadata.download_url, 'http://example.com')
- self.assertEqual(metadata.keywords, ['one', 'two'])
- self.assertEqual(metadata.platforms, ['UNKNOWN'])
- self.assertEqual(metadata.obsoletes, None)
- self.assertEqual(metadata.requires, ['foo'])
-
def test_suite():
suite = unittest.TestSuite()