-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathconftest.py
53 lines (41 loc) · 1.51 KB
/
conftest.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Pytest configuration."""
import pytest
from constants import TEST_FEEDS
from feedsource import FeedSource
from custom_components.feedparser.sensor import FeedParserSensor
def get_feeds() -> list[FeedSource]:
"""Return list of feeds represented by FeedSource objects."""
return [FeedSource(feed) for feed in TEST_FEEDS]
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
"""Generate tests and fixtures."""
feeds = get_feeds()
if "feed" in metafunc.fixturenames:
metafunc.parametrize("feed", feeds, ids=[f.name for f in feeds], indirect=True)
if "feed_with_image_in_summary" in metafunc.fixturenames:
feeds_with_image_in_summary = [
pytest.param(
feed,
id=feed.name,
)
for feed in feeds
if feed.has_images_in_summary
]
metafunc.parametrize(
"feed_with_image_in_summary",
feeds_with_image_in_summary,
indirect=True,
)
@pytest.fixture()
def feed(request: pytest.FixtureRequest) -> FeedSource:
"""Return feed file source."""
return request.param
@pytest.fixture()
def feed_sensor(feed: FeedSource) -> FeedParserSensor:
"""Return feed sensor initialized with the local RSS feed."""
return FeedParserSensor(**feed.sensor_config_local_feed)
@pytest.fixture()
def feed_with_image_in_summary(
request: pytest.FixtureRequest,
) -> FeedSource:
"""Return feed sensor with images in summary of its entries."""
return request.param