コード例 #1
0
    def test_dictionary(self):
        notifications = []

        def listener(longest_key):
            notifications.append(longest_key)

        d = StenoDictionary()
        self.assertEqual(d.longest_key, 0)

        d.add_longest_key_listener(listener)
        d[('S', )] = 'a'
        self.assertEqual(d.longest_key, 1)
        self.assertEqual(notifications, [1])
        d[('S', 'S', 'S', 'S')] = 'b'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(notifications, [1, 4])
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 4)
        self.assertEqual(d[('S', 'S')], 'c')
        self.assertEqual(notifications, [1, 4])
        del d[('S', 'S', 'S', 'S')]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        del d[('S', )]
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2])
        d.clear()
        self.assertEqual(d.longest_key, 0)
        self.assertEqual(notifications, [1, 4, 2, 0])

        d.remove_longest_key_listener(listener)
        d[('S', 'S')] = 'c'
        self.assertEqual(d.longest_key, 2)
        self.assertEqual(notifications, [1, 4, 2, 0])

        self.assertEqual(StenoDictionary([('a', 'b')]).items(), [('a', 'b')])
        self.assertEqual(StenoDictionary(a='b').items(), [('a', 'b')])
コード例 #2
0
ファイル: test_steno_dictionary.py プロジェクト: gcr/plover
 def test_dictionary(self):
     notifications = []
     def listener(longest_key):
         notifications.append(longest_key)
     
     d = StenoDictionary()
     self.assertEqual(d.longest_key, 0)
     
     d.add_longest_key_listener(listener)
     d[('S',)] = 'a'
     self.assertEqual(d.longest_key, 1)
     self.assertEqual(notifications, [1])
     d[('S', 'S', 'S', 'S')] = 'b'
     self.assertEqual(d.longest_key, 4)
     self.assertEqual(notifications, [1, 4])
     d[('S', 'S')] = 'c'
     self.assertEqual(d.longest_key, 4)
     self.assertEqual(d[('S', 'S')], 'c')
     self.assertEqual(notifications, [1, 4])
     del d[('S', 'S', 'S', 'S')]
     self.assertEqual(d.longest_key, 2)
     self.assertEqual(notifications, [1, 4, 2])
     del d[('S',)]
     self.assertEqual(d.longest_key, 2)
     self.assertEqual(notifications, [1, 4, 2])
     d.clear()
     self.assertEqual(d.longest_key, 0)
     self.assertEqual(notifications, [1, 4, 2, 0])
     
     d.remove_longest_key_listener(listener)
     d[('S', 'S')] = 'c'
     self.assertEqual(d.longest_key, 2)
     self.assertEqual(notifications, [1, 4, 2, 0])
     
     self.assertEqual(StenoDictionary([('a', 'b')]).items(), [('a', 'b')])
     self.assertEqual(StenoDictionary(a='b').items(), [('a', 'b')])