summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/metadata.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-09-10 03:18:20 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-09-10 03:18:20 (GMT)
commit6bbd775377ae4a6e87ccce990750ac02afe83573 (patch)
treee794c3ba5ecf0144ff6cd523777f4d774759fbbe /Lib/packaging/metadata.py
parent92ffc500d1b218d533953c8b7a79733902125f9c (diff)
downloadcpython-6bbd775377ae4a6e87ccce990750ac02afe83573.zip
cpython-6bbd775377ae4a6e87ccce990750ac02afe83573.tar.gz
cpython-6bbd775377ae4a6e87ccce990750ac02afe83573.tar.bz2
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.
Diffstat (limited to 'Lib/packaging/metadata.py')
-rw-r--r--Lib/packaging/metadata.py14
1 files changed, 12 insertions, 2 deletions
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 @@ 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."""