mirror of
https://github.com/python/cpython.git
synced 2025-09-22 08:23:36 +00:00
Minor tweaks in packaging’s test_dist.
- Use different Metadata objects to write and read a PKG-INFO (METADATA) file, to make sure the tested values come from the file - No need to restore methods on an instance after monkey-patching them: the methods are still the same on the class - Harmonize dedent calls
This commit is contained in:
parent
3e85e54274
commit
d2c7e3fe96
1 changed files with 15 additions and 21 deletions
|
@ -10,6 +10,7 @@ import packaging.dist
|
||||||
from packaging.dist import Distribution
|
from packaging.dist import Distribution
|
||||||
from packaging.command import set_command
|
from packaging.command import set_command
|
||||||
from packaging.command.cmd import Command
|
from packaging.command.cmd import Command
|
||||||
|
from packaging.metadata import Metadata
|
||||||
from packaging.errors import PackagingModuleError, PackagingOptionError
|
from packaging.errors import PackagingModuleError, PackagingOptionError
|
||||||
from packaging.tests import TESTFN, captured_stdout
|
from packaging.tests import TESTFN, captured_stdout
|
||||||
from packaging.tests import support, unittest
|
from packaging.tests import support, unittest
|
||||||
|
@ -203,13 +204,13 @@ class DistributionTestCase(support.TempdirManager,
|
||||||
config_file = os.path.join(temp_home, "config1.cfg")
|
config_file = os.path.join(temp_home, "config1.cfg")
|
||||||
hooks_module = os.path.join(temp_home, pyname)
|
hooks_module = os.path.join(temp_home, pyname)
|
||||||
|
|
||||||
self.write_file(config_file, textwrap.dedent('''
|
self.write_file(config_file, textwrap.dedent('''\
|
||||||
[test_dist]
|
[test_dist]
|
||||||
pre-hook.test = %(modname)s.log_pre_call
|
pre-hook.test = %(modname)s.log_pre_call
|
||||||
post-hook.test = %(modname)s.log_post_call'''
|
post-hook.test = %(modname)s.log_post_call'''
|
||||||
% {'modname': module_name}))
|
% {'modname': module_name}))
|
||||||
|
|
||||||
self.write_file(hooks_module, textwrap.dedent('''
|
self.write_file(hooks_module, textwrap.dedent('''\
|
||||||
record = []
|
record = []
|
||||||
|
|
||||||
def log_pre_call(cmd):
|
def log_pre_call(cmd):
|
||||||
|
@ -229,15 +230,9 @@ class DistributionTestCase(support.TempdirManager,
|
||||||
self.addCleanup(unload, module_name)
|
self.addCleanup(unload, module_name)
|
||||||
record = __import__(module_name).record
|
record = __import__(module_name).record
|
||||||
|
|
||||||
old_run = cmd.run
|
|
||||||
old_finalize = cmd.finalize_options
|
|
||||||
cmd.run = lambda: record.append('run')
|
cmd.run = lambda: record.append('run')
|
||||||
cmd.finalize_options = lambda: record.append('finalize')
|
cmd.finalize_options = lambda: record.append('finalize')
|
||||||
try:
|
|
||||||
d.run_command('test_dist')
|
d.run_command('test_dist')
|
||||||
finally:
|
|
||||||
cmd.run = old_run
|
|
||||||
cmd.finalize_options = old_finalize
|
|
||||||
|
|
||||||
self.assertEqual(record, ['finalize',
|
self.assertEqual(record, ['finalize',
|
||||||
'pre-test_dist',
|
'pre-test_dist',
|
||||||
|
@ -248,7 +243,7 @@ class DistributionTestCase(support.TempdirManager,
|
||||||
temp_home = self.mkdtemp()
|
temp_home = self.mkdtemp()
|
||||||
config_file = os.path.join(temp_home, "config1.cfg")
|
config_file = os.path.join(temp_home, "config1.cfg")
|
||||||
|
|
||||||
self.write_file(config_file, textwrap.dedent('''
|
self.write_file(config_file, textwrap.dedent('''\
|
||||||
[test_dist]
|
[test_dist]
|
||||||
pre-hook.test = nonexistent.dotted.name'''))
|
pre-hook.test = nonexistent.dotted.name'''))
|
||||||
|
|
||||||
|
@ -263,7 +258,7 @@ class DistributionTestCase(support.TempdirManager,
|
||||||
temp_home = self.mkdtemp()
|
temp_home = self.mkdtemp()
|
||||||
config_file = os.path.join(temp_home, "config1.cfg")
|
config_file = os.path.join(temp_home, "config1.cfg")
|
||||||
|
|
||||||
self.write_file(config_file, textwrap.dedent('''
|
self.write_file(config_file, textwrap.dedent('''\
|
||||||
[test_dist]
|
[test_dist]
|
||||||
pre-hook.test = packaging.tests.test_dist.__doc__'''))
|
pre-hook.test = packaging.tests.test_dist.__doc__'''))
|
||||||
|
|
||||||
|
@ -429,14 +424,13 @@ class MetadataTestCase(support.TempdirManager,
|
||||||
"requires_dist": ['foo']}
|
"requires_dist": ['foo']}
|
||||||
|
|
||||||
dist = Distribution(attrs)
|
dist = Distribution(attrs)
|
||||||
metadata = dist.metadata
|
|
||||||
|
|
||||||
# write it then reloads it
|
|
||||||
PKG_INFO = io.StringIO()
|
PKG_INFO = io.StringIO()
|
||||||
metadata.write_file(PKG_INFO)
|
dist.metadata.write_file(PKG_INFO)
|
||||||
PKG_INFO.seek(0)
|
PKG_INFO.seek(0)
|
||||||
|
|
||||||
|
metadata = Metadata()
|
||||||
metadata.read_file(PKG_INFO)
|
metadata.read_file(PKG_INFO)
|
||||||
|
|
||||||
self.assertEqual(metadata['name'], "package")
|
self.assertEqual(metadata['name'], "package")
|
||||||
self.assertEqual(metadata['version'], "1.0")
|
self.assertEqual(metadata['version'], "1.0")
|
||||||
self.assertEqual(metadata['summary'], "xxx")
|
self.assertEqual(metadata['summary'], "xxx")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue