Пример #1
0
def test_index_key_flip(fcstore):
    # Make sure only values from the specified index are returned.
    fca, fcb = FC(), FC()
    fca[u'a']['foo'] = 1
    fca[u'b']['foo'] = 1

    fcstore.define_index(u'a', feature_index('a'),
                         lambda s: s.lower().encode('utf-8'))
    fcstore.define_index(u'b', feature_index('b'),
                         lambda s: s.lower().encode('utf-8'))

    fcstore.put([('fca', fca), ('fcb', fcb)])

    assert list(fcstore.index_scan(u'a', u'foo')) == ['fca']
Пример #2
0
def test_index_key_flip(fcstore):
    # Make sure only values from the specified index are returned.
    fca, fcb = FC(), FC()
    fca[u'a']['foo'] = 1
    fca[u'b']['foo'] = 1

    fcstore.define_index(
            u'a', feature_index('a'), lambda s: s.lower().encode('utf-8'))
    fcstore.define_index(
            u'b', feature_index('b'), lambda s: s.lower().encode('utf-8'))

    fcstore.put([('fca', fca), ('fcb', fcb)])

    assert list(fcstore.index_scan(u'a', u'foo')) == ['fca']
Пример #3
0
def test_fcs_index_only_canonical(fcstore):
    fcstore.define_index(u'NAME', feature_index('canonical_name'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=True)
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert len(list(fcstore.index_scan(u'NAME', 'bAz'))) == 0
Пример #4
0
def test_fcs_bad_unicode_index(fcstore):
    fcstore.define_index(u'NAME',
                         feature_index('NAME'),
                         lambda s: unicode(s.lower()))
    feata = mk_fc_names('foo', 'baz')
    with pytest.raises(kvlayer.BadKey):
        fcstore.put([('a', feata)], indexes=True)
Пример #5
0
def test_fcs_index_only_canonical(fcstore):
    fcstore.define_index(u'NAME',
                         feature_index('canonical_name'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=True)
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert len(list(fcstore.index_scan(u'NAME', 'bAz'))) == 0
Пример #6
0
def test_fcs_index(fcstore):
    fcstore.define_index(u'NAME', feature_index('NAME'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=True)
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert list(fcstore.index_scan(u'NAME', 'bAz'))[0] == 'a'
    assert list(fcstore.index_scan_prefix(u'NAME', 'b'))[0] == 'a'
    assert list(fcstore.index_scan_prefix_and_return_key(u'NAME', 'bA'))[0] \
        == ('baz', 'a')
Пример #7
0
def test_fcs_index(fcstore):
    fcstore.define_index(u'NAME',
                         feature_index('NAME'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=True)
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert list(fcstore.index_scan(u'NAME', 'bAz'))[0] == 'a'
    assert list(fcstore.index_scan_prefix(u'NAME', 'b'))[0] == 'a'
    assert list(fcstore.index_scan_prefix_and_return_key(u'NAME', 'bA'))[0] \
        == ('baz', 'a')
Пример #8
0
def test_fcs_index_raw(fcstore):
    fcstore.define_index(u'NAME', feature_index('NAME'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=False)

    assert len(list(fcstore.index_scan(u'NAME', 'FoO'))) == 0
    assert len(list(fcstore.index_scan(u'NAME', 'bAz'))) == 0

    fcstore._index_put_raw(u'NAME', 'a', 'foo')
    fcstore._index_put_raw(u'NAME', 'a', 'baz')
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert list(fcstore.index_scan(u'NAME', 'bAz'))[0] == 'a'
    assert list(fcstore.index_scan_prefix(u'NAME', 'b'))[0] == 'a'
Пример #9
0
def test_fcs_index_raw(fcstore):
    fcstore.define_index(u'NAME',
                         feature_index('NAME'),
                         lambda s: s.lower().encode('utf-8'))
    feata = mk_fc_names('foo', 'baz')
    fcstore.put([('a', feata)], indexes=False)

    assert len(list(fcstore.index_scan(u'NAME', 'FoO'))) == 0
    assert len(list(fcstore.index_scan(u'NAME', 'bAz'))) == 0

    fcstore._index_put_raw(u'NAME', 'a', 'foo')
    fcstore._index_put_raw(u'NAME', 'a', 'baz')
    assert list(fcstore.index_scan(u'NAME', 'FoO'))[0] == 'a'
    assert list(fcstore.index_scan(u'NAME', 'bAz'))[0] == 'a'
    assert list(fcstore.index_scan_prefix(u'NAME', 'b'))[0] == 'a'
Пример #10
0
def test_fcs_bad_unicode_index(fcstore):
    fcstore.define_index(u'NAME', feature_index('NAME'),
                         lambda s: unicode(s.lower()))
    feata = mk_fc_names('foo', 'baz')
    with pytest.raises(kvlayer.BadKey):
        fcstore.put([('a', feata)], indexes=True)