Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Add a "simple" test case to verify the mean() good behavior #141

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
49 changes: 48 additions & 1 deletion tests/influxdb/client_test_with_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

"""

from __future__ import print_function
from __future__ import print_function, division

import datetime
import distutils.spawn
from functools import partial
import os
import re
import shutil
Expand Down Expand Up @@ -68,6 +69,17 @@
print(version, file=sys.stderr)


def point(serie, tags=None, timestamp=None, **fields):
res = {}
res['name'] = serie
if tags:
res['tags'] = tags
if timestamp:
res['timestamp'] = timestamp
res['fields'] = fields
return res


dummy_point = [ # some dummy points
{
"name": "cpu_load_short",
Expand Down Expand Up @@ -517,6 +529,41 @@ def test_create_retention_policy(self):
rsp
)

def test_mean_simple_1(self):
# test mean() function
cli = self.cli
cpu = partial(point, 'cpu')

pts = [
cpu(value=10),
cpu(value=30, tags={'host': 'srv1'}),
cpu(value=60, tags={'host': 'srv2'}),
cpu(value=90)
]
cli.write_points(pts)
time.sleep(1)
rsp = cli.query('SELECT mean(value) FROM cpu')
self.assertEqual(47.5, # (10+30+60+90) / 4 == 47.5
rsp['cpu'][0]['mean'])

# continue with others points..
pts = [
cpu(value=15),
cpu(value=60, tags={'host': 'srv1'}),
cpu(value=20, tags={'host': 'srv2'}),
cpu(value=90),
cpu(value=30, tags={'host': 'srv3'}),
]
cli.write_points(pts)
time.sleep(1)

rsp = cli.query("SELECT mean(value) FROM cpu WHERE host = 'srv1'")
self.assertEqual(45, rsp['cpu'][0]['mean'])

rsp = cli.query("SELECT mean(value) FROM cpu "
"WHERE host = 'srv1' OR host = 'srv3'")
self.assertEqual(40, rsp['cpu'][0]['mean']) # (30+60+30) / 3 -> 40

############################################################################


Expand Down