From a9d2a6869b6a75f7a77061c8691357a8920f9022 2020-02-11 23:33:11 From: Inception95 Date: 2020-02-11 23:33:11 Subject: [PATCH] Pop the last if path ends with slash --- diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index 4f21cb0..cda2697 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -42,6 +42,7 @@ def _elide(string, *, min_elide=30): object_parts = string.split('.') file_parts = string.split(os.sep) + file_parts.pop() if file_parts[-1] == '' else None if len(object_parts) > 3: return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(object_parts[0], object_parts[1][0], object_parts[-2][-1], object_parts[-1]) diff --git a/IPython/terminal/tests/test_interactivshell.py b/IPython/terminal/tests/test_interactivshell.py index 9651a22..6bacc8e 100644 --- a/IPython/terminal/tests/test_interactivshell.py +++ b/IPython/terminal/tests/test_interactivshell.py @@ -5,6 +5,7 @@ import sys import unittest +import os from IPython.core.inputtransformer import InputTransformer from IPython.testing import tools as tt @@ -19,6 +20,10 @@ class TestElide(unittest.TestCase): _elide('concatenate((a1, a2, ...), axis') # do not raise _elide('concatenate((a1, a2, ..), . axis') # do not raise nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh'), 'aaaa.b…g.hhhhhh') + + test_string = os.sep.join(['', 10*'a', 10*'b', 10*'c', '']) + expect_stirng = os.sep + 'a' + '\N{HORIZONTAL ELLIPSIS}' + 'b' + os.sep + 10*'c' + nt.assert_equal(_elide(test_string), expect_stirng) class TestContextAwareCompletion(unittest.TestCase):