Exemplo n.º 1
0
    def test_render_cmd_with_documentation_builder(self):
        # documentation-builder is a strict snap, can only work out of $HOME
        home = os.environ['HOME']
        markdown_dir = self.useFixture(fixtures.TempDir(rootdir=home))
        html_dir = self.useFixture(fixtures.TempDir(rootdir=home))

        with tempfile.NamedTemporaryFile('w') as metadata:
            metadata.write(json.dumps(self.metadata()))
            metadata.flush()

            args = main.parse_args([
                'render',
                metadata.name,
                '--name=SERVICE',
                '--dir={}'.format(markdown_dir.path),
            ])
            main.render_cmd(args)

        build = [
            'documentation-builder',
            '--base-directory={}'.format(markdown_dir.path),
            '--output-path={}'.format(html_dir.path),
        ]
        try:
            subprocess.check_output(build)
        except subprocess.CalledProcessError as e:
            print(e.output)
            raise

        p = partial(os.path.join, html_dir.path)
        self.assertTrue(os.path.exists(p('en/group.html')))
        self.assertTrue(os.path.exists(p('en/index.html')))
Exemplo n.º 2
0
    def test_render_cmd_with_templates(self):
        markdown_dir = self.useFixture(fixtures.TempDir())
        with tempfile.NamedTemporaryFile('w') as metadata:
            with tempfile.NamedTemporaryFile('w', dir=os.getcwd()) as template:
                metadata.write(json.dumps(self.metadata()))
                metadata.flush()

                template.write('TEMPLATE')
                template.flush()
                name = os.path.relpath(template.name)

                args = main.parse_args([
                    'render',
                    metadata.name,
                    '--name=SERVICE',
                    '--dir={}'.format(markdown_dir.path),
                    '--page-template=' + name,
                    '--index-template=' + name,
                ])
                main.render_cmd(args)

        p = partial(os.path.join, markdown_dir.path)
        with open(p('en/group.md')) as f:
            self.assertEqual(f.read(), 'TEMPLATE')
        with open(p('en/index.md')) as f:
            self.assertEqual(f.read(), 'TEMPLATE')