示例#1
0
 def testFailsOnFieldValueError(self):
     icd = createDefaultTestIcd(data.FORMAT_CSV)
     with interface.Validator(icd) as validator:
         location = tools.createCallerInputLocation(hasCell=True)
         validator.open(location)
         TestRow = [u"38123", u"12345", u"John", u"Doe", u"some", u"08.03.1957"]
         self.assertRaises(fields.FieldValueError, validator.validatedRow, TestRow)
         self.assertEqual(validator.acceptedCount, 0)
         self.assertEqual(validator.rejectedCount, 1)
         validator.close()
示例#2
0
 def testCanValidateValidData(self):
     icd = createDefaultTestIcd(data.FORMAT_CSV)
     with interface.Validator(icd) as validator:
         location = tools.createCallerInputLocation(hasCell=True)
         validator.open(location)
         TestRow = [u"38123", u"12345", u"John", u"Doe", u"male", u"08.03.1957"]
         row = validator.validatedRow(TestRow)
         self.assertEqual(row, TestRow)
         validator.close()
         self.assertEqual(validator.acceptedCount, 1)
         self.assertEqual(validator.rejectedCount, 0)
示例#3
0
 def testFailsOnRowCheckError(self):
     icd = createDefaultTestIcd(data.FORMAT_CSV)
     with interface.Validator(icd) as validator:
         location = tools.createCallerInputLocation(hasCell=True)
         validator.open(location)
         TestRow = [u"38123", u"12345", u"John", u"Doe", u"male", u"08.03.1957"]
         _ = validator.validatedRow(TestRow)
         location.advanceLine()
         self.assertRaises(checks.CheckError, validator.validatedRow, TestRow)
         self.assertEqual(validator.acceptedCount, 1)
         self.assertEqual(validator.rejectedCount, 1)
         validator.close()
示例#4
0
 def testFailsOnCheckAtEndError(self):
     icd = createDefaultTestIcd(data.FORMAT_CSV)
     try:
         with interface.Validator(icd) as validator:
             location = tools.createCallerInputLocation(hasCell=True)
             validator.open(location)
             for branchId in _TooManyTestBranchIds:
                 rowToValidate = [branchId, u"12345", u"John", u"Doe", u"male", u"08.03.1957"]
                 row = validator.validatedRow(rowToValidate)
                 self.assertEqual(row, rowToValidate)
                 location.advanceLine()
         self.fail("check 'distinct branches must be within limit' must fail")
     except checks.CheckError, error:
         errorMessage = u"%s" % error
         self.assertTrue("distinct count" in errorMessage, u"errorMessage=%r" % errorMessage)
示例#5
0
    def __init__(self, description, rule, availableFieldNames, locationOfDefinition=None):
        """
        Create a check with the human readable ``description``, a ``rule`` in a check dependent
        syntax which can act on the fields listed in ``availableFieldNames`` (in the same order as
        defined in the ICD) and the optional ``locationOfDefinition`` in the ICD. If no
        ``locationOfDefinition`` is provided, `tools.createCallerInputLocation(["checks"])` is
        used.
        """
        assert description
        assert rule is not None
        assert availableFieldNames is not None

        if not availableFieldNames:
            raise fields.FieldLookupError(u"field names must be specified", locationOfDefinition)
        self._description = description
        self._rule = rule
        self._fieldNames = availableFieldNames
        if locationOfDefinition is None:
            self._location = tools.createCallerInputLocation(["checks"])
        else:
            self._location = locationOfDefinition