def test_read(self): """Can older notebooks be opened without modification?""" # Open a version 3 notebook. Make sure it is still version 3. with self.fopen("test3.ipynb", "r") as f: nb = read(f) (major, minor) = get_version(nb) self.assertEqual(major, 3) # Open a version 2 notebook. Make sure it is still version 2. with self.fopen("test2.ipynb", "r") as f: nb = read(f) (major, minor) = get_version(nb) self.assertEqual(major, 2)
def _get_notebook_node(self): # pragma: no cover "Load captured notebook node" size = len(self._notebook_data) if size == 0: raise Exception("Captured buffer size for notebook node is zero.") node = reader.reads(self._notebook_data) self.nbversion = reader.get_version(node) return node
def test_open_current(self): """Can an old notebook be opened and converted to the current version while remembering the original version of the notebook?""" # Open a version 2 notebook and attempt to upgrade it to the current version # while remembering it's version information. with self.fopen("test2.ipynb", "r") as f: nb = read(f) (original_major, original_minor) = get_version(nb) nb = convert(nb, current_nbformat) # Check if upgrade was successful. (major, minor) = get_version(nb) self.assertEqual(major, current_nbformat) # Check if the original major revision was remembered. self.assertEqual(original_major, 2)
def test_write_downgrade_2(self): """dowgrade a v3 notebook to v2""" # Open a version 3 notebook. with self.fopen("test3.ipynb", "r") as f: nb = read(f, as_version=3) jsons = writes(nb, version=2) nb2 = json.loads(jsons) (major, minor) = get_version(nb2) self.assertEqual(major, 2)
def test_read(self): """Can older notebooks be opened and automatically converted to the current nbformat?""" # Open a version 2 notebook. with self.fopen("test2.ipynb", "r") as f: nb = read(f, as_version=current_nbformat) # Check that the notebook was upgraded to the latest version automatically. (major, minor) = get_version(nb) self.assertEqual(major, current_nbformat)
def _get_notebook_node(self): # pragma: no cover "Load captured notebook node" self._notebook_data.seek(0, os.SEEK_END) size = self._notebook_data.tell() if size == 0: raise Exception("Captured buffer size for notebook node is zero.") self._notebook_data.seek(0) node = reader.reads(self._notebook_data.read()) self.nbversion = reader.get_version(node) self._notebook_data.close() return node
def test_upgrade_2_3(self): """Do notebook upgrades work?""" # Open a version 2 notebook and attempt to upgrade it to version 3. with self.fopen("test2.ipynb", "r") as f: nb = read(f) nb = convert(nb, 3) # Check if upgrade was successful. (major, minor) = get_version(nb) self.assertEqual(major, 3)
def test_downgrade_3_2(self): """Do notebook downgrades work?""" # Open a version 3 notebook and attempt to downgrade it to version 2. with self.fopen("test3.ipynb", "r") as f: nb = read(f) nb = convert(nb, 2) # Check if downgrade was successful. (major, minor) = get_version(nb) self.assertEqual(major, 2)