예제 #1
0
 def test_strips_text(self):
     # The set method should strip the string before setting the field.
     target = make_target()
     field = StrippableText(__name__='test', strip_text=True)
     self.assertTrue(field.strip_text)
     field.set(target, '  testing  ')
     self.assertEqual('testing', target.test)
예제 #2
0
 def test_strips_text(self):
     # The set method should strip the string before setting the field.
     target = make_target()
     field = StrippableText(__name__='test', strip_text=True)
     self.assertTrue(field.strip_text)
     field.set(target, '  testing  ')
     self.assertEqual('testing', target.test)
예제 #3
0
 def test_default_constructor(self):
     # If strip_text is not set, or set to false, then the text is not
     # stripped when set.
     target = make_target()
     field = StrippableText(__name__='test')
     self.assertFalse(field.strip_text)
     field.set(target, '  testing  ')
     self.assertEqual('  testing  ', target.test)
예제 #4
0
 def test_strips_text_trailing_only(self):
     # The set method strips the trailing whitespace.
     target = make_target()
     field = StrippableText(
         __name__='test', strip_text=True, trailing_only=True)
     self.assertTrue(field.trailing_only)
     field.set(target, '  testing  ')
     self.assertEqual('  testing', target.test)
예제 #5
0
 def test_default_constructor(self):
     # If strip_text is not set, or set to false, then the text is not
     # stripped when set.
     target = make_target()
     field = StrippableText(__name__='test')
     self.assertFalse(field.strip_text)
     field.set(target, '  testing  ')
     self.assertEqual('  testing  ', target.test)
예제 #6
0
 def test_strips_text_trailing_only(self):
     # The set method strips the trailing whitespace.
     target = make_target()
     field = StrippableText(__name__='test',
                            strip_text=True,
                            trailing_only=True)
     self.assertTrue(field.trailing_only)
     field.set(target, '  testing  ')
     self.assertEqual('  testing', target.test)
예제 #7
0
 def test_setting_with_none(self):
     # The set method is given None, the attribute is set to None
     target = make_target()
     field = StrippableText(__name__='test', strip_text=True)
     field.set(target, None)
     self.assertIs(None, target.test)
예제 #8
0
 def test_validate_max_contraints(self):
     # The minimum length constraint tests the stripped string.
     field = StrippableText(
         __name__='test', strip_text=True, max_length=2)
     self.assertEqual(None, field.validate(u'  a  '))
예제 #9
0
 def test_validate_min_contraints(self):
     # The minimum length constraint tests the stripped string.
     field = StrippableText(__name__='test', strip_text=True, min_length=1)
     self.assertRaises(TooShort, field.validate, u'  ')
예제 #10
0
 def test_setting_with_none(self):
     # The set method is given None, the attribute is set to None
     target = make_target()
     field = StrippableText(__name__='test', strip_text=True)
     field.set(target, None)
     self.assertIs(None, target.test)
예제 #11
0
 def test_validate_max_contraints(self):
     # The minimum length constraint tests the stripped string.
     field = StrippableText(__name__='test', strip_text=True, max_length=2)
     self.assertEqual(None, field.validate(u'  a  '))