Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test_formatstring.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import unittest
  2. from lodel.leapi.datahandlers.datas import FormatString as Testee
  3. from lodel.editorial_model.components import EmClass
  4. class TesteeTestCase(unittest.TestCase):
  5. regex = '%s-%s'
  6. dummyEmClass = EmClass('testing')
  7. fone_name = 'field1'
  8. ftwo_name = 'field2'
  9. dummyEmClass.new_field(fone_name, 'varchar')
  10. dummyEmClass.new_field(ftwo_name, 'varchar')
  11. field_one_value = 'field one value'
  12. field_two_value = 'field two value'
  13. field_value_dict = {fone_name: field_one_value, ftwo_name: field_two_value}
  14. field_list = [fone_name, ftwo_name]
  15. test_Testee = Testee(regex,[fone_name, ftwo_name])
  16. max_length = round(len(regex % (field_one_value, field_two_value)) / 2)
  17. def test_has_base_type_property(self):
  18. self.assertTrue(hasattr(Testee, 'base_type'))
  19. def test_base_type_is_char(self):
  20. self.assertEqual(Testee.base_type, 'char')
  21. def test_has_help_property(self):
  22. self.assertTrue(hasattr(Testee, 'help'))
  23. def test_help_property_str_is_set(self):
  24. self.assertEqual(type(Testee.help), str)
  25. def test_string_formatting_output(self):
  26. expected_result = self.regex % (self.field_one_value, self.field_two_value)
  27. actual_result = self.test_Testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
  28. self.assertEqual(actual_result, expected_result)
  29. def test_throws_user_warning_on_exceeding_string(self):
  30. max_length = len(self.regex % (self.field_one_value, self.field_two_value)) / 2
  31. testee = Testee(self.regex, self.field_list, max_length=self.max_length)
  32. with self.assertWarns(UserWarning):
  33. testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
  34. def test_exceeding_string_length_is_truncated(self):
  35. max_length = 2
  36. testee = Testee(self.regex, self.field_list, max_length=self.max_length)
  37. result_string = testee._construct_data(self.dummyEmClass, None, self.field_value_dict, None)
  38. self.assertEqual(self.max_length, len(result_string))
  39. def test_thrown_exceeding_str_warning_message_composition(self):
  40. testee = Testee(self.regex, self.field_list, max_length=self.max_length)
  41. with self.assertWarnsRegex(UserWarning, '[T|t]runcat[a-z]+'):
  42. testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)