aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/DataStructures.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze.test/DataStructures.py')
-rw-r--r--src/argaze.test/DataStructures.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/argaze.test/DataStructures.py b/src/argaze.test/DataStructures.py
index 5f0a4ac..c1b78d5 100644
--- a/src/argaze.test/DataStructures.py
+++ b/src/argaze.test/DataStructures.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import unittest
+from dataclasses import dataclass, field
from argaze import DataStructures
@@ -27,6 +28,12 @@ def random_data_buffer(size, data_keys):
return ts_buffer
+@dataclass()
+class BasicDataClass():
+ """Define a basic dataclass for testing purpose."""
+
+ value: tuple
+
class TestTimeStampedBufferClass(unittest.TestCase):
"""Test TimeStampedBuffer class."""
@@ -56,12 +63,17 @@ class TestTimeStampedBufferClass(unittest.TestCase):
DataStructures.TimeStampedBuffer({"first": ""})
- def test_str(self):
+ def test___repr__(self):
"""Test TimeStampedBuffer string representation."""
- self.assertEqual(str(DataStructures.TimeStampedBuffer()), "{}")
- self.assertEqual(str(DataStructures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
- self.assertEqual(str(DataStructures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
+ self.assertEqual(repr(DataStructures.TimeStampedBuffer()), "{}")
+ self.assertEqual(repr(DataStructures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
+ self.assertEqual(repr(DataStructures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
+
+ data = BasicDataClass((123, 456))
+ ts_buffer = DataStructures.TimeStampedBuffer({0: data})
+
+ self.assertEqual(repr(ts_buffer), "{\"0\": {\"value\": [123, 456]}}")
def test_append(self):
"""Test TimeStampedBuffer append method."""
@@ -170,6 +182,11 @@ class TestTimeStampedBufferClass(unittest.TestCase):
self.assertEqual(ts_buffer_dataframe.columns[1], "data_B")
self.assertEqual(ts_buffer_dataframe.columns[2], "data_C")
+ self.assertEqual(ts_buffer_dataframe.index.dtype, 'float64')
+ self.assertEqual(ts_buffer_dataframe["data_A"].dtype, 'object')
+ self.assertEqual(ts_buffer_dataframe["data_B"].dtype, 'object')
+ self.assertEqual(ts_buffer_dataframe["data_C"].dtype, 'object')
+
# Check data exclusion option
ts_buffer_dataframe = ts_buffer.as_dataframe(exclude=["data_B"])
@@ -192,6 +209,16 @@ class TestTimeStampedBufferClass(unittest.TestCase):
self.assertEqual(ts_buffer_dataframe.columns[2], "data_B1")
self.assertEqual(ts_buffer_dataframe.columns[3], "data_C")
+ # Check dataframe conversion with dataclass
+ data = BasicDataClass((123, 456))
+ ts_buffer_dataframe = DataStructures.TimeStampedBuffer({0: data}).as_dataframe()
+
+ self.assertEqual(ts_buffer_dataframe.index.name, "timestamp")
+ self.assertEqual(ts_buffer_dataframe.index.size, 1)
+
+ self.assertEqual(ts_buffer_dataframe.columns.size, 1)
+ self.assertEqual(ts_buffer_dataframe.columns[0], "value")
+
if __name__ == '__main__':
unittest.main() \ No newline at end of file