-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
61 lines (43 loc) · 1.77 KB
/
test_basic.py
File metadata and controls
61 lines (43 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Basic tests for plexus-python."""
import time
from plexus import __version__
from plexus.client import Plexus
from plexus.config import DEFAULT_CONFIG
def test_version():
"""Version should be a string."""
assert isinstance(__version__, str)
assert len(__version__) > 0
def test_default_config():
"""Default config should have expected keys."""
assert "api_key" in DEFAULT_CONFIG
assert "source_id" in DEFAULT_CONFIG
def test_client_init():
"""Client should initialize without error."""
px = Plexus(api_key="test_key", endpoint="http://localhost")
assert px.api_key == "test_key"
assert px.endpoint == "http://localhost"
def test_make_point():
"""Client should create valid data points."""
px = Plexus(api_key="test", endpoint="http://localhost")
point = px._make_point("temperature", 72.5)
assert point["metric"] == "temperature"
assert point["value"] == 72.5
assert "timestamp" in point
assert "source_id" not in point
def test_make_point_with_tags():
"""Data points should include tags when provided."""
px = Plexus(api_key="test", endpoint="http://localhost")
point = px._make_point("temperature", 72.5, tags={"sensor": "A1"})
assert point["tags"] == {"sensor": "A1"}
def test_normalize_ts_ms_applies_clock_offset():
px = Plexus(api_key="test", endpoint="http://localhost")
px._clock_offset_ms = 5000
before = int(time.time() * 1000)
ts = px._normalize_ts_ms(None)
after = int(time.time() * 1000)
assert before + 5000 <= ts <= after + 5000
def test_normalize_ts_ms_ignores_offset_for_supplied_timestamp():
px = Plexus(api_key="test", endpoint="http://localhost")
px._clock_offset_ms = 5000
ts = px._normalize_ts_ms(1_700_000_000.0)
assert ts == 1_700_000_000_000