From 3ca2187e3b0103b447542e45d03be2356884f2fd Mon Sep 17 00:00:00 2001 From: elpolilla Date: Thu, 29 Jan 2009 02:21:08 +0000 Subject: [PATCH] Removed non-generic implementation of _add_single_attributes and modified test --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40791 --- scrapy/trunk/scrapy/contrib/item/models.py | 10 ++-------- scrapy/trunk/scrapy/tests/test_robustscrapeditem.py | 4 +--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/scrapy/trunk/scrapy/contrib/item/models.py b/scrapy/trunk/scrapy/contrib/item/models.py index a5be1a1c8..521504071 100644 --- a/scrapy/trunk/scrapy/contrib/item/models.py +++ b/scrapy/trunk/scrapy/contrib/item/models.py @@ -111,13 +111,7 @@ class RobustScrapedItem(ScrapedItem): return "%s: GUID=%s, url=%s" % ( self.__class__.__name__ , self.guid, self.url ) def _add_single_attributes(self, attrname, attrtype, attributes): - if len(attributes) == 1: - return attributes[0] - - if attrtype is basestring: - return ''.join(attributes) - else: - raise NotImplementedError('You must override _add_single_attributes method in order to join %s values into a single value.' % attrtype.__name__) + raise NotImplementedError('You must override _add_single_attributes method in order to join %s values into a single value.' % attrtype.__name__) def attribute(self, attrname, *values, **kwargs): """ @@ -171,7 +165,7 @@ class RobustScrapedItem(ScrapedItem): new_values.insert(0, old_value) if not multivalued: - if add and len(new_values) >= 1: + if add and len(new_values) > 1: new_values = self._add_single_attributes(attrname, attrtype, new_values) else: new_values = new_values[0] if new_values else None diff --git a/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py b/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py index 184e3323b..8f770cc1d 100644 --- a/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py +++ b/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py @@ -46,9 +46,7 @@ class RobustScrapedItemTestCase(unittest.TestCase): def test_attribute_add(self): self.item.attribute('name', 'John') - - self.item.attribute('name', 'Doe', add=True) - self.assertEqual(self.item.name, 'JohnDoe') + self.assertRaises(NotImplementedError, self.item.attribute, 'name', 'Doe', add=True) self.item.attribute('children', *['Ken', 'Tom']) self.item.attribute('children', 'Bobby')