# Path: moira/checker/state.py
# OK = "OK"
# WARN = "WARN"
# ERROR = "ERROR"
# NODATA = "NODATA"
# EXCEPTION = "EXCEPTION"
# DEL = "DEL"
# SCORES = {
#     "OK": 0,
#     "DEL": 0,
#     "WARN": 1,
#     "ERROR": 100,
#     "NODATA": 1000,
#     "EXCEPTION": 100000
# }
# def to_metric_state(state):
# 
# Path: moira/checker/expression.py
# DEFAULT = compile(_default, '<string>', mode='eval')
# class ExpressionError(Exception):
# def compile_expression(exp):
# def getExpression(trigger_expression=None, **kwargs):


from twisted.trial import unittest
from moira.checker import state, expression


class Expression(unittest.TestCase):

    def testDefault(self):
        self.assertEqual(expression.getExpression(t1=10, warn_value=60, error_value=90), state.OK)
        self.assertEqual(expression.getExpression(t1=60, warn_value=60, error_value=90), state.WARN)
        self.assertEqual(expression.getExpression(t1=90, warn_value=60, error_value=90), state.ERROR)
        self.assertEqual(expression.getExpression(t1=40, warn_value=30, error_value=10), state.OK)
        self.assertEqual(expression.getExpression(t1=20, warn_value=30, error_value=10), state.WARN)
        self.assertEqual(expression.getExpression(t1=10, warn_value=30, error_value=10), state.ERROR)

# Path: moira/checker/state.py
# OK = "OK"
# WARN = "WARN"
# ERROR = "ERROR"
# NODATA = "NODATA"
# EXCEPTION = "EXCEPTION"
# DEL = "DEL"
# SCORES = {
#     "OK": 0,
#     "DEL": 0,
#     "WARN": 1,
#     "ERROR": 100,
#     "NODATA": 1000,
#     "EXCEPTION": 100000
# }
# def to_metric_state(state):
# 
# Path: moira/checker/expression.py
# DEFAULT = compile(_default, '<string>', mode='eval')
# class ExpressionError(Exception):
# def compile_expression(exp):
# def getExpression(trigger_expression=None, **kwargs):


# Path: tests/unit/test_expression.py
from twisted.trial import unittest
from moira.checker import state, expression



class Expression(unittest.TestCase):

    def testDefault(self):
        self.assertEqual(expression.getExpression(t1=10, warn_value=60, error_value=90), state.OK)
        self.assertEqual(expression.getExpression(t1=60, warn_value=60, error_value=90), state.WARN)
        self.assertEqual(expression.getExpression(t1=90, warn_value=60, error_value=90), state.ERROR)
        self.assertEqual(expression.getExpression(t1=40, warn_value=30, error_value=10), state.OK)
        self.assertEqual(expression.getExpression(t1=20, warn_value=30, error_value=10), state.WARN)
        self.assertEqual(expression.getExpression(t1=10, warn_value=30, error_value=10), state.ERROR)

        self.assertEqual(expression.getExpression(**{'t1': 10, 'warn_value': 30, 'error_value': 10}), state.ERROR)