Exemplo n.º 1
0
    def testExport(self):
        # Only test single page, just to show "run()" works
        file = self.notebook.file('Foo/Bar.txt')
        file.write('=== Foo\ntest 123\n')

        output = self.tmpdir.file('output.html')

        cmd = ExportCommand('export')
        cmd.parse_options(self.notebook.path, 'Foo:Bar', '--output',
                          output.path, '--template',
                          'tests/data/TestTemplate.html')
        cmd.run()

        self.assertTrue(output.exists())
        html = output.read()
        self.assertTrue('<h1>Foo' in html)
        self.assertTrue('test 123' in html)
Exemplo n.º 2
0
    def testOptions(self):
        # Only testing we get a valid exporter, not the full command,
        # because the command is very slow

        ## Full notebook, minimal options
        cmd = ExportCommand('export')
        cmd.parse_options(self.notebook.path)
        self.assertRaises(UsageError, cmd.get_exporter, None)

        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            '--output',
            self.tmpdir.subdir('output').path,
        )
        exp = cmd.get_exporter(None)
        self.assertIsInstance(exp, MultiFileExporter)
        self.assertIsInstance(exp.layout, MultiFileLayout)
        self.assertIsInstance(exp.layout.dir, Dir)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNone(exp.document_root_url)
        self.assertIsNotNone(exp.format)
        self.assertIsNone(exp.index_page)

        ## Full notebook, full options
        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            '--format',
            'markdown',
            '--template',
            './tests/data/TestTemplate.html',
            '--output',
            self.tmpdir.subdir('output').path,
            '--root-url',
            '/foo/',
            '--index-page',
            'myindex',
            '--overwrite',
        )
        exp = cmd.get_exporter(None)
        self.assertIsInstance(exp, MultiFileExporter)
        self.assertIsInstance(exp.layout, MultiFileLayout)
        self.assertIsInstance(exp.layout.dir, Dir)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNotNone(exp.document_root_url)
        self.assertIsNotNone(exp.format)
        self.assertIsNotNone(exp.index_page)

        ## Full notebook, single page
        cmd = ExportCommand('export')
        cmd.parse_options(self.notebook.path, '--format', 'markdown',
                          '--template', './tests/data/TestTemplate.html',
                          '--output',
                          self.tmpdir.file('output.md').path, '-s')
        exp = cmd.get_exporter(None)
        self.assertIsInstance(exp, SingleFileExporter)
        self.assertIsInstance(exp.layout, SingleFileLayout)
        self.assertIsInstance(exp.layout.file, File)

        ## Single page
        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            'Foo:Bar',
            '--output',
            self.tmpdir.subdir('output').path,
        )
        exp = cmd.get_exporter(Path('Foo:Bar'))
        self.assertIsInstance(exp, MultiFileExporter)
        self.assertIsInstance(exp.layout, FileLayout)
        self.assertIsInstance(exp.layout.file, File)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNone(exp.document_root_url)
        self.assertIsNotNone(exp.format)
        self.assertIsNone(exp.index_page)

        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            'Foo:Bar',
            '--recursive',
            '--output',
            self.tmpdir.subdir('output').path,
        )
        exp = cmd.get_exporter(Path('Foo:Bar'))
        self.assertIsInstance(exp, MultiFileExporter)
        self.assertIsInstance(exp.layout, FileLayout)
        self.assertIsInstance(exp.layout.file, File)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNone(exp.document_root_url)
        self.assertIsNotNone(exp.format)
        self.assertIsNone(exp.index_page)

        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            'Foo:Bar',
            '-rs',
            '--output',
            self.tmpdir.subdir('output').path,
        )
        exp = cmd.get_exporter(Path('Foo:Bar'))
        self.assertIsInstance(exp, SingleFileExporter)
        self.assertIsInstance(exp.layout, SingleFileLayout)
        self.assertIsInstance(exp.layout.file, File)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNone(exp.document_root_url)
        self.assertIsNotNone(exp.format)

        ## MHTML exporter
        cmd = ExportCommand('export')
        cmd.parse_options(
            self.notebook.path,
            'Foo:Bar',
            '-rs',
            '--format',
            'mhtml',
            '--output',
            self.tmpdir.subdir('output').path,
        )
        exp = cmd.get_exporter(Path('Foo:Bar'))
        self.assertIsInstance(exp, MHTMLExporter)
        self.assertIsInstance(exp.file, File)
        self.assertIsInstance(exp.template, Template)
        self.assertIsNone(exp.document_root_url)