def test_normalize(): """ normalize_opts.py: Test normalize() """ a = NormObj('.', 'anchorhub-out', '{ }', ['.md'], False) a = n.normalize(a) assert a.input == '.' + get_path_separator() assert a.output == 'anchorhub-out' + get_path_separator() assert a.open == '{' assert a.close == '}' assert a.abs_input == path.abspath(a.input) + get_path_separator() assert a.abs_output == path.abspath(a.output) + get_path_separator()
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! ']
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! ']
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! "]
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! "]
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)