From 0be3795eb452d9ef358b25b8cd1ceb271325bd5e Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 6 Jul 2018 13:08:34 -0700 Subject: [PATCH] Some pathutils fixes (#589) * Fix pathutil tests * Handle IndexError in pathutils --- ptvsd/pathutils.py | 8 +++++--- tests/ptvsd/test_pathutils.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ptvsd/pathutils.py b/ptvsd/pathutils.py index 01789892..ba4e13d9 100644 --- a/ptvsd/pathutils.py +++ b/ptvsd/pathutils.py @@ -54,9 +54,11 @@ class PathUnNormcase(object): else: test_name = [sep + dirs[0]] for d in dirs[1:]: - test_name += ["{}[{}]".format(d[: - 1], d[-1])] - path = glob(sep.join(test_name))[0] - res = glob(sep.join((path, filename))) + test_name += ["{}[{}]".format(d[:-1], d[-1])] + path = glob(sep.join(test_name)) + if not path: + return name + res = glob(sep.join((path[0], filename))) if not res: return name return res[0] diff --git a/tests/ptvsd/test_pathutils.py b/tests/ptvsd/test_pathutils.py index 3aab6fbe..88833c66 100644 --- a/tests/ptvsd/test_pathutils.py +++ b/tests/ptvsd/test_pathutils.py @@ -61,9 +61,12 @@ class PathUtilTests(unittest.TestCase): "Windows OS specific test") def test_path_names_uppercase_disabled(self): tool = PathUnNormcase() - result = tool.un_normcase(FILENAME.upper()) + expected = FILENAME.upper() + result = tool.un_normcase(expected) - self.assertEqual(result, FILENAME) + # Since path tool is disabled we should get the same + # path back + self.assertEqual(result, expected) @unittest.skipIf(platform.system() != 'Windows', "Windows OS specific test") @@ -78,9 +81,12 @@ class PathUtilTests(unittest.TestCase): "Windows OS specific test") def test_path_names_lowercase_disabled(self): tool = PathUnNormcase() - result = tool.un_normcase(FILENAME.lower()) + expected = FILENAME.lower() + result = tool.un_normcase(expected) - self.assertEqual(result, FILENAME) + # Since path tool is disabled we should get the same + # path back + self.assertEqual(result, expected) @unittest.skipIf(platform.system() != 'Windows', "Windows OS specific test")