Skip to content

Commit 90f03bd

Browse files
adds unit property to Stream [ch1579]
1 parent 3145d26 commit 90f03bd

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

btrdb/stream.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ def name(self):
179179
"""
180180
return self.tags()["name"]
181181

182+
@property
183+
def unit(self):
184+
"""
185+
Returns the stream's unit which is parsed from the stream tags. This
186+
may require a round trip to the server depending on how the stream was
187+
acquired.
188+
189+
Returns
190+
-------
191+
str
192+
The unit for values of the stream.
193+
194+
"""
195+
return self.tags()["unit"]
196+
182197
@property
183198
def collection(self):
184199
"""

tests/btrdb/test_stream.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ def test_refresh_metadata_deserializes_annotations(self):
126126
assert stream.annotations()[0] == expected
127127

128128

129+
def test_stream_name_property(self):
130+
"""
131+
Assert name property comes from tags
132+
"""
133+
name = "LINE222VA-ANG"
134+
stream = Stream(None, "FAKE_UUID")
135+
stream._tags = {"name": name}
136+
assert stream.name == name
137+
138+
139+
def test_stream_unit_property(self):
140+
"""
141+
Assert unit property comes from tags
142+
"""
143+
unit = "whales"
144+
stream = Stream(None, "FAKE_UUID")
145+
stream._tags = {"unit": unit}
146+
assert stream.unit == unit
147+
148+
129149
##########################################################################
130150
## update tests
131151
##########################################################################

0 commit comments

Comments
 (0)