Beispiel #1
0
    def test_write_figures_to_custom_path(self):
        """
        Check if figure files are copied to configured path.
        """
        def fig_exists(path):
            return (len(os.listdir(path)) > 0)

        # check absolute path
        with self.create_temp_cwd(
            ['notebook4_jpeg.ipynb', 'containerized_deployments.jpeg']):
            output_dir = tempdir.TemporaryDirectory()
            path = os.path.join(output_dir.name, 'files')
            self.nbconvert('--log-level 0 notebook4_jpeg.ipynb --to rst '
                           '--NbConvertApp.output_files_dir={}'.format(path))
            assert fig_exists(path)
            output_dir.cleanup()

        # check relative path
        with self.create_temp_cwd(
            ['notebook4_jpeg.ipynb', 'containerized_deployments.jpeg']):
            self.nbconvert('--log-level 0 notebook4_jpeg.ipynb --to rst '
                           '--NbConvertApp.output_files_dir=output')
            assert fig_exists('output')

        # check default path with notebook name
        with self.create_temp_cwd(
            ['notebook4_jpeg.ipynb', 'containerized_deployments.jpeg']):
            self.nbconvert('--log-level 0 notebook4_jpeg.ipynb --to rst')
            assert fig_exists('notebook4_jpeg_files')
def test_cfg2dict():
    d = {'title': 'temp_title'}
    with tempdir.TemporaryDirectory() as td:
        loc_path = os.path.join(td, 'paper_stats.json')
        options.dict2cfg(d, loc_path)
        test_d = options.cfg2dict(loc_path)
        assert test_d == d
Beispiel #3
0
 def test_export(self):
     """Smoke test PDFExporter"""
     with tempdir.TemporaryDirectory() as td:
         newpath = os.path.join(td, os.path.basename(self._get_notebook()))
         shutil.copy(self._get_notebook(), newpath)
         (output, resources) = self.exporter_class(latex_count=1).from_filename(newpath)
         self.assertIsInstance(output, bytes)
         assert len(output) > 0
Beispiel #4
0
 def test_absolute_template_file(self):
     with tempdir.TemporaryDirectory() as td:
         template = os.path.join(td, 'abstemplate.ext.j2')
         test_output = 'absolute!'
         with open(template, 'w') as f:
             f.write(test_output)
         config = Config()
         config.TemplateExporter.template_file = template
         exporter = self._make_exporter(config=config)
         assert exporter.template.filename == template
         assert os.path.dirname(template) in exporter.template_paths
Beispiel #5
0
 def test_absolute_template_file_compatibility(self):
     with tempdir.TemporaryDirectory() as td:
         template = os.path.join(td, 'abstemplate.tpl')
         test_output = 'absolute!'
         with open(template, 'w') as f:
             f.write(test_output)
         config = Config()
         config.TemplateExporter.template_file = template
         with pytest.warns(DeprecationWarning):
             exporter = self._make_exporter(config=config)
         assert exporter.template.filename == template
         assert os.path.dirname(template) in exporter.template_paths
 def test_export(self):
     """Smoke test PDFExporter"""
     with tempdir.TemporaryDirectory() as td:
         file_name = os.path.basename(self._get_notebook())
         newpath = os.path.join(td, file_name)
         shutil.copy(self._get_notebook(), newpath)
         (output, resources) = self.exporter_class(
             latex_count=1).from_filename(newpath)
         self.assertIsInstance(output, bytes)
         assert len(output) > 0
         # all temporary file should be cleaned up
         assert {file_name} == set(os.listdir(td))
Beispiel #7
0
 def test_absolute_template_file(self):
     """--template '/path/to/template.tpl'"""
     with self.create_temp_cwd(['notebook*.ipynb']), tempdir.TemporaryDirectory() as td:
         template = os.path.join(td, 'mytemplate.tpl')
         test_output = 'success!'
         with open(template, 'w') as f:
             f.write(test_output)
         self.nbconvert('--log-level 0 notebook2 --template %s' % template)
         assert os.path.isfile('notebook2.html')
         with open('notebook2.html') as f:
             text = f.read()
         assert text == test_output
Beispiel #8
0
 def test_absolute_template_dir(self):
     with tempdir.TemporaryDirectory() as td:
         template = 'mytemplate'
         template_file = os.path.join(td, template, 'index.py.j2')
         template_dir = os.path.dirname(template_file)
         os.mkdir(template_dir)
         test_output = 'absolute!'
         with open(template_file, 'w') as f:
             f.write(test_output)
         config = Config()
         config.TemplateExporter.template_name = template
         config.TemplateExporter.extra_template_basedirs = [td]
         exporter = self._make_exporter(config=config)
         assert exporter.template.filename == template_file
         assert exporter.template_name == template
         assert os.path.join(td, template) in exporter.template_paths