Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_format_metrics_time_series datetime failure #72

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions tests/test_formater_influxdb.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from datetime import datetime, timedelta
from formatters.influxdb_formatter import MetricsInfluxdbFormatter
from metrics.metrics_result import MetricsResults, MetricsTimeSeries
import pytz


def test_format_metrics_results():
date = datetime.now()
metrics = MetricsResults(data={"v1": 1, "v2": 1, "v3": 2}, metadata={"project": 1}, date=date)
metrics = MetricsResults(data={"v1": 1, "v2": 1, "v3": 2},
metadata={"project": 1},
date=date)
lines = MetricsInfluxdbFormatter.format("test", metrics)
assert lines[0] == f"test,project=1 v1=1,v2=1,v3=2 {int(date.timestamp() * 1e9)}"
date_as_e9 = int(date.timestamp() * 1e9)
assert lines[0] == f"test,project=1 v1=1,v2=1,v3=2 {date_as_e9}"


def test_format_metrics_time_series():
date1 = datetime.now()
date1 = datetime.now(tz=pytz.UTC)
date2 = date1 + timedelta(days=1)
metrics_time_series = MetricsTimeSeries()

Expand All @@ -22,15 +26,18 @@ def test_format_metrics_time_series():
{"date": date2, "v1": 2, "v2": 2, "v3": 3},
]
)

lines = MetricsInfluxdbFormatter.format("test", metrics_time_series)
assert lines[0] == f"test,project=containers v1=1,v2=1,v3=2 {int(date1.timestamp() * 1e9)}"
assert lines[1] == f"test,project=containers v1=2,v2=2,v3=3 {int(date2.timestamp() * 1e9)}"
date1_as_e9 = int(date1.timestamp() * 1e9)
date2_as_e9 = int(date2.timestamp() * 1e9)
assert lines[0] == f"test,project=containers v1=1,v2=1,v3=2 {date1_as_e9}"
assert lines[1] == f"test,project=containers v1=2,v2=2,v3=3 {date2_as_e9}"


def test_print_metrics_results(capsys):
date = datetime.now()
metrics = MetricsResults(data={"v1": 1, "v2": 1, "v3": 2}, metadata={"project": 1}, date=date)
metrics = MetricsResults(data={"v1": 1, "v2": 1, "v3": 2},
metadata={"project": 1},
date=date)
MetricsInfluxdbFormatter.print("test", metrics)

captured = capsys.readouterr()
Expand Down