From 7ffeded8c8c4cc3ea3c287f7231175b6412ebbb2 2014-08-05 20:56:14 From: cel Date: 2014-08-05 20:56:14 Subject: [PATCH] Add tests for parse_filename. --- diff --git a/IPython/nbformat/v3/tests/test_misc.py b/IPython/nbformat/v3/tests/test_misc.py new file mode 100644 index 0000000..5805b06 --- /dev/null +++ b/IPython/nbformat/v3/tests/test_misc.py @@ -0,0 +1,31 @@ +from unittest import TestCase + +from IPython.utils.py3compat import unicode_type +from .. import parse_filename + + +class MiscTests(TestCase): + + def check_filename(self, path, exp_fname, exp_bname, exp_format): + fname, bname, format = parse_filename(path) + self.assertEqual(fname, exp_fname) + self.assertEqual(bname, exp_bname) + self.assertEqual(format, exp_format) + + def test_parse_filename(self): + + # check format detection + self.check_filename("test.ipynb", "test.ipynb", "test", "json") + self.check_filename("test.json", "test.json", "test", "json") + self.check_filename("test.py", "test.py", "test", "py") + + # check parsing an unknown format + self.check_filename("test.nb", "test.nb.ipynb", "test.nb", "json") + + # check parsing a full file path + self.check_filename("/tmp/test.ipynb", "/tmp/test.ipynb", "/tmp/test", + "json") + + # check parsing a file name containing dots + self.check_filename("test.nb.ipynb", "test.nb.ipynb", "test.nb", + "json")