@@ -42,14 +42,19 @@ def setUp(self):
4242 # Mock the _get_settings() method
4343 self .settings_obj = mock .MagicMock ()
4444 self .patcher = mock .patch .object (
45- document_processor .DocumentProcessor , "_get_settings" )
45+ document_processor .DocumentProcessor , "_get_settings"
46+ )
4647 self ._settings = self .patcher .start ()
4748 self ._settings .return_value = self .settings_obj
4849 self .addCleanup (self .patcher .stop )
4950
5051 self .doc_processor = document_processor .DocumentProcessor (
51- self .chunk_size , self .chunk_overlap , self .model_name ,
52- self .embeddings_model_dir , self .num_workers )
52+ self .chunk_size ,
53+ self .chunk_overlap ,
54+ self .model_name ,
55+ self .embeddings_model_dir ,
56+ self .num_workers ,
57+ )
5358
5459 def test__got_whitespace_false (self ):
5560 text = "NoWhitespace"
@@ -72,7 +77,8 @@ def test__filter_out_invalid_nodes(self):
7277 fake_node_1 .text = "NoWhitespace"
7378
7479 result = self .doc_processor ._filter_out_invalid_nodes (
75- [fake_node_0 , fake_node_1 ])
80+ [fake_node_0 , fake_node_1 ]
81+ )
7682
7783 # Only nodes with whitespaces should be returned
7884 self .assertEqual ([fake_node_0 ], result )
@@ -85,7 +91,8 @@ def test__save_index(self, mock_vector_index):
8591
8692 fake_index .set_index_id .assert_called_once_with ("fake-index" )
8793 fake_index .storage_context .persist .assert_called_once_with (
88- persist_dir = "/fake/path" )
94+ persist_dir = "/fake/path"
95+ )
8996
9097 @mock .patch .object (document_processor .json , "dumps" )
9198 @mock .patch ("builtins.open" , new_callable = mock .mock_open )
@@ -102,7 +109,7 @@ def test__save_metadata(self, mock_file, mock_dumps):
102109 "embedding-dimension" : mock .ANY ,
103110 "chunk" : self .chunk_size ,
104111 "overlap" : self .chunk_overlap ,
105- "total-embedded-files" : 0
112+ "total-embedded-files" : 0 ,
106113 }
107114 mock_dumps .assert_called_once_with (expected_dict )
108115
@@ -114,7 +121,8 @@ def test_process(self, mock_dir_reader):
114121 fake_good_nodes = [mock .Mock (), mock .Mock ()]
115122
116123 with mock .patch .object (
117- self .doc_processor , '_filter_out_invalid_nodes' ) as mock_filter :
124+ self .doc_processor , "_filter_out_invalid_nodes"
125+ ) as mock_filter :
118126 mock_filter .return_value = fake_good_nodes
119127 self .doc_processor .process ("/fake/path/docs" , fake_metadata )
120128
@@ -132,27 +140,45 @@ def test_save(self):
132140 mock_index .assert_called_once_with ("fake-index" , "/fake/output_dir" )
133141 mock_md .assert_called_once_with ("fake-index" , "/fake/output_dir" )
134142
135- @mock .patch .dict (os .environ , {
136- "POSTGRES_USER" : "postgres" ,
137- "POSTGRES_PASSWORD" : "somesecret" ,
138- "POSTGRES_HOST" : "localhost" ,
139- "POSTGRES_PORT" : "15432" ,
140- "POSTGRES_DATABASE" : "postgres" ,
141- })
142- @mock .patch ("lightspeed_rag_content.document_processor.HuggingFaceEmbedding" , new = MockEmbedding )
143+ @mock .patch .dict (
144+ os .environ ,
145+ {
146+ "POSTGRES_USER" : "postgres" ,
147+ "POSTGRES_PASSWORD" : "somesecret" ,
148+ "POSTGRES_HOST" : "localhost" ,
149+ "POSTGRES_PORT" : "15432" ,
150+ "POSTGRES_DATABASE" : "postgres" ,
151+ },
152+ )
153+ @mock .patch (
154+ "lightspeed_rag_content.document_processor.HuggingFaceEmbedding" ,
155+ new = MockEmbedding ,
156+ )
143157 def test_pgvector (self ):
144158 self .patcher .stop () # Remove the mock on the _get_settings() method
145159 self .doc_processor = document_processor .DocumentProcessor (
146- self .chunk_size , self .chunk_overlap , self .model_name ,
147- self .embeddings_model_dir , self .num_workers ,
148- "postgres" )
160+ self .chunk_size ,
161+ self .chunk_overlap ,
162+ self .model_name ,
163+ self .embeddings_model_dir ,
164+ self .num_workers ,
165+ "postgres" ,
166+ )
149167 self .assertIsNotNone (self .doc_processor )
150168
151- @mock .patch ("lightspeed_rag_content.document_processor.HuggingFaceEmbedding" , new = MockEmbedding )
169+ @mock .patch (
170+ "lightspeed_rag_content.document_processor.HuggingFaceEmbedding" ,
171+ new = MockEmbedding ,
172+ )
152173 def test_invalid_vector_store_type (self ):
153174 self .patcher .stop () # Remove the mock on the _get_settings() method
154- self .assertRaises (RuntimeError ,
175+ self .assertRaises (
176+ RuntimeError ,
155177 document_processor .DocumentProcessor ,
156- self .chunk_size , self .chunk_overlap , self .model_name ,
157- self .embeddings_model_dir , self .num_workers ,
158- "nonexisting" )
178+ self .chunk_size ,
179+ self .chunk_overlap ,
180+ self .model_name ,
181+ self .embeddings_model_dir ,
182+ self .num_workers ,
183+ "nonexisting" ,
184+ )
0 commit comments