Ejemplo n.º 1
0
def test_parse_args():
    """
    cmdparse.py: Test parse_args()

    The first three sets of assertions check for all the various flag names,
    both the long versions (--flag) and the short versions (-f)

    The final set of assertions check the default values
    """
    args = ['.', 'output', '-e', '.md', '.rst']
    pargs = cmd.parse_args(args)
    assert pargs.input == '.'
    assert pargs.output == 'output'
    assert pargs.extensions == ['.md', '.rst']

    args2 = ['../bears', '-w', '[--> <--]', '-X']
    pargs2 = cmd.parse_args(args2)
    assert pargs2.input == '../bears'
    assert pargs2.wrapper == '[--> <--]'
    assert pargs2.overwrite == True

    args3 = ['.', '--overwrite', '--wrapper', '$$$$ $$$$', '--extension',
             '.txt', '.fbi', '.wat', '.hub']
    pargs3 = cmd.parse_args(args3)
    assert pargs3.input == '.'
    assert pargs3.overwrite == True
    assert pargs3.wrapper == '$$$$ $$$$'
    assert pargs3.extensions == ['.txt', '.fbi', '.wat', '.hub']

    args4 = ['.']
    pargs4 = cmd.parse_args(args4)
    assert pargs4.input == ds.INPUT
    assert pargs4.output == ds.OUTPUT
    assert pargs4.wrapper == ds.WRAPPER
    assert pargs4.overwrite == False
    assert pargs4.extensions == ds.ARGPARSE_EXTENSION['default']
Ejemplo n.º 2
0
def test_atx_collector_strategy():
    """
    GitHub Built-in: Test MarkdownATXCollectorStrategy with defaults
    """
    opts = normalize_opts.normalize(cmdparse.parse_args(['.']))
    s = cstrategies.MarkdownATXCollectorStrategy(opts)

    lines = [
        "# This is my first test {#test1}", "This should not match",
        "### This should also not match",
        "#### This one should match though! {#test4}"
    ]
    assert s.test(lines, 0)
    assert not s.test(lines, 1)
    assert not s.test(lines, 2)
    assert s.test(lines, 3)

    assert s.get(lines, 0) == ['test1', 'This is my first test ']
    assert s.get(lines, 3) == ['test4', 'This one should match though! ']
Ejemplo n.º 3
0
def test_atx_collector_strategy_different_wrapper():
    """
    GitHub Built-in: Test MarkdownATXCollectorStrategy with different wrapper
    """
    opts = normalize_opts.normalize(cmdparse.parse_args(['.', '-w' '[> <]']))
    s = cstrategies.MarkdownATXCollectorStrategy(opts)

    lines = [
        "# This is my first test [>#test1<]", "This should not match",
        "### This should also not match",
        "#### This one should match though! [>#test4<]"
    ]
    assert s.test(lines, 0)
    assert not s.test(lines, 1)
    assert not s.test(lines, 2)
    assert s.test(lines, 3)

    assert s.get(lines, 0) == ['test1', 'This is my first test ']
    assert s.get(lines, 3) == ['test4', 'This one should match though! ']
Ejemplo n.º 4
0
def test_atx_collector_strategy():
    """
    GitHub Built-in: Test MarkdownATXCollectorStrategy with defaults
    """
    opts = normalize_opts.normalize(cmdparse.parse_args(["."]))
    s = cstrategies.MarkdownATXCollectorStrategy(opts)

    lines = [
        "# This is my first test {#test1}",
        "This should not match",
        "### This should also not match",
        "#### This one should match though! {#test4}",
    ]
    assert s.test(lines, 0)
    assert not s.test(lines, 1)
    assert not s.test(lines, 2)
    assert s.test(lines, 3)

    assert s.get(lines, 0) == ["test1", "This is my first test "]
    assert s.get(lines, 3) == ["test4", "This one should match though! "]
Ejemplo n.º 5
0
def test_atx_collector_strategy_different_wrapper():
    """
    GitHub Built-in: Test MarkdownATXCollectorStrategy with different wrapper
    """
    opts = normalize_opts.normalize(cmdparse.parse_args([".", "-w" "[> <]"]))
    s = cstrategies.MarkdownATXCollectorStrategy(opts)

    lines = [
        "# This is my first test [>#test1<]",
        "This should not match",
        "### This should also not match",
        "#### This one should match though! [>#test4<]",
    ]
    assert s.test(lines, 0)
    assert not s.test(lines, 1)
    assert not s.test(lines, 2)
    assert s.test(lines, 3)

    assert s.get(lines, 0) == ["test1", "This is my first test "]
    assert s.get(lines, 3) == ["test4", "This one should match though! "]
Ejemplo n.º 6
0
def main(argv=None):
    """
    Main entry method for AnchorHub. Takes in command-line arguments,
    finds files to parse within the specified input directory, and outputs
    parsed files to the specified output directory.

    :param argv: a list of string command line arguments
    """
    # Get command line arguments, validate them, and normalize them
    opts = cmdparse.parse_args(argv)
    assert validate_opts.validate(opts)
    opts = normalize_opts.normalize(opts)

    if opts.verbose:
        # Update client: print input and output directories
        messages.print_input_output(opts)

    file_paths = fileparse.get_file_list(opts)
    assert validate_files.validate(file_paths, opts)

    if opts.verbose and opts.is_dir:
        # Update client: print files that will be parsed
        messages.print_files(opts, file_paths)

    # For now, only using default GitHub Markdown for parsing
    # Collect tag/anchor combinations
    collector = make_github_markdown_collector(opts)
    anchors, duplicate_tags = collector.collect(file_paths)
    assert validate_anchors.validate(anchors, duplicate_tags, opts)

    # Write files using previously found AnchorHub tags and generated anchors
    writer = make_github_markdown_writer(opts)
    counter = writer.write(file_paths, anchors, opts)

    if opts.verbose:
        if opts.is_dir:
            # Update client: print files that had modifications
            messages.print_modified_files(opts, anchors)
        # Print summary statistics
        messages.print_summary_stats(counter)
Ejemplo n.º 7
0
def main(argv=None):
    """
    Main entry method for AnchorHub. Takes in command-line arguments,
    finds files to parse within the specified input directory, and outputs
    parsed files to the specified output directory.

    :param argv: a list of string command line arguments
    """
    # Get command line arguments, validate them, and normalize them
    opts = cmdparse.parse_args(argv)
    assert validate_opts.validate(opts)
    opts = normalize_opts.normalize(opts)

    if opts.verbose:
        # Update client: print input and output directories
        messages.print_input_output(opts)

    file_paths = fileparse.get_file_list(opts)
    assert validate_files.validate(file_paths, opts)

    if opts.verbose and opts.is_dir:
        # Update client: print files that will be parsed
        messages.print_files(opts, file_paths)

    # For now, only using default GitHub Markdown for parsing
    # Collect tag/anchor combinations
    collector = make_github_markdown_collector(opts)
    anchors, duplicate_tags = collector.collect(file_paths)
    assert validate_anchors.validate(anchors, duplicate_tags, opts)

    # Write files using previously found AnchorHub tags and generated anchors
    writer = make_github_markdown_writer(opts)
    counter = writer.write(file_paths, anchors, opts)

    if opts.verbose:
        if opts.is_dir:
            # Update client: print files that had modifications
            messages.print_modified_files(opts, anchors)
        # Print summary statistics
        messages.print_summary_stats(counter)