33
37
result = natural_sorted(input, key=lambda t: t[1])
34
38
self.assertEqual(result, wanted)
35
39
self.assertTrue(id(result) != id(input))
42
class TestOrderedDict(tests.TestCase):
45
items = [('foo', 1), ('bar', 2), ('baz', 3)]
46
mydict = OrderedDict(items)
48
self.assertIsInstance(repr(mydict), str)
50
self.assertEqual(mydict.items(), items)
51
self.assertEqual(list(mydict), [i[0] for i in items])
52
self.assertEqual(mydict.keys(), [i[0] for i in items])
55
mydict.setdefault('foo', 'dus')
56
items = [('foo', 1), ('bar', 'X'), ('baz', 3)]
57
self.assertEqual(mydict.items(), items)
58
self.assertEqual(list(mydict), [i[0] for i in items])
59
self.assertEqual(mydict.keys(), [i[0] for i in items])
63
items = [('foo', 1), ('baz', 3), ('bar', 'Y')]
64
self.assertEqual(mydict.items(), items)
65
self.assertEqual(list(mydict), [i[0] for i in items])
66
self.assertEqual(mydict.keys(), [i[0] for i in items])
69
mydict.setdefault('foo', 'dus')
70
items = [('baz', 3), ('bar', 'Y'), ('foo', 'dus')]
71
self.assertEqual(mydict.items(), items)
72
self.assertEqual(list(mydict), [i[0] for i in items])
73
self.assertEqual(mydict.keys(), [i[0] for i in items])
78
class TestFunctionThread(tests.TestCase):
83
return 'FOO: ' + ', '.join(args)
85
# Function OK, no lock
86
func = FunctionThread(foo, ('a', 'b', 'c'))
87
self.assertFalse(func.done)
91
self.assertTrue(func.done)
92
self.assertFalse(func.error)
93
self.assertEqual(func.result, 'FOO: a, b, c')
95
# Function OK, with lock
96
lock = threading.Lock()
98
func = FunctionThread(foo, ('a', 'b', 'c'), lock=lock)
99
self.assertFalse(func.done)
103
self.assertTrue(func.done)
104
self.assertFalse(func.error)
105
self.assertEqual(func.result, 'FOO: a, b, c')
110
raise AssertionError, 'FOO'
112
# Function raises, no lock
113
func = FunctionThread(error, ('a', 'b', 'c'))
114
self.assertFalse(func.done)
118
self.assertTrue(func.done)
119
self.assertTrue(func.error)
120
self.assertEqual(func.exc_info[0], AssertionError)
122
# Function raises, with lock
123
#~ lock = threading.Lock()
125
#~ func = FunctionThread(error, ('a', 'b', 'c'))
126
#~ self.assertFalse(func.done)
130
#~ self.assertTrue(func.done)
131
#~ self.assertTrue(func.error)
132
#~ self.assertEqual(func.exc_info[0], AssertionError)