Commit bbb0aec6 authored by carlosperate's avatar carlosperate

Force normalised file/dir addressed in the server file/dir browser.

parent 529e9151
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import os
try: try:
# 2.x name # 2.x name
import Tkinter import Tkinter
...@@ -37,6 +38,9 @@ def browse_file_dialog(): ...@@ -37,6 +38,9 @@ def browse_file_dialog():
root.update() root.update()
file_path = tkFileDialog.askopenfilename() file_path = tkFileDialog.askopenfilename()
root.destroy() root.destroy()
if file_path:
return os.path.normpath(file_path)
else:
return file_path return file_path
...@@ -54,7 +58,10 @@ def browse_dir_dialog(): ...@@ -54,7 +58,10 @@ def browse_dir_dialog():
root.deiconify() root.deiconify()
root.lift() root.lift()
root.focus_force() root.focus_force()
file_path = tkFileDialog.askdirectory( dir_path = tkFileDialog.askdirectory(
parent=root, initialdir="/", title='Please select a directory') parent=root, initialdir="/", title='Please select a directory')
root.destroy() root.destroy()
return file_path if dir_path:
return os.path.normpath(dir_path)
else:
return dir_path
...@@ -29,10 +29,10 @@ class GuiTestCase(unittest.TestCase): ...@@ -29,10 +29,10 @@ class GuiTestCase(unittest.TestCase):
# #
# Tests for checking browsing for paths and files # Tests for checking browsing for paths and files
# #
@mock.patch('ardublocklyserver.gui.tkFileDialog') @mock.patch('ardublocklyserver.gui.tkFileDialog.askopenfilename')
def test_browse_file(self, mock_file_select): def test_browse_file(self, mock_file_select):
test_file = 'test_file' test_file = os.path.join(os.getcwd(), 'test_file')
mock_file_select.askopenfilename.return_value = test_file mock_file_select.return_value = test_file
new_file = gui.browse_file_dialog() new_file = gui.browse_file_dialog()
self.assertEqual(new_file, test_file) self.assertEqual(new_file, test_file)
...@@ -44,11 +44,11 @@ class GuiTestCase(unittest.TestCase): ...@@ -44,11 +44,11 @@ class GuiTestCase(unittest.TestCase):
function_file = gui.browse_file_dialog() function_file = gui.browse_file_dialog()
self.assertEqual(canceled_file, function_file) self.assertEqual(canceled_file, function_file)
@mock.patch('ardublocklyserver.gui.tkFileDialog') @mock.patch('ardublocklyserver.gui.tkFileDialog.askdirectory')
def test_browse_path(self, mock_path_select): def test_browse_path(self, mock_path_select):
test_path = 'test_path' test_path = os.path.join(os.getcwd(), 'test_path')
mock_path_select.askopenfilename.return_value = test_path mock_path_select.return_value = test_path
new_path = gui.browse_file_dialog() new_path = gui.browse_dir_dialog()
self.assertEqual(new_path, test_path) self.assertEqual(new_path, test_path)
def test_browse_path_cancel(self): def test_browse_path_cancel(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment