Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6265 from cel4/fix_parse_filename
parse_filename: Fixed issues when file name contains dots.
- Loading branch information
Showing
3 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
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 | ||
abs_path = os.path.abspath("test.ipynb") | ||
basename, ext = os.path.splitext(abs_path) | ||
self.check_filename(abs_path, abs_path, basename, "json") | ||
|
||
# check parsing a file name containing dots | ||
self.check_filename("test.nb.ipynb", "test.nb.ipynb", "test.nb", | ||
"json") |