def test_fill(): data = Data("cpu.utilization", filter=Filter('app', 'test-app'))\ .fill(value=42, duration="1m")\ .publish(label = 'a') assert data.call_stack[0].name =='fill' assert data.call_stack[0].args == [KWArg("value", 42), KWArg("duration", '1m')]
def test_kpss(): data = Data("cpu.utilization", filter=Filter('app', 'test-app'))\ .kpss(over='1h')\ .publish(label = 'a') assert data.call_stack[0].name == 'kpss' # mode should default to level assert data.call_stack[0].args == [ KWArg("over", '1h'), KWArg("mode", 'level') ] data = Data("cpu.utilization", filter=Filter('app', 'test-app'))\ .kpss(over='2m', mode='trend')\ .publish(label = 'a') # should allow trend assert data.call_stack[0].args == [ KWArg("over", '2m'), KWArg("mode", 'trend') ] try: Data("cpu.utilization", filter=Filter('app', 'test-app'))\ .kpss(over='2m', mode='tr3nd') assert False except ValueError as ve: assert str(ve) == 'kpss mode must be level|trend'
def test_count_percentage_by_methods(): # TODO consider making this test use dynamic fn calls to test all stream # methods with the same signature. data = Data('cpu.utilization', filter=Filter('app', 'test-app'))\ .top(count=3, percentage=22.3, by=["env", "datacenter"])\ .bottom(count=4, percentage=22.4, by=["env", "datacenter"])\ .publish(label='A') assert data.call_stack[0].args == [KWArg("count", 3), KWArg("percentage", 22.3), KWArg("by", ["env", "datacenter"])] assert data.call_stack[1].args == [KWArg("count", 4), KWArg("percentage", 22.4), KWArg("by", ["env", "datacenter"])]
def test_ewma_happy(): data = Data('foo').ewma(1) assert data.call_stack[0].args[0].arg == 1 data = Data('foo').ewma(over='1m') assert data.call_stack[0].args[0] == KWArg("over", '1m')
def test_dimensions_method_happy(): data = Data('bar').dimensions(aliases={'foo': 'baz'}).publish(label='foo') assert data.call_stack[0].args[0] == KWArg("aliases", {'foo': 'baz'}) data = Data('bar').dimensions(renames={'foo': 'baz'}).publish(label='foo') assert data.call_stack[0].args[1] == KWArg("renames", {'foo': 'baz'})