@@ -27,9 +27,9 @@ def test_chunker_from_load_postprocessor():
2727 config_args = {"chunking_strategy" : "sentence" , "text_chunker_config" : {}}
2828 base_config = BasePostProcessorConfig (type = "chunker" , args = config_args )
2929 processor = load_postprocessor (base_config )
30- assert isinstance (
31- processor , MultimodalChunker
32- ), "Expected a MultimodalChunker instance."
30+ assert isinstance (processor , MultimodalChunker ), (
31+ "Expected a MultimodalChunker instance."
32+ )
3333
3434
3535def test_chunker_process ():
@@ -47,12 +47,12 @@ def test_chunker_process():
4747 chunks = chunker .process (sample )
4848 # Expect 2 chunks for the 2 sentences
4949 assert len (chunks ) == 2 , f"Expected 2 chunks, got { len (chunks )} "
50- assert (
51- chunks [0 ].text . strip () == "Hello world. "
52- ), f"Unexpected first chunk: { chunks [ 0 ]. text } "
53- assert (
54- chunks [1 ].text . strip () == "This is a test. "
55- ), f"Unexpected second chunk: { chunks [ 1 ]. text } "
50+ assert chunks [ 0 ]. text . strip () == "Hello world." , (
51+ f"Unexpected first chunk: { chunks [0 ].text } "
52+ )
53+ assert chunks [ 1 ]. text . strip () == "This is a test." , (
54+ f"Unexpected second chunk: { chunks [1 ].text } "
55+ )
5656
5757
5858# ------------------ Filter Tests ------------------
@@ -117,16 +117,16 @@ def filter(self, sample: MultimodalSample) -> bool:
117117 accept_filter = DummyAcceptFilter ("dummy_accept" )
118118 accepted = accept_filter .process (sample )
119119 # When filter returns True, process() should return the sample wrapped in a list.
120- assert accepted == [
121- sample
122- ], f"Expected sample to be kept when filter returns True, got { accepted } "
120+ assert accepted == [sample ], (
121+ f"Expected sample to be kept when filter returns True, got { accepted } "
122+ )
123123
124124 reject_filter = DummyRejectFilter ("dummy_reject" )
125125 rejected = reject_filter .process (sample )
126126 # When filter returns False, process() should return an empty list.
127- assert (
128- rejected == []
129- ), f"Expected sample to be rejected when filter returns False, got { rejected } "
127+ assert rejected == [], (
128+ f"Expected sample to be rejected when filter returns False, got { rejected } "
129+ )
130130
131131
132132# ------------------ NER Tests ------------------
@@ -147,9 +147,7 @@ def test_ner_from_config():
147147 """
148148 # Patch LLM.from_config to return our dummy LLM regardless of input.
149149 original_llm_from_config = LLM .from_config
150- LLM .from_config = (
151- lambda cfg : DummyLLM ()
152- ) # pyright: ignore[reportAttributeAccessIssue]
150+ LLM .from_config = lambda cfg : DummyLLM () # pyright: ignore[reportAttributeAccessIssue]
153151
154152 config = NERExtractorConfig (
155153 llm = LLMConfig ("dummy" ), # dummy config; our lambda ignores it
@@ -174,9 +172,7 @@ def test_ner_process():
174172 which should add to the sample's metadata a list with one dictionary.
175173 """
176174 original_llm_from_config = LLM .from_config
177- LLM .from_config = (
178- lambda cfg : DummyLLM ()
179- ) # pyright: ignore[reportAttributeAccessIssue]
175+ LLM .from_config = lambda cfg : DummyLLM () # pyright: ignore[reportAttributeAccessIssue]
180176
181177 config = NERExtractorConfig (
182178 llm = LLMConfig ("dummy" ),
@@ -204,15 +200,15 @@ def test_ner_process():
204200 # We expect one entity: HELLO WORLD as an ORGANIZATION with the given description.
205201 assert len (ner_entities ) == 1 , f"Expected 1 entity, got { len (ner_entities )} ."
206202 entity_info : dict [str , str ] = ner_entities [0 ]
207- assert (
208- entity_info .get (" entity" ) == "HELLO WORLD "
209- ), f"Unexpected entity name: { entity_info . get ( 'entity' ) } "
210- assert (
211- entity_info .get (" type" ) == "ORGANIZATION "
212- ), f"Unexpected entity type: { entity_info . get ( 'type' ) } "
213- assert entity_info .get ("description" ) == [
214- "A SAMPLE ORGANIZATION "
215- ], f"Unexpected entity description: { entity_info . get ( 'description' ) } "
203+ assert entity_info . get ( "entity" ) == "HELLO WORLD" , (
204+ f"Unexpected entity name: { entity_info .get (' entity' ) } "
205+ )
206+ assert entity_info . get ( "type" ) == "ORGANIZATION" , (
207+ f"Unexpected entity type: { entity_info .get (' type' ) } "
208+ )
209+ assert entity_info .get ("description" ) == ["A SAMPLE ORGANIZATION" ], (
210+ f"Unexpected entity description: { entity_info . get ( 'description' ) } "
211+ )
216212
217213 # Restore the original LLM.from_config
218214 LLM .from_config = original_llm_from_config
@@ -253,9 +249,9 @@ def test_tagger_from_load_tagger_modalities():
253249 """
254250 config = BaseTaggerConfig (type = "modalities_counter" , args = {})
255251 tagger = load_tagger (config )
256- assert isinstance (
257- tagger , ModalitiesCounter
258- ), "Expected a ModalitiesCounter instance."
252+ assert isinstance (tagger , ModalitiesCounter ), (
253+ "Expected a ModalitiesCounter instance."
254+ )
259255
260256
261257def test_tagger_from_load_tagger_lang_detector ():
@@ -292,9 +288,9 @@ def test_tagger_process_words_counter():
292288 processed = tagger .process (sample )
293289 expected_count = len (sample .text .split ())
294290 # WordsCounter's default metadata_key is set in its __init__ to 'word_count'
295- assert (
296- sample .metadata .get (" word_count" ) == expected_count
297- ), f"Expected word_count { expected_count } , got { sample . metadata . get ( 'word_count' ) } "
291+ assert sample . metadata . get ( "word_count" ) == expected_count , (
292+ f"Expected word_count { expected_count } , got { sample .metadata .get (' word_count' ) } "
293+ )
298294 assert isinstance (processed , list ), "Expected process() to return a list."
299295
300296
@@ -318,9 +314,9 @@ def test_tagger_process_modalities_counter():
318314 processed = tagger .process (sample )
319315 expected_count = len (sample .modalities )
320316 # ModalitiesCounter's default metadata_key is 'modalities_count'
321- assert (
322- sample .metadata .get (" modalities_count" ) == expected_count
323- ), f"Expected modalities_count { expected_count } , got { sample . metadata . get ( 'modalities_count' ) } "
317+ assert sample . metadata . get ( "modalities_count" ) == expected_count , (
318+ f"Expected modalities_count { expected_count } , got { sample .metadata .get (' modalities_count' ) } "
319+ )
324320 assert isinstance (processed , list ), "Expected process() to return a list."
325321
326322
0 commit comments