示例#1
0
 def test_publish_html(self, mock_lines, mock_open):
     """Verify an HTML file can be created."""
     path = os.path.join('mock', 'report.html')
     report.publish(self.document, path, '.html')
     mock_open.assert_called_once_with(path, 'w')
     mock_lines.assert_called_once_with(self.document, '.html',
                                        ignored=None)
示例#2
0
 def test_publish_html_long(self):
     """Verify an HTML file can be created (long)."""
     temp = tempfile.mkdtemp()
     try:
         path = os.path.join(temp, 'report.html')
         report.publish(self.document, path, '.html')
         self.assertTrue(os.path.isfile(path))
     finally:
         shutil.rmtree(temp)
示例#3
0
def _run_publish(args, cwd, _):
    """Process arguments and run the `demo report` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    try:
        tree = build(cwd, root=args.project)
        document = tree.find_document(args.prefix)
    except DemoError as error:
        logging.error(error)
        return False
    else:

        kwargs = {'ignored': tree.vcs.ignored}
        if args.width:
            kwargs['width'] = args.width

        if args.path:
            ext = os.path.splitext(args.path)[-1]
        if args.markdown:
            ext = '.md'
        elif args.html:
            ext = '.html'
        elif not args.path:
            ext = '.txt'

        if args.path:
            print("publishing {} to {}...".format(document, args.path))
            report.publish(document, args.path, ext, **kwargs)
        else:
            for line in report.lines(document, ext, **kwargs):
                print(line)

        return True