コード例 #1
0
 def test_dictionary_enabled(self):
     dc = StenoDictionaryCollection()
     d1 = StenoDictionary()
     d1.path = 'd1'
     d1[('TEFT', )] = 'test1'
     d1[('TEFGT', )] = 'Testing'
     d2 = StenoDictionary()
     d2[('TEFT', )] = 'test2'
     d2[('TEFT', '-G')] = 'Testing'
     d2.path = 'd2'
     dc.set_dicts([d2, d1])
     self.assertEqual(dc.lookup(('TEFT', )), 'test2')
     self.assertEqual(dc.raw_lookup(('TEFT', )), 'test2')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     self.assertCountEqual(dc.reverse_lookup('Testing'), [('TEFGT', ),
                                                          ('TEFT', '-G')])
     d2.enabled = False
     self.assertEqual(dc.lookup(('TEFT', )), 'test1')
     self.assertEqual(dc.raw_lookup(('TEFT', )), 'test1')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     self.assertCountEqual(dc.reverse_lookup('Testing'), [('TEFGT', )])
     d1.enabled = False
     self.assertEqual(dc.lookup(('TEST', )), None)
     self.assertEqual(dc.raw_lookup(('TEFT', )), None)
     self.assertEqual(dc.casereverse_lookup('testing'), None)
     self.assertCountEqual(dc.reverse_lookup('Testing'), [])
コード例 #2
0
def test_dictionary_enabled():
    dc = StenoDictionaryCollection()
    d1 = StenoDictionary()
    d1.path = 'd1'
    d1[('TEFT', )] = 'test1'
    d1[('TEFGT', )] = 'Testing'
    d2 = StenoDictionary()
    d2[('TEFT', )] = 'test2'
    d2[('TEFT', '-G')] = 'Testing'
    d2.path = 'd2'
    dc.set_dicts([d2, d1])
    assert dc.lookup(('TEFT', )) == 'test2'
    assert dc.raw_lookup(('TEFT', )) == 'test2'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == {('TEFT', '-G'), ('TEFGT', )}
    d2.enabled = False
    assert dc.lookup(('TEFT', )) == 'test1'
    assert dc.raw_lookup(('TEFT', )) == 'test1'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == {('TEFGT', )}
    d1.enabled = False
    assert dc.lookup(('TEST', )) is None
    assert dc.raw_lookup(('TEFT', )) is None
    assert dc.casereverse_lookup('testing') == []
    assert dc.reverse_lookup('Testing') == set()
コード例 #3
0
 def test_dictionary_enabled(self):
     dc = StenoDictionaryCollection()
     d1 = StenoDictionary()
     d1.path = 'd1'
     d1[('TEFT',)] = 'test1'
     d1[('TEFGT',)] = 'Testing'
     d2 = StenoDictionary()
     d2[('TEFT',)] = 'test2'
     d2[('TEFT','-G')] = 'Testing'
     d2.path = 'd2'
     dc.set_dicts([d2, d1])
     self.assertEqual(dc.lookup(('TEFT',)), 'test2')
     self.assertEqual(dc.raw_lookup(('TEFT',)), 'test2')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     assertCountEqual(self, dc.reverse_lookup('Testing'), [('TEFGT',), ('TEFT', '-G')])
     d2.enabled = False
     self.assertEqual(dc.lookup(('TEFT',)), 'test1')
     self.assertEqual(dc.raw_lookup(('TEFT',)), 'test1')
     self.assertEqual(dc.casereverse_lookup('testing'), ['Testing'])
     assertCountEqual(self, dc.reverse_lookup('Testing'), [('TEFGT',)])
     d1.enabled = False
     self.assertEqual(dc.lookup(('TEST',)), None)
     self.assertEqual(dc.raw_lookup(('TEFT',)), None)
     self.assertEqual(dc.casereverse_lookup('testing'), None)
     assertCountEqual(self, dc.reverse_lookup('Testing'), [])
コード例 #4
0
def test_dictionary_collection_longest_key():

    k1 = ('S', )
    k2 = ('S', 'T')
    k3 = ('S', 'T', 'R')

    dc = StenoDictionaryCollection()
    assert dc.longest_key == 0

    d1 = StenoDictionary()
    d1.path = 'd1'
    d1[k1] = 'a'

    dc.set_dicts([d1])
    assert dc.longest_key == 1

    d1[k2] = 'a'
    assert dc.longest_key == 2

    d2 = StenoDictionary()
    d2.path = 'd2'
    d2[k3] = 'c'

    dc.set_dicts([d2, d1])
    assert dc.longest_key == 3

    del d1[k2]
    assert dc.longest_key == 3

    dc.set_dicts([d1])
    assert dc.longest_key == 1

    dc.set_dicts([])
    assert dc.longest_key == 0
コード例 #5
0
def test_dictionary_enabled():
    dc = StenoDictionaryCollection()
    d1 = StenoDictionary()
    d1.path = 'd1'
    d1[('TEFT',)] = 'test1'
    d1[('TEFGT',)] = 'Testing'
    d2 = StenoDictionary()
    d2[('TEFT',)] = 'test2'
    d2[('TEFT', '-G')] = 'Testing'
    d2.path = 'd2'
    dc.set_dicts([d2, d1])
    assert dc.lookup(('TEFT',)) == 'test2'
    assert dc.raw_lookup(('TEFT',)) == 'test2'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == [('TEFT', '-G'), ('TEFGT',)]
    d2.enabled = False
    assert dc.lookup(('TEFT',)) == 'test1'
    assert dc.raw_lookup(('TEFT',)) == 'test1'
    assert dc.casereverse_lookup('testing') == ['Testing']
    assert dc.reverse_lookup('Testing') == [('TEFGT',)]
    d1.enabled = False
    assert dc.lookup(('TEST',)) is None
    assert dc.raw_lookup(('TEFT',)) is None
    assert dc.casereverse_lookup('testing') is None
    assert dc.reverse_lookup('Testing') == []
コード例 #6
0
def test_dictionary_collection_longest_key():

    k1 = ('S',)
    k2 = ('S', 'T')
    k3 = ('S', 'T', 'R')

    dc = StenoDictionaryCollection()
    assert dc.longest_key == 0

    d1 = StenoDictionary()
    d1.path = 'd1'
    d1[k1] = 'a'

    dc.set_dicts([d1])
    assert dc.longest_key == 1

    d1[k2] = 'a'
    assert dc.longest_key == 2

    d2 = StenoDictionary()
    d2.path = 'd2'
    d2[k3] = 'c'

    dc.set_dicts([d2, d1])
    assert dc.longest_key == 3

    del d1[k2]
    assert dc.longest_key == 3

    dc.set_dicts([d1])
    assert dc.longest_key == 1

    dc.set_dicts([])
    assert dc.longest_key == 0
コード例 #7
0
    def test_dictionary_collection(self):
        dc = StenoDictionaryCollection()
        d1 = StenoDictionary()
        d1[('S',)] = 'a'
        d1[('T',)] = 'b'
        d1.path = 'd1'
        d2 = StenoDictionary()
        d2[('S',)] = 'c'
        d2[('W',)] = 'd'
        d2.path = 'd2'
        dc.set_dicts([d2, d1])
        self.assertEqual(dc.lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')
        f = lambda k, v: v == 'c'
        dc.add_filter(f)
        self.assertIsNone(dc.lookup(('S',)))
        self.assertEqual(dc.raw_lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')
        self.assertEqual(dc.reverse_lookup('c'), [('S',)])

        dc.remove_filter(f)
        self.assertEqual(dc.lookup(('S',)), 'c')
        self.assertEqual(dc.lookup(('W',)), 'd')
        self.assertEqual(dc.lookup(('T',)), 'b')

        self.assertEqual(dc.reverse_lookup('c'), [('S',)])

        dc.set(('S',), 'e')
        self.assertEqual(dc.lookup(('S',)), 'e')
        self.assertEqual(d2[('S',)], 'e')

        dc.set(('S',), 'f', path='d1')
        self.assertEqual(dc.lookup(('S',)), 'e')
        self.assertEqual(d1[('S',)], 'f')
        self.assertEqual(d2[('S',)], 'e')

        # Iterating on a StenoDictionaryCollection is
        # the same as iterating on its dictionaries' paths.
        self.assertEqual(list(dc), ['d2', 'd1'])

        # Test get and [].
        self.assertEqual(dc.get('d1'), d1)
        self.assertEqual(dc['d1'], d1)
        self.assertEqual(dc.get('invalid'), None)
        with self.assertRaises(KeyError):
            dc['invalid']
コード例 #8
0
    def test_dictionary_collection(self):
        dc = StenoDictionaryCollection()
        d1 = StenoDictionary()
        d1[('S', )] = 'a'
        d1[('T', )] = 'b'
        d1.path = 'd1'
        d2 = StenoDictionary()
        d2[('S', )] = 'c'
        d2[('W', )] = 'd'
        d2.path = 'd2'
        dc.set_dicts([d2, d1])
        self.assertEqual(dc.lookup(('S', )), 'c')
        self.assertEqual(dc.lookup(('W', )), 'd')
        self.assertEqual(dc.lookup(('T', )), 'b')
        f = lambda k, v: v == 'c'
        dc.add_filter(f)
        self.assertIsNone(dc.lookup(('S', )))
        self.assertEqual(dc.raw_lookup(('S', )), 'c')
        self.assertEqual(dc.lookup(('W', )), 'd')
        self.assertEqual(dc.lookup(('T', )), 'b')
        self.assertEqual(dc.reverse_lookup('c'), [('S', )])

        dc.remove_filter(f)
        self.assertEqual(dc.lookup(('S', )), 'c')
        self.assertEqual(dc.lookup(('W', )), 'd')
        self.assertEqual(dc.lookup(('T', )), 'b')

        self.assertEqual(dc.reverse_lookup('c'), [('S', )])

        dc.set(('S', ), 'e')
        self.assertEqual(dc.lookup(('S', )), 'e')
        self.assertEqual(d2[('S', )], 'e')

        dc.set(('S', ), 'f', path='d1')
        self.assertEqual(dc.lookup(('S', )), 'e')
        self.assertEqual(d1[('S', )], 'f')
        self.assertEqual(d2[('S', )], 'e')

        # Iterating on a StenoDictionaryCollection is
        # the same as iterating on its dictionaries' paths.
        self.assertEqual(list(dc), ['d2', 'd1'])

        # Test get and [].
        self.assertEqual(dc.get('d1'), d1)
        self.assertEqual(dc['d1'], d1)
        self.assertEqual(dc.get('invalid'), None)
        with self.assertRaises(KeyError):
            dc['invalid']
コード例 #9
0
def test_dictionary_collection():
    d1 = StenoDictionary()
    d1[('S', )] = 'a'
    d1[('T', )] = 'b'
    d1.path = 'd1'
    d2 = StenoDictionary()
    d2[('S', )] = 'c'
    d2[('W', )] = 'd'
    d2.path = 'd2'
    dc = StenoDictionaryCollection([d2, d1])
    assert dc.lookup(('S', )) == 'c'
    assert dc.lookup(('W', )) == 'd'
    assert dc.lookup(('T', )) == 'b'
    f = lambda k, v: v == 'c'
    dc.add_filter(f)
    assert dc.lookup(('S', )) is None
    assert dc.raw_lookup(('S', )) == 'c'
    assert dc.lookup(('W', )) == 'd'
    assert dc.lookup(('T', )) == 'b'
    assert dc.reverse_lookup('c') == {('S', )}

    dc.remove_filter(f)
    assert dc.lookup(('S', )) == 'c'
    assert dc.lookup(('W', )) == 'd'
    assert dc.lookup(('T', )) == 'b'

    assert dc.reverse_lookup('c') == {('S', )}

    dc.set(('S', ), 'e')
    assert dc.lookup(('S', )) == 'e'
    assert d2[('S', )] == 'e'

    dc.set(('S', ), 'f', path='d1')
    assert dc.lookup(('S', )) == 'e'
    assert d1[('S', )] == 'f'
    assert d2[('S', )] == 'e'

    # Iterating on a StenoDictionaryCollection is
    # the same as iterating on its dictionaries' paths.
    assert list(dc) == ['d2', 'd1']

    # Test get and [].
    assert dc.get('d1') == d1
    assert dc['d1'] == d1
    assert dc.get('invalid') is None
    with pytest.raises(KeyError):
        dc['invalid']
コード例 #10
0
def test_dictionary_collection():
    d1 = StenoDictionary()
    d1[('S',)] = 'a'
    d1[('T',)] = 'b'
    d1.path = 'd1'
    d2 = StenoDictionary()
    d2[('S',)] = 'c'
    d2[('W',)] = 'd'
    d2.path = 'd2'
    dc = StenoDictionaryCollection([d2, d1])
    assert dc.lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'
    f = lambda k, v: v == 'c'
    dc.add_filter(f)
    assert dc.lookup(('S',)) is None
    assert dc.raw_lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'
    assert dc.reverse_lookup('c') == [('S',)]

    dc.remove_filter(f)
    assert dc.lookup(('S',)) == 'c'
    assert dc.lookup(('W',)) == 'd'
    assert dc.lookup(('T',)) == 'b'

    assert dc.reverse_lookup('c') == [('S',)]

    dc.set(('S',), 'e')
    assert dc.lookup(('S',)) == 'e'
    assert d2[('S',)] == 'e'

    dc.set(('S',), 'f', path='d1')
    assert dc.lookup(('S',)) == 'e'
    assert d1[('S',)] == 'f'
    assert d2[('S',)] == 'e'

    # Iterating on a StenoDictionaryCollection is
    # the same as iterating on its dictionaries' paths.
    assert list(dc) == ['d2', 'd1']

    # Test get and [].
    assert dc.get('d1') == d1
    assert dc['d1'] == d1
    assert dc.get('invalid') is None
    with pytest.raises(KeyError):
        dc['invalid']