コード例 #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  '))