Changeset View
Changeset View
Standalone View
Standalone View
swh/counters/tests/test_init.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import inspect | import inspect | ||||
import pytest | import pytest | ||||
from swh.counters import get_counters | from swh.counters import get_counters, get_history | ||||
from swh.counters.api.client import RemoteCounters | from swh.counters.api.client import RemoteCounters | ||||
from swh.counters.history import History | |||||
from swh.counters.interface import CountersInterface | from swh.counters.interface import CountersInterface | ||||
from swh.counters.redis import Redis | from swh.counters.redis import Redis | ||||
COUNTERS_IMPLEMENTATIONS = [ | COUNTERS_IMPLEMENTATIONS = [ | ||||
("remote", RemoteCounters, {"url": "localhost"}), | ("remote", RemoteCounters, {"url": "localhost"}), | ||||
("redis", Redis, {"host": "localhost"}), | ("redis", Redis, {"host": "localhost"}), | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | for meth_name in dir(interface): | ||||
continue | continue | ||||
expected_signature = inspect.signature(interface_meth) | expected_signature = inspect.signature(interface_meth) | ||||
actual_signature = inspect.signature(concrete_meth) | actual_signature = inspect.signature(concrete_meth) | ||||
assert expected_signature == actual_signature, meth_name | assert expected_signature == actual_signature, meth_name | ||||
assert missing_methods == [] | assert missing_methods == [] | ||||
def test_get_history_failure(): | |||||
with pytest.raises(ValueError, match="Unknown history class"): | |||||
get_history("unknown-history") | |||||
def test_get_history(): | |||||
concrete_history = get_history( | |||||
"prometheus", | |||||
**{ | |||||
"prometheus_host": "", | |||||
"prometheus_port": "", | |||||
"live_data_start": "", | |||||
"cache_base_directory": "", | |||||
}, | |||||
) | |||||
assert isinstance(concrete_history, History) |