From 657cb6ad6c390c6356db42d6114a9d00c5e1f0a5 Mon Sep 17 00:00:00 2001 From: "Bess L. Walker" Date: Sat, 25 Apr 2020 17:27:12 -0600 Subject: [PATCH] Substitute Python3-only code for Python 2.7-compatible code. --- gooey/gui/components/widgets/core/chooser.py | 6 ++---- gooey/tests/test_chooser_results.py | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gooey/gui/components/widgets/core/chooser.py b/gooey/gui/components/widgets/core/chooser.py index fea5db6..684fa10 100644 --- a/gooey/gui/components/widgets/core/chooser.py +++ b/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\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) diff --git a/gooey/tests/test_chooser_results.py b/gooey/tests/test_chooser_results.py index b59e083..fb86888 100644 --- a/gooey/tests/test_chooser_results.py +++ b/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()