diff options
| author | ?ric Araujo <merwok@netwok.org> | 2010-08-12 19:46:39 +0200 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2010-08-12 19:46:39 +0200 |
| commit | 8693f3e6bfa1eb47fbb501fef414d03fc9134c34 (patch) | |
| tree | eaff8521449d5a35a8ac2b9998de81f4ff181815 /src/distutils2 | |
| parent | 87eae65d05db3b6ed3e6e4f97e0fa9fd3dc4d9e7 (diff) | |
| download | disutils2-8693f3e6bfa1eb47fbb501fef414d03fc9134c34.tar.gz | |
Fix DistributionMetadata.update
Diffstat (limited to 'src/distutils2')
| -rw-r--r-- | src/distutils2/metadata.py | 24 | ||||
| -rw-r--r-- | src/distutils2/tests/test_metadata.py | 6 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py index ed80fac..5fa1d88 100644 --- a/src/distutils2/metadata.py +++ b/src/distutils2/metadata.py @@ -336,34 +336,28 @@ class DistributionMetadata(object): self._write_field(fileobject, field, value) def update(self, other=None, **kwargs): - """Set metadata values from the given mapping + """Set metadata values from the given iterable `other` and kwargs. - Convert the keys to Metadata fields. Given keys that don't match a - metadata argument will not be used. + Behavior is like `dict.update`: If `other` has a ``keys`` method, + they are looped over and ``self[key]`` is assigned ``other[key]``. + Else, ``other`` is an iterable of ``(key, value)`` iterables. - If overwrite is set to False, just add metadata values that are - actually not defined. - - If there is existing values in conflict with the dictionary ones, the - new values prevails. - - Empty values (e.g. None and []) are not setted this way. + Keys that don't match a metadata field or that have an empty value are + dropped. """ def _set(key, value): - if value not in ([], None, '') and key in _ATTR2FIELD: + if key in _ATTR2FIELD and value: self.set(self._convert_name(key), value) if other is None: pass - elif hasattr(other, 'iteritems'): # iteritems saves memory and lookups - for k, v in other.iteritems(): - _set(k, v) elif hasattr(other, 'keys'): for k in other.keys(): - _set(k, v) + _set(k, other[k]) else: for k, v in other: _set(k, v) + if kwargs: self.update(kwargs) diff --git a/src/distutils2/tests/test_metadata.py b/src/distutils2/tests/test_metadata.py index e7e8d68..49a4757 100644 --- a/src/distutils2/tests/test_metadata.py +++ b/src/distutils2/tests/test_metadata.py @@ -152,7 +152,11 @@ class DistributionMetadataTestCase(LoggingSilencer, unittest.TestCase): self.assertIn('Version', metadata.keys()) self.assertIn('0.5', metadata.values()) self.assertIn(('Version', '0.5'), metadata.items()) - #TODO test update + + metadata.update({'version': '0.6'}) + self.assertEqual(metadata['Version'], '0.6') + metadata.update([('version', '0.7')]) + self.assertEqual(metadata['Version'], '0.7') def test_versions(self): metadata = DistributionMetadata() |
