Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Add gap_detection attribute to Stream and allow extra attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Derrett committed Jul 5, 2016
1 parent 133d5b8 commit ce523d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions librato/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ def __init__(self, metric=None, source='*', composite=None,
name=None, type=None, id=None,
group_function=None, summary_function=None,
transform_function=None, downsample_function=None,
period=None, split_axis=None,
period=None, split_axis=None, gap_detection=None,
min=None, max=None,
units_short=None, units_long=None, color=None,
# deprecated
composite_function=None
composite_function=None, **kwargs
):
self.metric = metric
self.source = source
Expand All @@ -30,6 +30,11 @@ def __init__(self, metric=None, source='*', composite=None,
self.units_short = units_short
self.units_long = units_long
self.color = color
self.gap_detection = gap_detection

# Pick up any attributes that are not explicitly defined
for attr in kwargs:
setattr(self, attr, kwargs[attr])

# Can't have a composite and source/metric
if self.composite:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ def test_init_units(self):
self.assertEqual(Stream(units_short='req/s').units_short, 'req/s')
self.assertEqual(Stream(units_long='requests per second').units_long, 'requests per second')

def test_init_color(self):
self.assertIsNone(Stream().color)
self.assertEqual(Stream(color='#f00').color, '#f00')

def test_init_gap_detection(self):
self.assertIsNone(Stream().gap_detection)
self.assertTrue(Stream(gap_detection=True).gap_detection)
self.assertFalse(Stream(gap_detection=False).gap_detection)

# Adding this to avoid exceptions raised due to unknown Stream attributes
def test_init_with_extra_attributes(self):
attrs = {"color": "#f00", "something": "foo"}
s = Stream(**attrs)
# color is a known attribute
self.assertEqual(s.color, '#f00')
self.assertEqual(s.something, 'foo')


def test_get_payload(self):
self.assertEqual(Stream(metric='my.metric').get_payload(),
{'metric': 'my.metric', 'source': '*'})
Expand Down

0 comments on commit ce523d7

Please sign in to comment.