def test_fails_on_inconsistent_length(self): try: fields.ConstantFieldFormat('inconsistent_length', False, '2', '"a"', _ANY_FORMAT) self.fail() except errors.InterfaceError as anticipated_error: dev_test.assert_error_fnmatches( self, anticipated_error, "length is 2 but must be 1 to match constant 'a'")
def test_can_match_empty_constant(self): always_empty_format = fields.ConstantFieldFormat('constant', True, None, '', _ANY_FORMAT) self.assertEqual(always_empty_format.validated(''), '')
def test_can_match_constant_string(self): self._constant_format = fields.ConstantFieldFormat('constant', False, None, '"some"', _ANY_FORMAT) self.assertEqual(self._constant_format.validated('some'), 'some')
def test_can_match_constant_float(self): self._constant_format = fields.ConstantFieldFormat('constant', False, None, '3.1', _ANY_FORMAT) self.assertEqual(self._constant_format.validated('3.1'), '3.1')
def setUp(self): self._constant_format = fields.ConstantFieldFormat('constant', False, None, 'some', _ANY_FORMAT)