test_misc.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. from unittest import TestCase
  3. from ipython_genutils.py3compat import unicode_type
  4. from .. import parse_filename
  5. class MiscTests(TestCase):
  6. def check_filename(self, path, exp_fname, exp_bname, exp_format):
  7. fname, bname, format = parse_filename(path)
  8. self.assertEqual(fname, exp_fname)
  9. self.assertEqual(bname, exp_bname)
  10. self.assertEqual(format, exp_format)
  11. def test_parse_filename(self):
  12. # check format detection
  13. self.check_filename("test.ipynb", "test.ipynb", "test", "json")
  14. self.check_filename("test.json", "test.json", "test", "json")
  15. self.check_filename("test.py", "test.py", "test", "py")
  16. # check parsing an unknown format
  17. self.check_filename("test.nb", "test.nb.ipynb", "test.nb", "json")
  18. # check parsing a full file path
  19. abs_path = os.path.abspath("test.ipynb")
  20. basename, ext = os.path.splitext(abs_path)
  21. self.check_filename(abs_path, abs_path, basename, "json")
  22. # check parsing a file name containing dots
  23. self.check_filename("test.nb.ipynb", "test.nb.ipynb", "test.nb",
  24. "json")