mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-31 16:07:41 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # coding: utf-8
 | |
| from __future__ import unicode_literals
 | |
| 
 | |
| from ...strings import StringStore
 | |
| 
 | |
| import pytest
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('text1,text2,text3', [(b'Hello', b'goodbye', b'hello')])
 | |
| def test_stringstore_save_bytes(stringstore, text1, text2, text3):
 | |
|     i = stringstore[text1]
 | |
|     assert i == 1
 | |
|     assert stringstore[text1] == 1
 | |
|     assert stringstore[text2] != i
 | |
|     assert stringstore[text3] != i
 | |
|     assert i == 1
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('text1,text2,text3', [('Hello', 'goodbye', 'hello')])
 | |
| def test_stringstore_save_unicode(stringstore, text1, text2, text3):
 | |
|     i = stringstore[text1]
 | |
|     assert i == 1
 | |
|     assert stringstore[text1] == 1
 | |
|     assert stringstore[text2] != i
 | |
|     assert stringstore[text3] != i
 | |
|     assert i == 1
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('text', [b'A'])
 | |
| def test_stringstore_retrieve_id(stringstore, text):
 | |
|     i = stringstore[text]
 | |
|     assert stringstore.size == 1
 | |
|     assert stringstore[1] == text.decode('utf8')
 | |
|     with pytest.raises(IndexError):
 | |
|         stringstore[2]
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('text1,text2', [(b'0123456789', b'A')])
 | |
| def test_stringstore_med_string(stringstore, text1, text2):
 | |
|     store = stringstore[text1]
 | |
|     assert stringstore[store] == text1.decode('utf8')
 | |
|     dummy = stringstore[text2]
 | |
|     assert stringstore[text1] == store
 | |
| 
 | |
| 
 | |
| def test_stringstore_long_string(stringstore):
 | |
|     text = "INFORMATIVE](http://www.google.com/search?as_q=RedditMonkey&hl=en&num=50&btnG=Google+Search&as_epq=&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=&as_qdr=all&as_nlo=&as_nhi=&as_occt=any&as_dt=i&as_sitesearch=&as_rights=&safe=off"
 | |
|     store = stringstore[text]
 | |
|     assert stringstore[store] == text
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('factor', [254, 255, 256])
 | |
| def test_stringstore_multiply(stringstore, factor):
 | |
|     text = 'a' * factor
 | |
|     store = stringstore[text]
 | |
|     assert stringstore[store] == text
 | |
| 
 | |
| 
 | |
| def test_stringstore_massive_strings(stringstore):
 | |
|     text = 'a' * 511
 | |
|     store = stringstore[text]
 | |
|     assert stringstore[store] == text
 | |
|     text2 = 'z' * 512
 | |
|     store = stringstore[text2]
 | |
|     assert stringstore[store] == text2
 | |
|     text3 = '1' * 513
 | |
|     store = stringstore[text3]
 | |
|     assert stringstore[store] == text3
 | |
| 
 | |
| 
 | |
| @pytest.mark.parametrize('text', ["qqqqq"])
 | |
| def test_stringstore_to_bytes(stringstore, text):
 | |
|     store = stringstore[text]
 | |
|     serialized = stringstore.to_bytes()
 | |
|     new_stringstore = StringStore().from_bytes(serialized)
 | |
|     assert new_stringstore[store] == text
 |