Beispiel #1
0
 def test__val_text__strCoersion(self):
     """validators.val_text: Given values that can be converted 
     to strings should be converted and returned.
     """
     expected = '100'
     actual = v.val_text(None, 100)
     self.assertEqual(expected, actual)
Beispiel #2
0
 def test__val_text__valid(self):
     """validators.val_text: If the given value is a valid string, 
     the function should return it.
     """
     expected = 'spam'
     actual = v.val_text(None, expected)
     self.assertEqual(expected, actual)
Beispiel #3
0
 def test__val_text__normalization(self):
     """validators.val_text: If the given value contains unicode 
     characters that haven't been normalized, normalize them. The 
     default normal form should be NFC.
     """
     expected = 'á'
     text = '\u0061\u0301'
     actual = v.val_text(None, text)
     self.assertEqual(expected, actual)
Beispiel #4
0
 def test_val_text__charsetNormalization(self):
     """validators.val.text: Given values should be normalized to 
     UTF-8 strings and returned, if the source character set is 
     given.
     """
     expected = 'résumé'
     b = b'r\xe9sum\xe9'
     actual = v.val_text(None, b, 'iso_8859_1')
     self.assertEqual(expected, actual)
Beispiel #5
0
 def test__val_text__invalidUtf8(self):
     """validators.val_text: If the given value contains invalid 
     characters for the expected character set, the value should 
     be rejected.
     """
     expected = ValueError
     
     class Spam:
         msg = 'Bad ({}).'
     obj = Spam()
     text = b'r\xc3sum\xc3'
     
     with self.assertRaises(ValueError):
         actual = v.val_text(obj, text)