Skip to content

Commit 9ca3941

Browse files
feat: replaced exit with ValueError (#182)
1 parent 1dcb900 commit 9ca3941

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

prometheus_api_client/prometheus_connect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from urllib.parse import urlparse
33
import bz2
44
import os
5-
import sys
65
import json
76
import logging
87
import numpy
@@ -190,7 +189,7 @@ def get_metric_range_data(
190189
end = round(end_time.timestamp())
191190

192191
if (end_time - start_time).total_seconds() < chunk_size.total_seconds():
193-
sys.exit("specified chunk_size is too big")
192+
raise ValueError("specified chunk_size is too big")
194193
chunk_seconds = round(chunk_size.total_seconds())
195194

196195
if label_config:

tests/test_prometheus_connect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def test_get_metric_range_data_with_incorrect_input_types(self): # noqa D102
8888
chunk_size = timedelta(minutes=7)
8989
end_time = datetime.now() - timedelta(minutes=10)
9090

91+
with self.assertRaises(ValueError, msg="specified chunk_size is too big"):
92+
_ = self.pc.get_metric_range_data(
93+
metric_name="up",
94+
start_time=start_time,
95+
end_time=end_time,
96+
chunk_size=timedelta(minutes=30),
97+
)
9198
with self.assertRaises(TypeError, msg="start_time accepted invalid value type"):
9299
_ = self.pc.get_metric_range_data(
93100
metric_name="up", start_time="20m", end_time=end_time, chunk_size=chunk_size

0 commit comments

Comments
 (0)