def test_query_one_doc_in_index():
    index = InvertedIndex()
    index.inverted_index = defaultdict(set, {
        'foo': {1, 2, 3},
        'bar': {1},
        'foobar': {1, 2}
    })
    assert index.query(['foo', 'bar'
                        ]) == {1}, 'didnt find a doc, which present in index'
def test_dump_load_small_index():
    index = InvertedIndex()
    index.inverted_index = _SMALL_INDEX
    small_index_path = 'small.index'
    with open(small_index_path, 'wb') as fd:
        index.dump(fd)
    with open(small_index_path, 'rb') as fd:
        index.load(fd)
    assert index.inverted_index == _SMALL_INDEX, 'dumped and loaded index not the same'
def test_unicode_query_two_docs_in_index():
    index = InvertedIndex()
    index.inverted_index = defaultdict(set, {
        'один': {1, 2, 3},
        'bar': {1},
        'два': {1, 2}
    })
    assert index.query(['один', 'два']) == {
        1, 2
    }, 'didnt find a two docs, which are present in index with unicode'
def test_dump_small_index():
    index = InvertedIndex()
    index.inverted_index = _SMALL_INDEX
    small_index_path = 'small.index'
    index.dump(fd=open(small_index_path, 'wb'))
    assert os.path.getsize(small_index_path) > 0, 'build index with zero size'
def test_query_not_in_index():
    index = InvertedIndex()
    index.inverted_index = defaultdict(set, {'foo': {1, 2, 3}, 'bar': {1}})
    assert index.query(['foobar']) == set(), 'find a doc, that not in index'