mirror of https://github.com/scrapy/scrapy.git
fixed import error (thanks Shane) and added some basic tests for ScrapedItem
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40913
This commit is contained in:
parent
934535740b
commit
987ceb540e
|
|
@ -14,7 +14,7 @@ class ScrapedItem(object):
|
|||
for attr, value in data.iteritems():
|
||||
setattr(self, attr, value)
|
||||
elif data is not None:
|
||||
raise UsageError("Initialize with dict, not %s" % data.__class__.__name__)
|
||||
raise TypeError("Initialize with dict, not %s" % data.__class__.__name__)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
import unittest
|
||||
|
||||
from scrapy.item import ScrapedItem
|
||||
|
||||
class ItemTestCase(unittest.TestCase):
|
||||
|
||||
def test_item(self):
|
||||
|
||||
class MyItem(ScrapedItem):
|
||||
pass
|
||||
|
||||
item = MyItem()
|
||||
self.assertEqual(repr(item), 'MyItem({})')
|
||||
|
||||
item = ScrapedItem({'key': 'value'})
|
||||
self.assertEqual(item.key, 'value')
|
||||
|
||||
self.assertRaises(TypeError, ScrapedItem, 10)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue