test_paths.py 842 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import re
  2. import nose.tools as nt
  3. from notebook.base.handlers import path_regex
  4. try: # py3
  5. assert_regex = nt.assert_regex
  6. assert_not_regex = nt.assert_not_regex
  7. except AttributeError: # py2
  8. assert_regex = nt.assert_regexp_matches
  9. assert_not_regex = nt.assert_not_regexp_matches
  10. # build regexps that tornado uses:
  11. path_pat = re.compile('^' + '/x%s' % path_regex + '$')
  12. def test_path_regex():
  13. for path in (
  14. '/x',
  15. '/x/',
  16. '/x/foo',
  17. '/x/foo.ipynb',
  18. '/x/foo/bar',
  19. '/x/foo/bar.txt',
  20. ):
  21. assert_regex(path, path_pat)
  22. def test_path_regex_bad():
  23. for path in (
  24. '/xfoo',
  25. '/xfoo/',
  26. '/xfoo/bar',
  27. '/xfoo/bar/',
  28. '/x/foo/bar/',
  29. '/x//foo',
  30. '/y',
  31. '/y/x/foo',
  32. ):
  33. assert_not_regex(path, path_pat)