1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import contextlib
20 import gc
21 import platform
22 import random
23 import unittest
24
25 import wx
26
27 from timelinelib.calendar.gregorian.timetype import GregorianTimeType
28 from timelinelib.test.utils import svg_to_dict
32
33 HALT_GUI = False
34 AUTO_CLOSE = False
35
38
40 message = "Periods not equal.\n First: %s \"%s\"\n Second: %s \"%s\"" % (
41 first,
42 time_type.format_period(first),
43 second,
44 time_type.format_period(second),
45 )
46 self.assertEqual(first, second, message)
47
49 for element in list_:
50 if element is object_:
51 self.fail("%r was in list" % object_)
52
54 (modification_description, modifier_fn) = get_random_modifier(modifiers)
55 one = modifier_fn(create_fn())
56 other = modifier_fn(create_fn())
57 fail_message_one_other = "%r vs %r (%s)" % (one, other,
58 modification_description)
59 self.assertTrue(type(one) == type(other), fail_message_one_other)
60 self.assertFalse(one is None, fail_message_one_other)
61 self.assertTrue(one is not None, fail_message_one_other)
62 self.assertTrue(one is not other, fail_message_one_other)
63 self.assertFalse(one is other, fail_message_one_other)
64 self.assertTrue(one == other, fail_message_one_other)
65 self.assertFalse(one != other, fail_message_one_other)
66 self.assertTrue(one == one, fail_message_one_other)
67 self.assertFalse(one != one, fail_message_one_other)
68 (modification_description, modifier_fn) = get_random_modifier(modifiers)
69 modified = modifier_fn(other)
70 fail_message_modified_one = "%r vs %r (%s)" % (modified, one,
71 modification_description)
72 self.assertTrue(type(modified) == type(one), fail_message_modified_one)
73 self.assertTrue(modified is not one, fail_message_modified_one)
74 self.assertFalse(modified is one, fail_message_modified_one)
75 self.assertTrue(modified != one, fail_message_modified_one)
76 self.assertFalse(modified == one, fail_message_modified_one)
77
79 with self.wxapp() as app:
80 dialog = dialog_class(*args, **kwargs)
81 try:
82 if self.HALT_GUI:
83 if self.AUTO_CLOSE:
84 wx.CallLater(2000, dialog.Close)
85 dialog.ShowModal()
86 finally:
87 dialog.Destroy()
88
89 @contextlib.contextmanager
96
98 app = wx.App(False)
99 if platform.system() == "Windows":
100 import locale
101 locale.setlocale(locale.LC_ALL, 'C')
102 self.locale = wx.Locale()
103 self.locale.Init(wx.LANGUAGE_DEFAULT)
104 return app
105
107 if app.GetTopWindow():
108 app.GetTopWindow().Destroy()
109 app.Destroy()
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 gc.collect()
125
128 return random.choice(modifiers)
129