-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom code directory #179
Changes from all commits
d283703
2ef58b4
6af4dd8
10c000f
2b89b90
251b1c3
3ceac85
62d6929
0f05aba
085d165
e53a946
23dd497
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ Carlos Pereira Atencio ([email protected]) | |
Nick Sarbicki ([email protected]) | ||
Kushal Das ([email protected]) | ||
Tibs / Tony Ibbs ([email protected]) | ||
Zander Brown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"theme": "night", "paths": ["path/foo.py", "path/bar.py"]} | ||
{"theme": "night", "paths": ["path/foo.py", "path/bar.py"], "workspace": "/home/foo/mycode"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"theme": "night", "paths": ["path/foo.py", "path/bar.py"]} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ def test_CONSTANTS(): | |
Ensure the expected constants exist. | ||
""" | ||
assert mu.logic.HOME_DIRECTORY | ||
assert mu.logic.PYTHON_DIRECTORY | ||
assert mu.logic.DATA_DIR | ||
assert mu.logic.WORKSPACE_NAME | ||
# These should NEVER change. | ||
assert mu.logic.MICROBIT_PID == 516 | ||
assert mu.logic.MICROBIT_VID == 3368 | ||
|
@@ -152,6 +152,21 @@ def test_get_settings_no_files(): | |
assert mock_json_dump.call_count == 1 | ||
|
||
|
||
def test_get_workspace(): | ||
""" | ||
Normally return generated folder otherwise user value | ||
""" | ||
should_be = os.path.join(mu.logic.HOME_DIRECTORY, | ||
mu.logic.WORKSPACE_NAME) | ||
with mock.patch('mu.logic.get_settings_path', | ||
return_value='tests/settingswithoutworkspace.json'): | ||
assert mu.logic.get_workspace_dir() == should_be | ||
# read from our demo settings.json | ||
with mock.patch('mu.logic.get_settings_path', | ||
return_value='tests/settings.json'): | ||
assert mu.logic.get_workspace_dir() == '/home/foo/mycode' | ||
|
||
|
||
def test_check_flake(): | ||
""" | ||
Ensure the check_flake method calls PyFlakes with the expected code | ||
|
@@ -303,8 +318,8 @@ def test_editor_init(): | |
assert e.repl is None | ||
assert e.theme == 'day' | ||
assert mkd.call_count == 2 | ||
assert mkd.call_args_list[0][0][0] == mu.logic.PYTHON_DIRECTORY | ||
assert mkd.call_args_list[1][0][0] == mu.logic.DATA_DIR | ||
assert mkd.call_args_list[0][0][0] == mu.logic.DATA_DIR | ||
assert mkd.call_args_list[1][0][0] == mu.logic.get_workspace_dir() | ||
|
||
|
||
def test_editor_restore_session(): | ||
|
@@ -543,7 +558,8 @@ def test_add_fs_no_repl(): | |
ed = mu.logic.Editor(view) | ||
with mock.patch('mu.logic.microfs.get_serial', return_value=True): | ||
ed.add_fs() | ||
view.add_filesystem.assert_called_once_with(home=mu.logic.PYTHON_DIRECTORY) | ||
workspace = mu.logic.get_workspace_dir() | ||
view.add_filesystem.assert_called_once_with(home=workspace) | ||
assert ed.fs | ||
|
||
|
||
|
@@ -905,9 +921,10 @@ def test_save_no_path(): | |
ed = mu.logic.Editor(view) | ||
with mock.patch('builtins.open', mock_open): | ||
ed.save() | ||
mock_open.assert_called_once_with('foo.py', 'w', newline='') | ||
assert mock_open.call_count == 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to explain this change: |
||
mock_open.assert_called_with('foo.py', 'w', newline='') | ||
mock_open.return_value.write.assert_called_once_with('foo') | ||
view.get_save_path.assert_called_once_with(mu.logic.PYTHON_DIRECTORY) | ||
view.get_save_path.assert_called_once_with(mu.logic.get_workspace_dir()) | ||
|
||
|
||
def test_save_no_path_no_path_given(): | ||
|
@@ -1101,7 +1118,7 @@ def test_quit_modified_ok(): | |
ed.quit(mock_event) | ||
assert view.show_confirmation.call_count == 1 | ||
assert mock_event.ignore.call_count == 0 | ||
assert mock_open.call_count == 1 | ||
assert mock_open.call_count == 2 | ||
assert mock_open.return_value.write.call_count > 0 | ||
|
||
|
||
|
@@ -1128,7 +1145,7 @@ def test_quit_save_tabs_with_paths(): | |
ed.quit(mock_event) | ||
assert view.show_confirmation.call_count == 1 | ||
assert mock_event.ignore.call_count == 0 | ||
assert mock_open.call_count == 1 | ||
assert mock_open.call_count == 2 | ||
assert mock_open.return_value.write.call_count > 0 | ||
recovered = ''.join([i[0][0] for i | ||
in mock_open.return_value.write.call_args_list]) | ||
|
@@ -1159,7 +1176,7 @@ def test_quit_save_theme(): | |
ed.quit(mock_event) | ||
assert view.show_confirmation.call_count == 1 | ||
assert mock_event.ignore.call_count == 0 | ||
assert mock_open.call_count == 1 | ||
assert mock_open.call_count == 2 | ||
assert mock_open.return_value.write.call_count > 0 | ||
recovered = ''.join([i[0][0] for i | ||
in mock_open.return_value.write.call_args_list]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly tests for this would be good.
Any suggestions of what & how?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Briefly (I have dad duty things taking up my time this evening, will reply more fully tomorrow AM), yes: ensure you set up the test with a settings file somewhere temporary and Mock away get_settings_path to return a path to this new temp settings file. Then test to your hearts' content. Does this make sense..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. unfortunately i may not be able to work on this again until tomorrow PM