Beispiel #1
0
def test_parse_file():
    # retrieve the list of files to process
    file_list = utils.make_file_list( ['./assets/*.c'] )
    for filename in file_list:
        source_processor.parse_file( filename )
    # get blocks
    blocks = source_processor.blocks
    count  = len( blocks )

    # there must be 12 blocks in file
    assert count == 12
Beispiel #2
0
def test_make_file_list(tmpdir):
    utils.output_dir = tmpdir
    f1 = tmpdir.join("test1.c")
    f2 = tmpdir.join("test2.c")
    f3 = tmpdir.join("test3.txt")
    f1.write("foo")
    f2.write("bar")
    f3.write("baz")
    args = [str(tmpdir + '/*.c')]
    expected = ['test1.c', 'test2.c']

    out_list = utils.make_file_list(args)
    out_list = [f for f in out_list]
    for i in range(len(expected)):
        assert expected[i] in out_list[i]
Beispiel #3
0
def test_parse_source():
    # retrieve the list of files to process
    file_list = utils.make_file_list( ['./assets/*.c'] )
    for filename in file_list:
        source_processor.parse_file( filename )
        content_processor.parse_sources( source_processor )
    # process sections
    content_processor.finish()
    # get headers
    headers = content_processor.headers
    # expected values
    expected_key = 'freetype/ftbbox.h'
    expected_val = 'FT_BBOX_H'

    assert headers[expected_key] == expected_val
Beispiel #4
0
def main():
    """Main program loop."""

    global output_dir
    global log_level

    parser = argparse.ArgumentParser(description="DocWriter Usage information")
    parser.add_argument(
        "files",
        nargs="+",
        help="list of source files to parse, wildcards are allowed",
    )
    parser.add_argument(
        "-t",
        "--title",
        metavar="T",
        help="set project title, as in '-t \"My Project\"'",
    )
    parser.add_argument(
        "-o",
        "--output",
        metavar="DIR",
        required=True,
        help="set output directory, as in '-o mydir'",
    )
    parser.add_argument(
        "-p",
        "--prefix",
        metavar="PRE",
        help="set documentation prefix, as in '-p ft2'",
    )
    parser.add_argument(
        "-s",
        "--site",
        metavar="DIR",
        help="set 'site_dir' in mkdocs.yml [default=site]",
    )
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        "-q",
        "--quiet",
        help="run quietly, show only errors",
        action="store_true",
    )
    group.add_argument(
        "-v", "--verbose", help="increase output verbosity", action="store_true"
    )
    args = parser.parse_args()

    # process options
    project_title = "Project"
    project_prefix = None
    output_dir = None

    if args.title:
        project_title = args.title

    if args.output:
        utils.output_dir = args.output

    if args.prefix:
        project_prefix = args.prefix

    if args.site:
        utils.site_dir = args.site

    if args.quiet:
        log_level = logging.ERROR

    if args.verbose:
        log_level = logging.DEBUG

    # set up the logger
    setup_logger(level=log_level)
    log = logging.getLogger("docwriter")

    # check all packages
    status = check.check()
    if status != 0:
        sys.exit(3)

    utils.check_output()
    utils.create_markdown_dir()

    # create context and processor
    source_processor = sources.SourceProcessor()
    content_processor = content.ContentProcessor()

    # retrieve the list of files to process
    file_list = utils.make_file_list(args.files)
    for filename in file_list:
        source_processor.parse_file(filename)
        content_processor.parse_sources(source_processor)

    # process sections
    content_processor.finish()

    # clean up directory
    log.info("Cleaning output directory")
    utils.clean_markdown_dir()

    formatter = tomarkdown.MdFormatter(
        content_processor, project_title, project_prefix
    )

    # build the docs
    utils.build_message()

    formatter.toc_dump()
    formatter.index_dump()
    formatter.section_dump_all()
Beispiel #5
0
"""

from docwriter import content
from docwriter import sources
from docwriter import tomarkdown
from docwriter import utils

# Create test objects
# create context and processor
source_processor  = sources.SourceProcessor()
content_processor = content.ContentProcessor()
# Names
project_title  = 'Test Docs'
project_prefix = 'test'
# retrieve the list of files to process
file_list = utils.make_file_list( ['./assets/*.c'] )
for filename in file_list:
    source_processor.parse_file( filename )
    content_processor.parse_sources( source_processor )
# process sections
content_processor.finish()

formatter = tomarkdown.MdFormatter( content_processor,
                                    project_title,
                                    project_prefix )

def test_html_quote():
    test_string = '7 & 9 < 4 & 5 but 12 & 15 > 4 & 5'
    expt_string = '7 &amp; 9 &lt; 4 &amp; 5 but 12 &amp; 15 &gt; 4 &amp; 5'
    assert tomarkdown.html_quote(test_string) == expt_string