From 804dbb8d258c2c5e58c0b7fcdff21c68d818706a Mon Sep 17 00:00:00 2001 From: ines Date: Mon, 29 May 2017 01:05:53 +0200 Subject: [PATCH] Add StringStore test for API docs --- spacy/tests/stringstore/test_stringstore.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spacy/tests/stringstore/test_stringstore.py b/spacy/tests/stringstore/test_stringstore.py index 228f69b53..65b994606 100644 --- a/spacy/tests/stringstore/test_stringstore.py +++ b/spacy/tests/stringstore/test_stringstore.py @@ -6,6 +6,25 @@ from ...strings import StringStore import pytest +def test_stringstore_from_api_docs(stringstore): + apple_hash = stringstore.add('apple') + assert apple_hash == 8566208034543834098 + assert stringstore[apple_hash] == u'apple' + + assert u'apple' in stringstore + assert u'cherry' not in stringstore + + orange_hash = stringstore.add('orange') + all_strings = [s for s in stringstore] + assert all_strings == [u'apple', u'orange'] + + banana_hash = stringstore.add('banana') + assert len(stringstore) == 3 + assert banana_hash == 2525716904149915114 + assert stringstore[banana_hash] == u'banana' + assert stringstore[u'banana'] == banana_hash + + @pytest.mark.parametrize('text1,text2,text3', [(b'Hello', b'goodbye', b'hello')]) def test_stringstore_save_bytes(stringstore, text1, text2, text3): key = stringstore.add(text1)