Skip to content

Commit 75b6e48

Browse files
author
aviau
committed
ResultSet: added as_dict()
1 parent 922a0a5 commit 75b6e48

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

influxdb/point.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ def __eq__(self, other):
6969

7070
def __ne__(self, other):
7171
return not self.__eq__(other)
72+
73+
def as_dict(self):
74+
return {
75+
"serie": self.serie,
76+
"point": [{col: getattr(self.values, col)} for col in self.columns]
77+
}

tests/influxdb/point_test.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77

88
class TestPoint(unittest.TestCase):
9-
10-
def test_point(self):
11-
point = Point(
9+
def setUp(self):
10+
self.point = Point(
1211
"serie_name",
1312
['col1', 'col2'],
1413
[1, '2'],
@@ -18,12 +17,13 @@ def test_point(self):
1817
}
1918
)
2019

21-
self.assertEqual(point.columns, ['col1', 'col2'])
22-
self.assertEqual(point.tags, {"SWAG": True, "ALLO": "BYE"})
23-
self.assertEqual(point.values.col1, 1)
24-
self.assertEqual(point.values.col2, '2')
20+
def test_point(self):
21+
self.assertEqual(self.point.columns, ['col1', 'col2'])
22+
self.assertEqual(self.point.tags, {"SWAG": True, "ALLO": "BYE"})
23+
self.assertEqual(self.point.values.col1, 1)
24+
self.assertEqual(self.point.values.col2, '2')
2525
self.assertEqual(
26-
str(point),
26+
str(self.point),
2727
"Point(values=(col1=1, col2='2'),"
2828
" tags={'ALLO': 'BYE', 'SWAG': True})"
2929
)
@@ -36,3 +36,9 @@ def test_point_eq(self):
3636
tags={"SWAG": True, "ALLO": "BYE"})
3737

3838
self.assertEqual(point1, point2)
39+
40+
def test_as_dict(self):
41+
self.assertEqual(
42+
self.point.as_dict(),
43+
{'point': [{'col1': 1}, {'col2': '2'}], 'serie': 'serie_name'}
44+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy