def test_configure(self):
        class TestOptions(service.OptionsGlue):
            optParameters = [["test", "t", "default", "help"]]
            config_section = "statsd"

        o = TestOptions()
        config_file = ConfigParser.RawConfigParser()
        config_file.readfp(StringIO("[statsd]\n\n[plugin_sli]\n"
            "rules = \n"
            "   test_o-k => red IF below 5\n"
            "   test_o-k => green IF between 0.1 3\n"
            "   other* => red IF above 4\n"))
        o.configure(config_file)
        smf = SLIMetricFactory()
        smf.configure(o)
        smr = smf.build_metric("", "test_o-k")
        rc = smr.conditions["red"]
        self.assertTrue(isinstance(rc, BelowCondition))
        self.assertEquals(rc.value, 5)
        gc = smr.conditions["green"]
        self.assertTrue(isinstance(gc, BetweenCondition))
        self.assertEquals(gc.hi, 3)
        self.assertEquals(gc.low, 0.1)
        smr = smf.build_metric("", "otherXX")
        rc = smr.conditions["red"]
        self.assertTrue(isinstance(rc, AboveCondition))
        self.assertEquals(rc.value, 4)
    def test_configure_linear(self):
        class TestOptions(service.OptionsGlue):
            optParameters = [["test", "t", "default", "help"]]
            config_section = "statsd"

        o = TestOptions()
        config_file = ConfigParser.RawConfigParser()
        config_file.readfp(StringIO("[statsd]\n\n[plugin_sli]\n"
            "rules = \n"
            "   test => red IF below 5 1\n"
            "   test => green IF above 3 1\n"))
        o.configure(config_file)
        smf = SLIMetricFactory()
        smf.configure(o)
        smr = smf.build_metric("", "test")
        rc = smr.conditions["red"]
        self.assertTrue(isinstance(rc, BelowCondition))
        self.assertEquals(rc.value, 5)
        self.assertEquals(rc.slope, 1)
        rc = smr.conditions["green"]
        self.assertTrue(isinstance(rc, AboveCondition))
        self.assertEquals(rc.value, 3)
        self.assertEquals(rc.slope, 1)