From 168b2b8cb283cc0b3226f182a5649664607bf7c2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 23 Oct 2014 20:47:06 +1100 Subject: [PATCH] * Add tests for string intern --- tests/test_intern.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_intern.py diff --git a/tests/test_intern.py b/tests/test_intern.py new file mode 100644 index 000000000..63b4b3433 --- /dev/null +++ b/tests/test_intern.py @@ -0,0 +1,35 @@ +# -*- coding: utf8 -*- +from __future__ import unicode_literals + +from spacy.utf8string import StringStore + +import pytest + +@pytest.fixture +def sstore(): + return StringStore() + +def test_save_bytes(sstore): + Hello_i = sstore[b'Hello'] + assert Hello_i == 1 + assert sstore[b'Hello'] == 1 + assert sstore[b'goodbye'] != Hello_i + assert sstore[b'hello'] != Hello_i + assert Hello_i == 1 + + +def test_save_unicode(sstore): + with pytest.raises(TypeError): + A_i = sstore['A'] + + +def test_zero_id(sstore): + with pytest.raises(IndexError): + sstore[0] + +def test_retrieve_id(sstore): + A_i = sstore[b'A'] + assert sstore.size == 1 + assert sstore[1] == b'A' + with pytest.raises(IndexError): + sstore[2]