mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-28 06:31:12 +03:00 
			
		
		
		
	issue5230 writer now checks instance of loc parameter before trying to operate on it
This commit is contained in:
		
							parent
							
								
									e1e25c7e30
								
							
						
					
					
						commit
						8c1d0d628f
					
				|  | @ -446,10 +446,10 @@ cdef class KnowledgeBase: | |||
| 
 | ||||
| cdef class Writer: | ||||
|     def __init__(self, object loc): | ||||
|         if path.exists(loc): | ||||
|             assert not path.isdir(loc), "%s is directory." % loc | ||||
|         if isinstance(loc, Path): | ||||
|             loc = bytes(loc) | ||||
|         if path.exists(loc): | ||||
|             assert not path.isdir(loc), "%s is directory." % loc | ||||
|         cdef bytes bytes_loc = loc.encode('utf8') if type(loc) == unicode else loc | ||||
|         self._fp = fopen(<char*>bytes_loc, 'wb') | ||||
|         if not self._fp: | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ from unittest import TestCase | |||
| import pytest | ||||
| import srsly | ||||
| from numpy import zeros | ||||
| from spacy.kb import KnowledgeBase | ||||
| from spacy.kb import KnowledgeBase, Writer | ||||
| from spacy.vectors import Vectors | ||||
| 
 | ||||
| from spacy.language import Language | ||||
|  | @ -101,6 +101,19 @@ def test_to_disk_resource_warning(obj): | |||
|     assert len(warnings_list) == 0 | ||||
| 
 | ||||
| 
 | ||||
| def test_writer_with_path_py35(): | ||||
|     writer = None | ||||
|     with make_tempdir() as d: | ||||
|         path = d / "test" | ||||
|         try: | ||||
|             writer = Writer(path) | ||||
|         except Exception as e: | ||||
|             pytest.fail(str(e)) | ||||
|         finally: | ||||
|             if writer: | ||||
|                 writer.close() | ||||
| 
 | ||||
| 
 | ||||
| class TestToDiskResourceWarningUnittest(TestCase): | ||||
|     def test_resource_warning(self): | ||||
|         scenarios = zip(*objects_to_test) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user