8000 Fix asserts for called_once_with() (#2448) · ag-python-qt/mu-pyqt@3776e0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3776e0c

Browse files
Fix asserts for called_once_with() (mu-editor#2448)
As some of the mocks are not Autospecced, any call to a method that don't exists will succed. The called_once_with() methods are not real asserts, so they have to be replaced with assert_called_once_with(). --------- Co-authored-by: Carlos Pereira Atencio <4189262+carlosperate@users.noreply.github.com>
1 parent 5a6b462 commit 3776e0c

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

tests/modes/test_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_debug_start():
5757
"mu.modes.debugger.Debugger", mock_debugger_class
5858
), mock.patch.object(venv, "interpreter", "interpreter"):
5959
dm.start()
60-
editor.save_tab_to_file.called_once_with(view.current_tab)
60+
editor.save_tab_to_file.assert_called_once_with(view.current_tab)
6161
view.add_python3_runner.assert_called_once_with(
6262
"interpreter",
6363
"/foo/bar",

tests/modes/test_pygamezero.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_pgzero_run_game():
126126
with mock.patch.object(venv, "interpreter", "interpreter"):
127127
pm.run_game()
128128

129-
editor.save_tab_to_file.called_once_with(view.current_tab)
129+
editor.save_tab_to_file.assert_called_once_with(view.current_tab)
130130
view.add_python3_runner.assert_called_once_with(
131131
interpreter="interpreter",
132132
script_name="/foo/bar",

tests/test_logic.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def test_editor_restore_session_existing_runtime():
893893
assert ed.minify is False
894894
assert ed.microbit_runtime == "/foo"
895895
assert ed._view.zoom_position == 5
896-
assert venv_relocate.called_with("foo")
896+
venv_relocate.assert_called_with("foo")
897897

898898

899899
def test_editor_restore_session_missing_runtime():
@@ -1069,7 +1069,7 @@ def test_editor_open_focus_passed_file():
10691069
with generate_session():
10701070
ed.restore_session(paths=[filepath])
10711071

1072-
assert ed.direct_load.called_with(filepath)
1072+
ed.direct_load.assert_called_with(os.path.abspath(filepath))
10731073

10741074

10751075
def test_editor_session_and_open_focus_passed_file():
@@ -1439,12 +1439,12 @@ def test_load_stores_newline():
14391439
newline = "r\n"
14401440
text = newline.join("the cat sat on the mat".split())
14411441
editor = mocked_editor()
1442-
with generate_python_file("abc\r\ndef") as filepath:
1442+
with generate_python_file(text) as filepath:
14431443
editor._view.get_load_path.return_value = filepath
14441444
editor.load()
14451445

1446-
assert editor._view.add_tab.called_with(
1447-
filepath, text, editor.modes[editor.mode].api(), "\r\n"
1446+
editor._view.add_tab.assert_called_with(
1447+
filepath, text, editor.modes[editor.mode].api(), "\n"
14481448
)
14491449

14501450

@@ -1459,7 +1459,7 @@ def test_save_restores_newline():
14591459
with mock.patch("mu.logic.save_and_encode") as mock_save:
14601460
ed = mocked_editor(text=test_text, newline=newline, path=filepath)
14611461
ed.save()
1462-
assert mock_save.called_with(test_text, filepath, newline)
1462+
mock_save.assert_called_with(test_text, filepath, newline)
14631463

14641464

14651465
def test_save_strips_trailing_spaces():
@@ -2524,7 +2524,7 @@ def test_change_mode_workspace_dir_exception():
25242524
ed.change_mode("circuitpython")
25252525
assert mock_error.call_count == 1
25262526
assert ed.mode == "circuitpython"
2527-
assert python_mode.workspace_dir.called_once()
2527+
python_mode.workspace_dir.assert_called_once_with()
25282528

25292529

25302530
def test_autosave():

tests/test_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def test_save_only_changed(mocked_open):
246246
settings.as_string = mock.Mock(return_value=rstring())
247247
settings.save()
248248

249-
assert settings.as_string.called_with(changed_only=True)
250-
assert mocked_open.called_with(settings.filepath, "w")
249+
settings.as_string.assert_called_with(changed_only=True)
250+
mocked_open.assert_called_with(settings.filepath, "w", encoding="utf-8")
251251

252252

253253
@patch.object(mu.settings, "logger")

0 commit comments

Comments
 (0)
0