def test_bounded_str_sanitisation(self): grimacing_face = u"\U0001f62c" sanitise = cef.str_sanitiser("[banana]*", min_len=3, max_len=6, escape_chars="b") self.assertRaises(ValueError, sanitise, "an", "label") self.assertEqual(sanitise("ba", "label"), r"\ba") self.assertEqual(sanitise("banan", "label"), r"\banan") # Escaping makes string too long: six.assertRaisesRegex(self, ValueError, "range", sanitise, "banana", "label") self.assertRaises(ValueError, sanitise, "apple", "label") self.assertRaises(TypeError, sanitise, 3, "label") # encoding makes string too long: six.assertRaisesRegex( self, ValueError, "range", cef.str_sanitiser(max_len=3), grimacing_face, "label", ) # encoding makes string long enough: assert cef.str_sanitiser(min_len=4)(grimacing_face, "dbg") == grimacing_face
def test_unbounded_str_sanitisation(self): sanitise = cef.str_sanitiser("banana") self.assertEqual(sanitise("banana", "label"), "banana") self.assertRaises(ValueError, sanitise, "apple", "label") sanitise = cef.str_sanitiser() self.assertEqual(sanitise("", "label"), "") sanitise = cef.str_sanitiser(min_len=1) self.assertRaises(ValueError, sanitise, "", "label") self.assertEqual(sanitise("a", "label"), "a")
def test_unbounded_str_sanitisation(self): sanitise = cef.str_sanitiser('banana') self.assertEqual(sanitise('banana', 'label'), 'banana') self.assertRaises(ValueError, sanitise, 'apple', 'label') sanitise = cef.str_sanitiser() self.assertEqual(sanitise('', 'label'), '') sanitise = cef.str_sanitiser(min_len=1) self.assertRaises(ValueError, sanitise, '', 'label') self.assertEqual(sanitise('a', 'label'), 'a')
def test_bounded_str_sanitisation(self): sanitise = cef.str_sanitiser( '[banana]*', min_len=3, max_len=6, escape_chars='b') self.assertRaises(ValueError, sanitise, 'an', 'label') self.assertEqual(sanitise('ba', 'label'), r'\ba') self.assertEqual(sanitise('banan', 'label'), r'\banan') # Escaping makes string too long: self.assertRaisesRegexp( ValueError, 'range', sanitise, 'banana', 'label') self.assertRaises(ValueError, sanitise, 'apple', 'label') self.assertRaises(TypeError, sanitise, 3, 'label')