# Path: hecatoncheir/exception.py
# class ValidationError(Exception):
#     source = None
# 
#     def __init__(self, value, rule, params=None, source=None):
#         self.value = value
#         self.rule = rule
#         self.params = params
#         self.source = source
# 
#     def __str__(self):
#         return self.value
# 
# Path: hecatoncheir/validator/StatEvalValidator.py
# class StatEvalValidator(StatisticsValidator.StatisticsValidator):
#     """Validator for the min/max value
# 
#     v = StatEvalValidator('foo', [u'COL1', '{min} > 100'])
#     s = {'row_count': 100,
#         'columns': [{
#             'column_name': 'COL1',
#             'min': 101,
#             'max': 1000,
#             'cardinality': 10}]}
#     assert v.validate(s) == True
#     """
#     def __init__(self, label, rule):
#         StatisticsValidator.StatisticsValidator.__init__(self, label, rule)
# 
#     def validate(self, stats):
#         """Validate a min/max rule based the column statistics
# 
#         Args:
#             stats (dict): a table statistics. see Data_Structure.txt
#                           for more info.
# 
#         Returns:
#             True if the expression is true, otherwise False.
#         """
#         # rule: [ column_name, expression ]
#         assert len(self.rule) == 2
#         assert 'columns' in stats
# 
#         c = None
#         for col in stats['columns']:
#             if col['column_name'] == self.rule[0]:
#                 c = col
#                 break
# 
#         if c is None:
#             raise ValidationError(
#                 _("Column `%s' not found. Check your validation rule again.") %
#                 self.rule[0],
#                 self.rule)
#         assert 'row_count' in stats
#         assert ('nulls' in c and 'min' in c and 'max' in c and
#                 'cardinality' in c)
#         kv = {'rows': stats['row_count'], 'nulls': c['nulls'], 'min': c['min'],
#               'max': c['max'], 'cardinality': c['cardinality']}
# 
#         self.statistics[0] += 1
# 
#         try:
#             s = self.rule[1].format(**kv)
#         except KeyError as e:
#             self.statistics[1] += 1
#             raise ValidationError(
#                 _("Parameter error: ") + "`%s'" % kv,
#                 self.rule)
# 
#         try:
#             if eval(s) is False:
#                 self.statistics[1] += 1
#                 return False
#         except SyntaxError:
#             self.statistics[1] += 1
#             raise ValidationError(
#                 _("Syntax error: ") + "`%s'" % s,
#                 self.rule)
# 
#         return True


import sys
import unittest
from hecatoncheir.exception import ValidationError
from hecatoncheir.validator import StatEvalValidator
                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 10}],
             'row_count': 10}
        self.assertTrue(v.validate(s))

    def test_validate_003(self):
        v = StatEvalValidator.StatEvalValidator('foo', rule=[u'COL1', '{cardinality} > 10'])
        s = {'columns': [{
                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 10}],
             'row_count': 10}
        self.assertFalse(v.validate(s))

        v = StatEvalValidator.StatEvalValidator('foo', rule=[u'COL1', '{cardinality} > 10'])
        s = {'columns': [{
                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 11}],
             'row_count': 11}
        self.assertTrue(v.validate(s))

    def test_validate_004(self):

# Path: hecatoncheir/exception.py
# class ValidationError(Exception):
#     source = None
# 
#     def __init__(self, value, rule, params=None, source=None):
#         self.value = value
#         self.rule = rule
#         self.params = params
#         self.source = source
# 
#     def __str__(self):
#         return self.value
# 
# Path: hecatoncheir/validator/StatEvalValidator.py
# class StatEvalValidator(StatisticsValidator.StatisticsValidator):
#     """Validator for the min/max value
# 
#     v = StatEvalValidator('foo', [u'COL1', '{min} > 100'])
#     s = {'row_count': 100,
#         'columns': [{
#             'column_name': 'COL1',
#             'min': 101,
#             'max': 1000,
#             'cardinality': 10}]}
#     assert v.validate(s) == True
#     """
#     def __init__(self, label, rule):
#         StatisticsValidator.StatisticsValidator.__init__(self, label, rule)
# 
#     def validate(self, stats):
#         """Validate a min/max rule based the column statistics
# 
#         Args:
#             stats (dict): a table statistics. see Data_Structure.txt
#                           for more info.
# 
#         Returns:
#             True if the expression is true, otherwise False.
#         """
#         # rule: [ column_name, expression ]
#         assert len(self.rule) == 2
#         assert 'columns' in stats
# 
#         c = None
#         for col in stats['columns']:
#             if col['column_name'] == self.rule[0]:
#                 c = col
#                 break
# 
#         if c is None:
#             raise ValidationError(
#                 _("Column `%s' not found. Check your validation rule again.") %
#                 self.rule[0],
#                 self.rule)
#         assert 'row_count' in stats
#         assert ('nulls' in c and 'min' in c and 'max' in c and
#                 'cardinality' in c)
#         kv = {'rows': stats['row_count'], 'nulls': c['nulls'], 'min': c['min'],
#               'max': c['max'], 'cardinality': c['cardinality']}
# 
#         self.statistics[0] += 1
# 
#         try:
#             s = self.rule[1].format(**kv)
#         except KeyError as e:
#             self.statistics[1] += 1
#             raise ValidationError(
#                 _("Parameter error: ") + "`%s'" % kv,
#                 self.rule)
# 
#         try:
#             if eval(s) is False:
#                 self.statistics[1] += 1
#                 return False
#         except SyntaxError:
#             self.statistics[1] += 1
#             raise ValidationError(
#                 _("Syntax error: ") + "`%s'" % s,
#                 self.rule)
# 
#         return True


# Path: tests/testStatEvalValidator.py
import sys
import unittest
from hecatoncheir.exception import ValidationError
from hecatoncheir.validator import StatEvalValidator

                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 10}],
             'row_count': 10}
        self.assertTrue(v.validate(s))

    def test_validate_003(self):
        v = StatEvalValidator.StatEvalValidator('foo', rule=[u'COL1', '{cardinality} > 10'])
        s = {'columns': [{
                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 10}],
             'row_count': 10}
        self.assertFalse(v.validate(s))

        v = StatEvalValidator.StatEvalValidator('foo', rule=[u'COL1', '{cardinality} > 10'])
        s = {'columns': [{
                    'column_name': 'COL1',
                    'nulls': 0,
                    'min': 100,
                    'max': 1001,
                    'cardinality': 11}],
             'row_count': 11}
        self.assertTrue(v.validate(s))

    def test_validate_004(self):

        v = StatEvalValidator.StatEvalValidator('foo', rule=[u'COL2', '{cardinality} > 10'])