Browse Source

Substitute Python3-only code for Python 2.7-compatible code.

pull/575/head
Bess L. Walker 4 years ago
committed by Chris
parent
commit
657cb6ad6c
2 changed files with 15 additions and 11 deletions
  1. 6
      gooey/gui/components/widgets/core/chooser.py
  2. 20
      gooey/tests/test_chooser_results.py

6
gooey/gui/components/widgets/core/chooser.py

@ -1,7 +1,6 @@
import wx
import wx.lib.agw.multidirdialog as MDD
import os
import pathlib
import re
from gooey.gui.components.widgets.core.text_input import TextInput
@ -123,11 +122,10 @@ class MultiDirChooser(Chooser):
if 'nt' == os.name:
for i, path in enumerate(paths):
if path:
purepath = pathlib.PurePath(path)
parts = purepath.parts
parts = path.split(os.sep)
vol = parts[0]
drives = re.match(r'.*\((?P<drive>\w:)\)', vol)
paths[i] = os.sep.join((drives.group('drive'),) + parts[1:])
paths[i] = os.sep.join([drives.group('drive')] + parts[1:])
return os.pathsep.join(paths)

20
gooey/tests/test_chooser_results.py

@ -2,14 +2,15 @@ import argparse
import os
import unittest
from unittest.mock import patch
from gooey.gui.components.widgets.core import chooser
class TestChooserResults(unittest.TestCase):
class MockWxMDD:
def GetPaths(self):
pass
@patch('gooey.gui.components.widgets.core.chooser.MDD')
def test_multiDirChooserGetResult(self, mockWxMDD):
class TestChooserResults(unittest.TestCase):
def test_multiDirChooserGetResult(self):
expected_outputs = [
(None, "", [""]),
@ -23,7 +24,12 @@ class TestChooserResults(unittest.TestCase):
]
for osname, expected, pathsoutput in expected_outputs:
if osname and osname == os.name:
mockWxMDD.GetPaths.return_value = pathsoutput
result = chooser.MultiDirChooser.getResult(None, mockWxMDD)
if not osname or osname == os.name:
chooser.MDD.MultiDirDialog = MockWxMDD
chooser.MDD.MultiDirDialog.GetPaths = lambda self : pathsoutput
result = chooser.MultiDirChooser.getResult(None, MockWxMDD())
print(result)
self.assertEqual(result, expected)
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save