diff options
author | Wolfgang Müller | 2024-03-05 18:08:09 +0100 |
---|---|---|
committer | Wolfgang Müller | 2024-03-05 19:25:59 +0100 |
commit | d1d654ebac2d51e3841675faeb56480e440f622f (patch) | |
tree | 56ef123c1a15a10dfd90836e4038e27efde950c6 /tests/scrapers/test_scraper.py | |
download | hircine-0.1.0.tar.gz |
Initial commit0.1.0
Diffstat (limited to '')
-rw-r--r-- | tests/scrapers/test_scraper.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/scrapers/test_scraper.py b/tests/scrapers/test_scraper.py new file mode 100644 index 0000000..6f6f29d --- /dev/null +++ b/tests/scrapers/test_scraper.py @@ -0,0 +1,55 @@ +from hircine.scraper import Scraper, ScrapeWarning + + +class MockScraper(Scraper): + is_available = True + + def scrape(self): + yield lambda: "foo" + yield "bar" + + +class WarningScraper(Scraper): + is_available = True + + def warn(self, str): + raise ScrapeWarning("Invalid input") + + def scrape(self): + yield lambda: "foo" + yield lambda: self.warn("bar") + yield "baz" + + +class ParserlessScraper(Scraper): + is_available = True + + def scrape(self): + yield "literal" + + +def test_scraper_collects(): + generator = MockScraper(None).collect() + + assert set(generator) == set(["foo", "bar"]) + + +def test_scraper_collects_with_transformer(): + generator = MockScraper(None).collect([lambda gen, info: map(str.upper, gen)]) + + assert set(generator) == set(["FOO", "BAR"]) + + +def test_scraper_collects_warnings(): + scraper = WarningScraper(None) + generator = scraper.collect() + + assert set(generator) == set(["foo", "baz"]) + assert scraper.get_warnings() == ["Invalid input"] + + +def test_scraper_collects_literal(): + scraper = ParserlessScraper(None) + generator = scraper.collect() + + assert set(generator) == set(["literal"]) |