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.
diff --git a/Lib/packaging/metadata.py b/Lib/packaging/metadata.py
index 104600b..7d7fc6b 100644
--- a/Lib/packaging/metadata.py
+++ b/Lib/packaging/metadata.py
@@ -354,11 +354,20 @@
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 @@
_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."""