Commit 6bbd7753 authored by Éric Araujo's avatar Éric Araujo

Consolidate tests for packaging.metadata.

New tests were added in test_metadata and old tests inherited from
distutils were still in test_dist, so I moved them into test_metadata
(except for one which was more at home in test_run) and merged
duplicates.

I also added some skips to lure contributors <wink>, optimized the
Metadata.update method a trifle, and added notes about a number of
issues.

A note: The tests in test_dist used to dump the Metadata objects to a
file in the METADATA format and look for strings in its contents; I
updated them to use the mapping API of Metadata instead.  For some
fields with special writing rules, I have added tests to ensure my
conversion did not lose anything.
parent 92ffc500
......@@ -354,11 +354,20 @@ class Metadata:
Keys that don't match a metadata field or that have an empty value are
dropped.
"""
# XXX the code should just use self.set, which does tbe same checks and
# conversions already, but that would break packaging.pypi: it uses the
# update method, which does not call _set_best_version (which set
# does), and thus allows having a Metadata object (as long as you don't
# modify or write it) with extra fields from PyPI that are not fields
# defined in Metadata PEPs. to solve it, the best_version system
# should be reworked so that it's called only for writing, or in a new
# strict mode, or with a new, more lax Metadata subclass in p7g.pypi
def _set(key, value):
if key in _ATTR2FIELD and value:
self.set(self._convert_name(key), value)
if other is None:
if not other:
# other is None or empty container
pass
elif hasattr(other, 'keys'):
for k in other.keys():
......@@ -368,7 +377,8 @@ class Metadata:
_set(k, v)
if kwargs:
self.update(kwargs)
for k, v in kwargs.items():
_set(k, v)
def set(self, name, value):
"""Control then set a metadata field."""
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,16 +3,16 @@
import os
import sys
import shutil
from tempfile import mkstemp
from io import StringIO
from packaging import install
from packaging.tests import unittest, support, TESTFN
from packaging.run import main
from test.script_helper import assert_python_ok
# setup script that uses __file__
setup_using___file__ = """\
__file__
from packaging.run import setup
......@@ -20,7 +20,6 @@ setup()
"""
setup_prints_cwd = """\
import os
print os.getcwd()
......@@ -29,11 +28,12 @@ setup()
"""
class CoreTestCase(support.TempdirManager, support.LoggingCatcher,
unittest.TestCase):
class RunTestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
def setUp(self):
super(CoreTestCase, self).setUp()
super(RunTestCase, self).setUp()
self.old_stdout = sys.stdout
self.cleanup_testfn()
self.old_argv = sys.argv, sys.argv[:]
......@@ -43,7 +43,7 @@ class CoreTestCase(support.TempdirManager, support.LoggingCatcher,
self.cleanup_testfn()
sys.argv = self.old_argv[0]
sys.argv[:] = self.old_argv[1]
super(CoreTestCase, self).tearDown()
super(RunTestCase, self).tearDown()
def cleanup_testfn(self):
path = TESTFN
......@@ -77,9 +77,16 @@ class CoreTestCase(support.TempdirManager, support.LoggingCatcher,
os.chmod(install_path, old_mod)
install.get_path = old_get_path
def test_show_help(self):
# smoke test, just makes sure some help is displayed
status, out, err = assert_python_ok('-m', 'packaging.run', '--help')
self.assertEqual(status, 0)
self.assertGreater(out, b'')
self.assertEqual(err, b'')
def test_suite():
return unittest.makeSuite(CoreTestCase)
return unittest.makeSuite(RunTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
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