File: test_misc.py

package info (click to toggle)
nbformat 5.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,072 kB
  • sloc: python: 4,746; makefile: 167; javascript: 2
file content (31 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

import os
from unittest import TestCase

from nbformat.v3 import parse_filename


class MiscTests(TestCase):
    def check_filename(self, path, exp_fname, exp_bname, exp_format):
        fname, bname, fmt = parse_filename(path)
        self.assertEqual(fname, exp_fname)
        self.assertEqual(bname, exp_bname)
        self.assertEqual(fmt, 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")