Skip to content

Commit e09ea79

Browse files
committed
Fix flaky/platform-dependent test
1 parent c7b0e3a commit e09ea79

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tests/test_command_import_wordpress.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,26 @@ def test_write_content_does_not_destroy_text(import_command):
339339
with mock.patch("nikola.plugins.basic_import.open", open_mock, create=True):
340340
import_command.write_content("some_file", content)
341341

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+
]
350362

351363

352364
def test_configure_redirections(import_command):

0 commit comments

Comments
 (0)