-
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
24 changed files
with
4,760 additions
and
2 deletions.
There are no files selected for viewing
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,16 @@ | ||
#!/bin/bash | ||
# | ||
# Script to test the integration in local home-assistant | ||
# | ||
# Install home-assistant first with `pip3 install -U homeassisant` | ||
|
||
DIR=$(dirname $0) | ||
|
||
mkdir -p "$DIR/test_hass" | ||
|
||
if [ ! -L "$DIR/test_hass/custom_components" ]; then | ||
# Create symlink from custom_components to hass subdir so it can be tested | ||
(cd "$DIR/test_hass" && ln -s "../custom_components" "custom_components") | ||
fi | ||
|
||
exec python3 -m homeassistant -c test_hass |
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,13 @@ | ||
|
||
logger: | ||
default: warning | ||
logs: | ||
custom_components.feedparser: debug | ||
|
||
# Loads default set of integrations. Do not remove. | ||
default_config: | ||
|
||
http: | ||
server_port: 9123 | ||
|
||
sensor: !include sensors.yaml |
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,32 @@ | ||
"""Pytest configuration.""" | ||
|
||
import pytest | ||
from constants import TEST_FEEDS | ||
from feedsource import FeedSource | ||
from pytest import FixtureRequest | ||
|
||
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.""" | ||
if "feed" in metafunc.fixturenames: | ||
feeds = get_feeds() | ||
metafunc.parametrize("feed", feeds, ids=[f.name for f in feeds], indirect=True) | ||
|
||
|
||
@pytest.fixture | ||
def feed(request: 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) |
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,58 @@ | ||
"""Constants for tests.""" | ||
from pathlib import Path | ||
|
||
TESTS_PATH = Path(__file__).parent | ||
DATA_PATH = TESTS_PATH / "data" | ||
TEST_HASS_PATH = Path(__file__).parents[1] / "test_hass" | ||
|
||
TEST_FEEDS = [ | ||
{ | ||
"has_images": True, | ||
"sensor_config": { | ||
"name": "CTK", | ||
"feed_url": "https://www.ceskenoviny.cz/sluzby/rss/cr.php", | ||
"scan_interval": {"hours": 1, "minutes": 30}, | ||
}, | ||
}, | ||
{ | ||
"has_images": True, | ||
"sensor_config": { | ||
"name": "nu_nl", | ||
"feed_url": "https://www.nu.nl/rss", | ||
}, | ||
}, | ||
{ | ||
"has_images": True, | ||
"sensor_config": { | ||
"name": "nu_nl_algemeen", | ||
"feed_url": "https://www.nu.nl/rss/Algemeen", | ||
}, | ||
}, | ||
{ | ||
"has_images": True, | ||
"sensor_config": { | ||
"name": "ct24", | ||
"feed_url": "https://ct24.ceskatelevize.cz/rss/hlavni-zpravy", | ||
}, | ||
}, | ||
{ | ||
"has_images": False, | ||
"sensor_config": { | ||
"name": "bbc_europe", | ||
"feed_url": "http://feeds.bbci.co.uk/news/world/europe/rss.xml", | ||
"date_format": "%a, %d %b %Y %H:%M:%S %z", | ||
}, | ||
}, | ||
{ | ||
"has_images": False, | ||
"sensor_config": { | ||
"name": "zive", | ||
"feed_url": "https://www.zive.cz/rss/sc-47/", | ||
"show_topn": 1, | ||
}, | ||
}, | ||
] | ||
|
||
DEFAULT_EXCLUSIONS: list[str] = [] | ||
DEFAULT_INCLUSIONS = ["image", "title", "link", "published"] | ||
DATE_FORMAT = "%a, %d %b %Y %H:%M:%S UTC%z" |
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,12 @@ | ||
{ | ||
"has_images": true, | ||
"sensor_config": { | ||
"name": "CTK", | ||
"feed_url": "https://www.ceskenoviny.cz/sluzby/rss/cr.php", | ||
"scan_interval": { | ||
"hours": 1, | ||
"minutes": 30 | ||
} | ||
}, | ||
"download_date": "2023-07-30T13:48:50.563494" | ||
} |
Oops, something went wrong.