##// END OF EJS Templates
Fix a couple of edge cases, and update tests...
Matthias Bussonnier -
Show More
@@ -38,7 +38,7 b' install:'
38 - pip install setuptools --upgrade
38 - pip install setuptools --upgrade
39 - pip install -e file://$PWD#egg=ipython[test] --upgrade
39 - pip install -e file://$PWD#egg=ipython[test] --upgrade
40 - pip install trio curio --upgrade --upgrade-strategy eager
40 - pip install trio curio --upgrade --upgrade-strategy eager
41 - pip install pytest 'matplotlib !=3.2.0'
41 - pip install pytest 'matplotlib !=3.2.0' mypy
42 - pip install codecov check-manifest --upgrade
42 - pip install codecov check-manifest --upgrade
43
43
44 script:
44 script:
@@ -50,6 +50,7 b' script:'
50 fi
50 fi
51 - cd /tmp && iptest --coverage xml && cd -
51 - cd /tmp && iptest --coverage xml && cd -
52 - pytest IPython
52 - pytest IPython
53 - mypy --ignore-missing-imports -m IPython.terminal.ptutils
53 # On the latest Python (on Linux) only, make sure that the docs build.
54 # On the latest Python (on Linux) only, make sure that the docs build.
54 - |
55 - |
55 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
56 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
@@ -23,7 +23,7 b' import os'
23
23
24 _completion_sentinel = object()
24 _completion_sentinel = object()
25
25
26 def _elide_point(string, *, min_elide=30):
26 def _elide_point(string:str, *, min_elide=30)->str:
27 """
27 """
28 If a string is long enough, and has at least 3 dots,
28 If a string is long enough, and has at least 3 dots,
29 replace the middle part with ellipses.
29 replace the middle part with ellipses.
@@ -53,7 +53,7 b' def _elide_point(string, *, min_elide=30):'
53
53
54 return string
54 return string
55
55
56 def _elide_typed(string, typed, *, min_elide=30):
56 def _elide_typed(string:str, typed:str, *, min_elide:int=30)->str:
57 """
57 """
58 Elide the middle of a long string if the beginning has already been typed.
58 Elide the middle of a long string if the beginning has already been typed.
59 """
59 """
@@ -61,11 +61,13 b' def _elide_typed(string, typed, *, min_elide=30):'
61 if len(string) < min_elide:
61 if len(string) < min_elide:
62 return string
62 return string
63 cut_how_much = len(typed)-3
63 cut_how_much = len(typed)-3
64 if cut_how_much < 7:
65 return string
64 if string.startswith(typed) and len(string)> len(typed):
66 if string.startswith(typed) and len(string)> len(typed):
65 return f"{string[:3]}\N{HORIZONTAL ELLIPSIS}{string[cut_how_much:]}"
67 return f"{string[:3]}\N{HORIZONTAL ELLIPSIS}{string[cut_how_much:]}"
66 return string
68 return string
67
69
68 def _elide(string, typed, min_elide=30):
70 def _elide(string:str, typed:str, min_elide=30)->str:
69 return _elide_typed(
71 return _elide_typed(
70 _elide_point(string, min_elide=min_elide),
72 _elide_point(string, min_elide=min_elide),
71 typed, min_elide=min_elide)
73 typed, min_elide=min_elide)
@@ -17,14 +17,32 b' import nose.tools as nt'
17 class TestElide(unittest.TestCase):
17 class TestElide(unittest.TestCase):
18
18
19 def test_elide(self):
19 def test_elide(self):
20 _elide('concatenate((a1, a2, ...), axis') # do not raise
20 _elide('concatenate((a1, a2, ...), axis', '') # do not raise
21 _elide('concatenate((a1, a2, ..), . axis') # do not raise
21 _elide('concatenate((a1, a2, ..), . axis', '') # do not raise
22 nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh'), 'aaaa.b…g.hhhhhh')
22 nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh',''), 'aaaa.b…g.hhhhhh')
23
23
24 test_string = os.sep.join(['', 10*'a', 10*'b', 10*'c', ''])
24 test_string = os.sep.join(['', 10*'a', 10*'b', 10*'c', ''])
25 expect_stirng = os.sep + 'a' + '\N{HORIZONTAL ELLIPSIS}' + 'b' + os.sep + 10*'c'
25 expect_stirng = os.sep + 'a' + '\N{HORIZONTAL ELLIPSIS}' + 'b' + os.sep + 10*'c'
26 nt.assert_equal(_elide(test_string), expect_stirng)
26 nt.assert_equal(_elide(test_string, ''), expect_stirng)
27
27
28 def test_elide_typed_normal(self):
29 nt.assert_equal(_elide('the quick brown fox jumped over the lazy dog', 'the quick brown fox', min_elide=10), 'the…fox jumped over the lazy dog')
30
31
32 def test_elide_typed_short_match(self):
33 """
34 if the match is too short we don't elide.
35 avoid the "the...the"
36 """
37 nt.assert_equal(_elide('the quick brown fox jumped over the lazy dog', 'the', min_elide=10), 'the quick brown fox jumped over the lazy dog')
38
39 def test_elide_typed_no_match(self):
40 """
41 if the match is too short we don't elide.
42 avoid the "the...the"
43 """
44 # here we typed red instead of brown
45 nt.assert_equal(_elide('the quick brown fox jumped over the lazy dog', 'the quick red fox', min_elide=10), 'the quick brown fox jumped over the lazy dog')
28
46
29 class TestContextAwareCompletion(unittest.TestCase):
47 class TestContextAwareCompletion(unittest.TestCase):
30
48
General Comments 0
You need to be logged in to leave comments. Login now