def test_detector_with_assign_combinator(): """ We should correctly generate a detector comprised of two assignment functions """ cpu_util_string = 'cpu.utilization' sum_string = 'utilization_sum' count_string = 'utilization_count' mean_string = 'utilization_mean' sum_data = Data(cpu_util_string).sum() count_data = Data(cpu_util_string).count() utilization_sum = Assign(sum_string, sum_data) utilization_count = Assign(count_string, count_data) mean_data = Div(Ref(sum_string), Ref(count_string)) utilization_mean = Assign(mean_string, mean_data) detect = Detect(When(GT(Ref(mean_string), 50))).publish(label='detector') program = Program(utilization_sum, utilization_count, utilization_mean, detect) detector = Detector().with_program(program) assert detector.options["programText"] == "{0}\n{1}\n{2}\n{3}".format( str(utilization_sum), str(utilization_count), str(utilization_mean), str(detect)) assert program.statements.pop() == detect assert program.statements.pop() == utilization_mean assert program.statements.pop() == utilization_count assert program.statements.pop() == utilization_sum
def test_assign(assignee, expr): """Assign.__str__ should always return a string matching assignee = expr.""" assert str(Assign(assignee, expr)) == \ "{0} = {1}".format(str(assignee), str(expr))
def test_valid_publish_statements_assign_invalid(): with pytest.raises(ProgramDoesNotPublishTimeseriesError): Program( Assign('A', Data('foo')) ).validate()
def test_valid_publish_statements_assign_happy(): Program( Assign('A', Data('foo').publish(label='lol')) ).validate()