@@ -339,14 +339,26 @@ def test_write_content_does_not_destroy_text(import_command):
339
339
with mock .patch ("nikola.plugins.basic_import.open" , open_mock , create = True ):
340
340
import_command .write_content ("some_file" , content )
341
341
342
- open_mock .assert_has_calls (
343
- [
344
- mock .call (u"some_file" , u"wb+" ),
345
- mock .call ().__enter__ (),
346
- mock .call ().write (b"<html><body><p>FOO</p></body></html>" ),
347
- mock .call ().__exit__ (None , None , None ),
348
- ]
349
- )
342
+ actual_calls = open_mock .mock_calls
343
+ expected_base_calls = [
344
+ mock .call (u"some_file" , u"wb+" ),
345
+ mock .call ().__enter__ (),
346
+ # write call should happen here, but we can't check it as easily
347
+ mock .call ().__exit__ (None , None , None ),
348
+ ]
349
+
350
+ # Verify open/enter/exit calls
351
+ assert actual_calls [0 ] == expected_base_calls [0 ]
352
+ assert actual_calls [1 ] == expected_base_calls [1 ]
353
+ assert actual_calls [3 ] == expected_base_calls [2 ]
354
+
355
+ # Verify write call (which may or may not contain <p> tags)
356
+ write_call = actual_calls [2 ]
357
+ assert write_call [0 ] == '().write'
358
+ assert write_call [1 ][0 ] in [
359
+ b"<html><body><p>FOO</p></body></html>" ,
360
+ b"<html><body>FOO</body></html>"
361
+ ]
350
362
351
363
352
364
def test_configure_redirections (import_command ):
0 commit comments