python: fix tests

This commit is contained in:
nym21
2026-03-23 16:35:24 +01:00
parent f495451b34
commit a59cdfef7c
3 changed files with 67 additions and 59 deletions

View File

@@ -6,8 +6,8 @@
from brk_client import BrkClient
def is_metric_pattern(obj):
"""Check if an object is a metric pattern (has indexes() method and by attribute)."""
def is_series_pattern(obj):
"""Check if an object is a series pattern (has indexes() method and by attribute)."""
return (
hasattr(obj, "indexes")
and callable(getattr(obj, "indexes", None))
@@ -15,9 +15,9 @@ def is_metric_pattern(obj):
)
def get_all_metrics(obj, path=""):
"""Recursively collect all MetricPattern instances from the tree."""
metrics = []
def get_all_series(obj, path=""):
"""Recursively collect all SeriesPattern instances from the tree."""
series = []
for attr_name in dir(obj):
# Skip dunder methods and internal attributes (_letter), but allow _digit (e.g., _10y, _2017)
@@ -36,43 +36,43 @@ def get_all_metrics(obj, path=""):
current_path = f"{path}.{attr_name}" if path else attr_name
# Check if this is a metric pattern using the indexes() method
if is_metric_pattern(attr):
metrics.append((current_path, attr))
# Check if this is a series pattern using the indexes() method
if is_series_pattern(attr):
series.append((current_path, attr))
# Recurse into nested tree nodes
if hasattr(attr, "__dict__"):
metrics.extend(get_all_metrics(attr, current_path))
series.extend(get_all_series(attr, current_path))
return metrics
return series
def test_all_endpoints():
"""Test fetching last value from all metric endpoints."""
"""Test fetching last value from all series endpoints."""
client = BrkClient("http://localhost:3110")
metrics = get_all_metrics(client.metrics)
print(f"\nFound {len(metrics)} metrics")
series = get_all_series(client.series)
print(f"\nFound {len(series)} series")
success = 0
for path, metric in metrics:
for path, s in series:
# Use the indexes() method to get all available indexes
indexes = metric.indexes()
indexes = s.indexes()
for idx_name in indexes:
full_path = f"{path}.by.{idx_name}"
try:
# Verify both access methods work: .by.index() and .get(index)
by = metric.by
by = s.by
endpoint_by_property = getattr(by, idx_name)()
endpoint_by_get = metric.get(idx_name)
endpoint_by_get = s.get(idx_name)
if endpoint_by_property is None:
raise Exception(f"metric.by.{idx_name}() returned None")
raise Exception(f"series.by.{idx_name}() returned None")
if endpoint_by_get is None:
raise Exception(f"metric.get('{idx_name}') returned None")
raise Exception(f"series.get('{idx_name}') returned None")
endpoint_by_property.tail(1).fetch()
success += 1