File: test_exceptions.py

package info (click to toggle)
python-recipe-scrapers 15.9.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 246,580 kB
  • sloc: python: 13,214; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import unittest

from recipe_scrapers import (
    AbstractScraper,
    NoSchemaFoundInWildMode,
    RecipeSchemaNotFound,
    WebsiteNotImplementedError,
    scrape_html,
)


class TestExceptions(unittest.TestCase):
    def test_website_not_implemented_error(self):
        with self.assertRaises(WebsiteNotImplementedError):
            scrape_html(html="<html></html>", org_url="http://example.com/recipe")

    def test_no_schema_found_in_wild_mode_error(self):
        exception = NoSchemaFoundInWildMode("example.com")

        self.assertEqual(exception.url, "example.com")
        self.assertEqual(exception.message, "No Recipe Schema found at example.com.")

    def test_no_schema_found_for_fill_plugin(self):
        class TestScraper(AbstractScraper):
            @classmethod
            def host(cls):
                return "example.com"

        scraper = TestScraper(html="<html></html>", url="http://example.com/recipe")
        with self.assertRaises(RecipeSchemaNotFound):
            scraper.category()