Ejemplo n.º 1
0
    def test_deprecated_is_instance(self):
        from itemadapter.utils import is_scrapy_item

        with warnings.catch_warnings(record=True) as caught:
            is_scrapy_item(1)
            self.assertEqual(len(caught), 1)
            self.assertTrue(issubclass(caught[0].category, DeprecationWarning))
            self.assertEqual(
                "itemadapter.utils.is_scrapy_item is deprecated"
                " and it will be removed in a future version",
                str(caught[0].message),
            )
Ejemplo n.º 2
0
    def test_removed_baseitem(self):
        class MockItemModule:
            Item = ScrapyItem

        with mock.patch("scrapy.item", MockItemModule):
            self.assertFalse(is_scrapy_item(dict()))
Ejemplo n.º 3
0
    def test_deprecated_baseitem(self):
        class SubClassedBaseItem(scrapy.item.BaseItem):
            pass

        self.assertTrue(is_scrapy_item(scrapy.item.BaseItem()))
        self.assertTrue(is_scrapy_item(SubClassedBaseItem()))
Ejemplo n.º 4
0
 def test_true(self):
     self.assertTrue(is_scrapy_item(ScrapyItem()))
     self.assertTrue(is_scrapy_item(ScrapySubclassedItem()))
     self.assertTrue(
         is_scrapy_item(ScrapySubclassedItem(name="asdf", value=1234)))
Ejemplo n.º 5
0
 def test_module_not_available(self):
     self.assertFalse(
         is_scrapy_item(ScrapySubclassedItem(name="asdf", value=1234)))
Ejemplo n.º 6
0
 def test_false(self):
     self.assertFalse(is_scrapy_item(int))
     self.assertFalse(is_scrapy_item(sum))
     self.assertFalse(is_scrapy_item(1234))
     self.assertFalse(is_scrapy_item(object()))
     self.assertFalse(is_scrapy_item(AttrsItem()))
     self.assertFalse(is_scrapy_item("a string"))
     self.assertFalse(is_scrapy_item(b"some bytes"))
     self.assertFalse(is_scrapy_item({"a": "dict"}))
     self.assertFalse(is_scrapy_item(["a", "list"]))
     self.assertFalse(is_scrapy_item(("a", "tuple")))
     self.assertFalse(is_scrapy_item({"a", "set"}))
     self.assertFalse(is_scrapy_item(ScrapySubclassedItem))
Ejemplo n.º 7
0
 def is_item(cls, item: Any) -> bool:
     return is_scrapy_item(item)