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