-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
87 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for the feedparser component.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Pytest configuration.""" | ||
from pathlib import Path | ||
|
||
import pytest | ||
from pytest import FixtureRequest | ||
|
||
|
||
def get_feeds() -> dict[str, str]: | ||
"""Return dict of feed names and paths.""" | ||
fixtures_path = Path(__file__).parent / "fixtures" | ||
feed_files = [f.name for f in fixtures_path.glob("*.xml")] | ||
feeds = {} | ||
for feed_file in feed_files: | ||
feed_name = feed_file.split("-")[0] | ||
feeds[feed_name] = f"file://{fixtures_path / feed_file}" | ||
return feeds | ||
|
||
|
||
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: | ||
"""Generate tests and fixtures.""" | ||
if "feed_file" in metafunc.fixturenames: | ||
feeds = get_feeds() | ||
metafunc.parametrize( | ||
"feed_file", feeds.values(), ids=feeds.keys(), indirect=True | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def feed_file(request: FixtureRequest) -> Path: | ||
"""Return feed file.""" | ||
return Path(request.param) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
""""Tests the feedparser sensor.""" | ||
|
||
from pathlib import Path | ||
|
||
from custom_components.feedparser.sensor import DEFAULT_SCAN_INTERVAL | ||
from custom_components.feedparser.sensor import FeedParserSensor | ||
from custom_components.feedparser.sensor import DEFAULT_SCAN_INTERVAL, FeedParserSensor | ||
|
||
|
||
def test_update_sensor(): | ||
def test_update_sensor(feed_file: Path) -> None: | ||
"""Test instantiate sensor.""" | ||
fixtures_path = Path(__file__).parent / 'fixtures' | ||
feed_file = next(fixtures_path.glob('nu*')) | ||
feed_sensor = FeedParserSensor( | ||
feed=f'file://{feed_file}', | ||
name="Nu.nl", | ||
date_format='%a, %d %b %Y %H:%M:%S %Z', | ||
feed=f"file://{feed_file}", | ||
name=feed_file.name.split("-")[0], | ||
date_format="%a, %d %b %Y %H:%M:%S %Z", | ||
local_time=False, | ||
show_topn=9999, | ||
inclusions=['image'], | ||
inclusions=["image", "title", "link", "published"], | ||
exclusions=[], | ||
scan_interval=DEFAULT_SCAN_INTERVAL, | ||
) | ||
feed_sensor.update() | ||
assert feed_sensor._entries | ||
# assert that all entries have non-default image |