##// END OF EJS Templates
fix and test path regexes...
Min RK -
Show More
@@ -0,0 +1,61 b''
1
2 import re
3 import nose.tools as nt
4
5 from IPython.html.base.handlers import path_regex, notebook_path_regex
6
7 try: # py3
8 assert_regex = nt.assert_regex
9 assert_not_regex = nt.assert_not_regex
10 except AttributeError: # py2
11 assert_regex = nt.assert_regexp_matches
12 assert_not_regex = nt.assert_not_regexp_matches
13
14
15 # build regexps that tornado uses:
16 path_pat = re.compile('^' + '/x%s' % path_regex + '$')
17 nb_path_pat = re.compile('^' + '/y%s' % notebook_path_regex + '$')
18
19 def test_path_regex():
20 for path in (
21 '/x',
22 '/x/',
23 '/x/foo',
24 '/x/foo.ipynb',
25 '/x/foo/bar',
26 '/x/foo/bar.txt',
27 ):
28 assert_regex(path, path_pat)
29
30 def test_path_regex_bad():
31 for path in (
32 '/xfoo',
33 '/xfoo/',
34 '/xfoo/bar',
35 '/xfoo/bar/',
36 '/x/foo/bar/',
37 '/x//foo',
38 '/y',
39 '/y/x/foo',
40 ):
41 assert_not_regex(path, path_pat)
42
43 def test_notebook_path_regex():
44 for path in (
45 '/y/asdf.ipynb',
46 '/y/foo/bar.ipynb',
47 '/y/a/b/c/d/e.ipynb',
48 ):
49 assert_regex(path, nb_path_pat)
50
51 def test_notebook_path_regex_bad():
52 for path in (
53 '/y',
54 '/y/',
55 '/y/.ipynb',
56 '/y/foo/.ipynb',
57 '/y/foo/bar',
58 '/yfoo.ipynb',
59 '/yfoo/bar.ipynb',
60 ):
61 assert_not_regex(path, nb_path_pat)
@@ -463,8 +463,9 b' class FilesRedirectHandler(IPythonHandler):'
463 463 # URL pattern fragments for re-use
464 464 #-----------------------------------------------------------------------------
465 465
466 path_regex = r"(?P<path>.*)"
467 notebook_path_regex = r"(?P<path>.+\.ipynb)"
466 # path matches any number of `/foo[/bar...]` or just `/` or ''
467 path_regex = r"(?P<path>(?:(?:/[^/]+)+|/?))"
468 notebook_path_regex = r"(?P<path>(?:/[^/]+)+\.ipynb)"
468 469
469 470 #-----------------------------------------------------------------------------
470 471 # URL to handler mappings
General Comments 0
You need to be logged in to leave comments. Login now