File: test_scraper.py

package info (click to toggle)
dosage 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: python: 12,703; sh: 55; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 1,060 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
32
33
34
# SPDX-License-Identifier: MIT
# Copyright (C) 2013-2014 Bastian Kleineidam
# Copyright (C) 2015-2022 Tobias Gruetzmacher
from pathlib import Path

import pytest

from dosagelib.scraper import scrapers


class TestScraper(object):
    """Test scraper module functions."""

    def test_get_scrapers(self):
        for scraperobj in scrapers.all():
            scraperobj.indexes = ["bla"]
            assert scraperobj.url, "missing url in %s" % scraperobj.name

    def test_find_scrapers_single(self):
        assert scrapers.find("xkcd")

    def test_find_scrapers_multi(self):
        with pytest.raises(ValueError, match='multiple comics found'):
            scrapers.find("a")

    def test_find_scrapers_error(self):
        with pytest.raises(ValueError, match='empty comic name'):
            scrapers.find('')

    def test_user_dir(self):
        oldlen = len(scrapers.all())
        scrapers.adddir(Path(__file__).parent / 'mocks' / 'extra')
        assert len(scrapers.all()) == oldlen + 1
        assert scrapers.find('AnotherDummyTestScraper')