def test_markdown_with_plugins_list_and_filter_by_id_ends_with_non_sequence():
    """
    Test to make sure that `plugins list` lists all plugins with the specified id filter
        for a filter that returns no values.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["plugins", "list", "this-is-not-an-used-identifier"]

    expected_return_code = 0
    expected_output = """No plugin rule identifiers matches the pattern 'this-is-not-an-used-identifier'."""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
def test_md030_bad_spacing_ul_single_config_1_2():
    """
    Test to make sure this rule does trigger with a document that
    contains unordered lists with two spaces after the marker and
    configuration for multi line lists.  ul_multi does not come into
    effect as all list items have a single paragraph.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "--set",
        "plugins.md030.ul_single=$#1",
        "--set",
        "plugins.md030.ul_multi=$#2",
        "--strict-config",
        "--stack-trace",
        "scan",
        "test/resources/rules/md030/bad_spacing_ul_single.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md030/bad_spacing_ul_single.md:1:1: " +
        "MD030: Spaces after list markers " +
        "[Expected: 1; Actual: 2] (list-marker-space)\n" +
        "test/resources/rules/md030/bad_spacing_ul_single.md:2:1: " +
        "MD030: Spaces after list markers " +
        "[Expected: 1; Actual: 2] (list-marker-space)\n" +
        "test/resources/rules/md030/bad_spacing_ul_single.md:3:1: " +
        "MD030: Spaces after list markers " +
        "[Expected: 1; Actual: 2] (list-marker-space)")
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 3
0
def test_md024_good_same_heading_but_not_in_siblings_atx_with_alternate_configuration(
):
    """
    Test to make sure this rule does not trigger with a document that
    contains Atx headings with duplicate content in siblings.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {
        "plugins": {
            "md024": {
                "allow_different_nesting": True
            }
        }
    }
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(
            supplied_configuration)
        supplied_arguments = [
            "-c",
            configuration_file,
            "scan",
            "test/resources/rules/md024/same_heading_but_not_in_siblings_atx.md",
        ]

        expected_return_code = 0
        expected_output = ""
        expected_error = ""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(expected_output, expected_error,
                                       expected_return_code)
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 4
0
def test_md018_bad_single_paragraph_with_starting_space():
    """
    Test to make sure this rule does trigger with a document that
    contains multiple possible Atx Headings without the proper space at the start
    with a single paragraph but with increasing indent.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "scan",
        "test/resources/rules/md018/single_paragraph_with_starting_space.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md018/single_paragraph_with_starting_space.md:1:1: "
        +
        "MD018: No space present after the hash character on a possible Atx Heading. (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_space.md:2:2: "
        +
        "MD018: No space present after the hash character on a possible Atx Heading. (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_space.md:3:3: "
        +
        "MD018: No space present after the hash character on a possible Atx Heading. (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_space.md:4:4: "
        +
        "MD018: No space present after the hash character on a possible Atx Heading. (no-missing-space-atx)\n"
    )
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 5
0
def test_markdown_with_dash_e_single_by_id_and_config_causing_config_exception(
):
    """
    Test to make sure if we tell the test plugin to throw an exception during the
    call to `initialize_from_config`, that it is handled properly.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {"MD999": {"test_value": 10}}
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(
            supplied_configuration)
        supplied_arguments = [
            "-e",
            "MD999",
            "-c",
            configuration_file,
            "test/resources/rules/md047/end_with_blank_line.md",
        ]

        expected_return_code = 1
        expected_output = """MD999>>init_from_config
MD999>>test_value>>10
MD999>>other_test_value>>1
"""
        expected_error = """BadPluginError encountered while configuring plugins:
Plugin id 'MD999' had a critical failure during the 'apply_configuration' action.
"""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(expected_output, expected_error,
                                       expected_return_code)
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 6
0
def test_md002_bad_proper_setext_heading_start_with_alternate_configuration():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md002 directory starting with a setext heading of ====== to
    create a h1 heading.  The modified  configuration will cause the file to be parsed
    with reported issues.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {"MD002": {"level": 2}}
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(supplied_configuration)
        supplied_arguments = [
            "-e",
            "MD002",
            "-c",
            configuration_file,
            "test/resources/rules/md002/proper_setext_heading_start.md",
        ]

        expected_return_code = 1
        expected_output = (
            "test/resources/rules/md002/proper_setext_heading_start.md:2:1: "
            + "MD002: First heading should be a top level heading "
            + "[Expected: h2; Actual: h1] (first-heading-h1,first-header-h1)\n"
        )
        expected_error = ""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(
            expected_output, expected_error, expected_return_code
        )
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 7
0
def test_md022_bad_proper_line_spacing_atx_with_alternate_lines_below():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/MD022 directory that has atx headings that do not have proper
    spacing below the heading with an alternate configuration.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {"MD022": {"lines_below": 2}}
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(supplied_configuration)
        supplied_arguments = [
            "-c",
            configuration_file,
            "test/resources/rules/md022/proper_line_spacing_atx.md",
        ]

        expected_return_code = 1
        expected_output = (
            "test/resources/rules/md022/proper_line_spacing_atx.md:1:1: "
            + "MD022: Headings should be surrounded by blank lines "
            + "[Expected: 2; Actual: 1; Below] (blanks-around-headings,blanks-around-headers)\n"
            + "test/resources/rules/md022/proper_line_spacing_atx.md:7:1: "
            + "MD022: Headings should be surrounded by blank lines "
            + "[Expected: 2; Actual: 1; Below] (blanks-around-headings,blanks-around-headers)\n"
        )
        expected_error = ""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(
            expected_output, expected_error, expected_return_code
        )
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 8
0
def test_md020_bad_paragraphs_with_starting_whitespace():
    """
    Test to make sure this rule does trigger with a document that
    contains multiple Atx Closed Headings within a paragraph
    with increasing starting whitespace.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "scan",
        "test/resources/rules/md020/paragraphs_with_starting_whitespace.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md020/paragraphs_with_starting_whitespace.md:1:1: "
        +
        "MD020: No space present inside of the hashes on a possible Atx Closed Heading. "
        + "(no-missing-space-closed-atx)\n" +
        "test/resources/rules/md020/paragraphs_with_starting_whitespace.md:3:2: "
        +
        "MD020: No space present inside of the hashes on a possible Atx Closed Heading. "
        + "(no-missing-space-closed-atx)\n" +
        "test/resources/rules/md020/paragraphs_with_starting_whitespace.md:5:3: "
        +
        "MD020: No space present inside of the hashes on a possible Atx Closed Heading. "
        + "(no-missing-space-closed-atx)\n" +
        "test/resources/rules/md020/paragraphs_with_starting_whitespace.md:7:4: "
        +
        "MD020: No space present inside of the hashes on a possible Atx Closed Heading. "
        + "(no-missing-space-closed-atx)\n")
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 9
0
def test_md018_bad_single_paragraph_with_starting_whitespace():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md018 directory that has multiple possible atx headings within
    a single paragraph each one with starting whitespace that would normally be
    permitted.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "test/resources/rules/md018/single_paragraph_with_starting_whitespace.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md018/single_paragraph_with_starting_whitespace.md:0:0: "
        +
        "MD018: No space after hash on atx style heading (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_whitespace.md:0:0: "
        +
        "MD018: No space after hash on atx style heading (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_whitespace.md:0:0: "
        +
        "MD018: No space after hash on atx style heading (no-missing-space-atx)\n"
        +
        "test/resources/rules/md018/single_paragraph_with_starting_whitespace.md:0:0: "
        +
        "MD018: No space after hash on atx style heading (no-missing-space-atx)\n"
    )
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 10
0
def test_md009_bad_html_block_with_extra():
    """
    Test to make sure this rule does trigger with a document that
    has trailing spaces for text within a HTML block.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "--disable-rules",
        "md033",
        "scan",
        "test/resources/rules/md009/bad_html_block_with_extra.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md009/bad_html_block_with_extra.md:2:5: " +
        "MD009: Trailing spaces " +
        "[Expected: 0 or 2; Actual: 1] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_html_block_with_extra.md:3:3: " +
        "MD009: Trailing spaces " +
        "[Expected: 0 or 2; Actual: 1] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_html_block_with_extra.md:4:2: " +
        "MD009: Trailing spaces " +
        "[Expected: 0 or 2; Actual: 1] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_html_block_with_extra.md:5:5: " +
        "MD009: Trailing spaces " +
        "[Expected: 0 or 2; Actual: 1] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_html_block_with_extra.md:6:6: " +
        "MD009: Trailing spaces " +
        "[Expected: 0 or 2; Actual: 1] (no-trailing-spaces)")
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
def test_md030_good_spacing_ol_single_with_config_2_1():
    """
    Test to make sure this rule does trigger with a document that
    contains unordered lists with a single space after the marker,
    and configuration that applies.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "--set",
        "plugins.md030.ol_single=$#2",
        "--set",
        "plugins.md030.ol_multi=$#1",
        "--strict-config",
        "scan",
        "test/resources/rules/md030/good_spacing_ol_single.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md030/good_spacing_ol_single.md:1:1: "
        + "MD030: Spaces after list markers "
        + "[Expected: 2; Actual: 1] (list-marker-space)\n"
        + "test/resources/rules/md030/good_spacing_ol_single.md:2:1: "
        + "MD030: Spaces after list markers "
        + "[Expected: 2; Actual: 1] (list-marker-space)\n"
        + "test/resources/rules/md030/good_spacing_ol_single.md:3:1: "
        + "MD030: Spaces after list markers "
        + "[Expected: 2; Actual: 1] (list-marker-space)"
    )
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
Esempio n. 12
0
def test_markdown_with_good_strict_config_type():
    """
    Test to make sure that we can set the strict configuration mode from
    the configuration file, capturing any bad errors.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {
        "mode": {
            "strict-config": True
        },
        "log": {
            "file": 0
        }
    }
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(
            supplied_configuration)
        supplied_arguments = [
            "-c",
            configuration_file,
            "scan",
            "test/resources/rules/md047/end_with_blank_line.md",
        ]

        expected_return_code = 1
        expected_output = ""
        expected_error = "Configuration Error: The value for property 'log.file' must be of type 'str'.\n"

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(expected_output, expected_error,
                                       expected_return_code)
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 13
0
def test_md024_good_different_inline_heading_content_atx():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md021 directory that has good atx heading start spacing
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "test/resources/rules/md024/different_inline_heading_content_atx.md",
    ]

    expected_return_code = 0
    expected_output = ""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
def test_markdown_with_extensions_list_and_filter_by_id_ends_with_non_sequence():
    """
    Test to make sure the command line interface to extensions
    lists the matching items (none) when presented with an identifier
    that does not match any extension.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["extensions", "list", "this-is-not-an-used-identifier"]

    expected_return_code = 0
    expected_output = """No extension identifier matches the pattern 'this-is-not-an-used-identifier'."""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
Esempio n. 15
0
def test_markdown_with_dash_l_on_non_matching_globbed_files():
    """
    Test to make sure we get a failure if '-l' is supplied with a
    globbed file path that works but does not find any matching files.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["scan", "-l", "rules/md001/z*.md"]

    expected_return_code = 1
    expected_output = """"""
    expected_error = (
        """Provided glob path 'rules/md001/z*.md' did not match any files.""")

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments,
                                          cwd=scanner.resource_directory)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 16
0
def test_markdown_with_dash_l_on_mixed_directories():
    """
    Test to make sure we get the path to a single file if '-l' is supplied
    with multiple paths containing a simple md file.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["scan", "-l", "only-text", "simple"]

    expected_return_code = 0
    expected_output = """simple/simple.md
"""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments,
                                          cwd=scanner.resource_directory)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 17
0
def test_md009_bad_paragraph_increasing_extra_with_config_strict():
    """
    Test to make sure this rule does trigger with a document that
    has increasing amounts trailing spaces at the end of lines, and
    configuration set to strict.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "--set",
        "plugins.md009.strict=$!True",
        "--strict-config",
        "scan",
        "test/resources/rules/md009/bad_paragraph_increasing_extra.md",
    ]

    expected_return_code = 1
    expected_output = (
        "test/resources/rules/md009/bad_paragraph_increasing_extra.md:1:18: " +
        "MD009: Trailing spaces " +
        "[Expected: 0; Actual: 1] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_paragraph_increasing_extra.md:2:19: " +
        "MD009: Trailing spaces " +
        "[Expected: 0; Actual: 2] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_paragraph_increasing_extra.md:3:20: " +
        "MD009: Trailing spaces " +
        "[Expected: 0; Actual: 3] (no-trailing-spaces)\n" +
        "test/resources/rules/md009/bad_paragraph_increasing_extra.md:4:17: " +
        "MD009: Trailing spaces " +
        "[Expected: 0; Actual: 2] (no-trailing-spaces)")
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 18
0
def test_markdown_with_dash_l_on_non_md_file():
    """
    Test to make sure we get help if '-l' is supplied with a file path that isn't a md file.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["-l", "only-text/simple_text_file.txt"]

    expected_return_code = 1
    expected_output = ""
    expected_error = """Provided file path 'only-text/simple_text_file.txt' is not a valid markdown file. Skipping.
No Markdown files found.
"""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments,
                                          cwd=scanner.resource_directory)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
def test_markdown_with_dash_dash_add_plugin_with_bad_string_detail_from_configuration():
    """
    Test to make sure we get an error logged if a plugin throws an exception that a string detail is bad.
    Note: this version loads from configuration.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {
        "plugins": {
            "additional_paths": "test/resources/plugins/bad/bad_string_detail_is_int.py"
        }
    }
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(supplied_configuration)
        supplied_arguments = [
            "-c",
            configuration_file,
            "scan",
            "test/resources/rules/md047/end_with_blank_line.md",
        ]

        expected_return_code = 1
        expected_output = ""
        expected_error = """\n\nBadPluginError encountered while loading plugins:
Plugin class 'BadStringDetailIsInt' returned an improperly typed value for field name 'plugin_description'.
"""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(
            expected_output, expected_error, expected_return_code
        )
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
def test_markdown_with_plugins_list_and_bad_filter():
    """
    Test to make sure that `plugins list` errors when provided an overly generic filter.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["plugins", "list", "*"]

    expected_return_code = 2
    expected_output = ""
    expected_error = """usage: main.py plugins list [-h] [--all] [list_filter]
main.py plugins list: error: argument list_filter: Value '*' is not a valid pattern for an id or a name.
"""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )
Esempio n. 21
0
def test_md024_bad_same_heading_in_siblings_setext_with_configuration():
    """
    Test to make sure this rule does trigger with a document that
    contains SetExt headings with duplicate content in siblings with configuration.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {"plugins": {"md024": {"siblings_only": True}}}
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(
            supplied_configuration)
        supplied_arguments = [
            "--disable-rules",
            "md025",
            "-c",
            configuration_file,
            "scan",
            "test/resources/rules/md024/same_heading_in_siblings_setext.md",
        ]

        expected_return_code = 1
        expected_output = (
            "test/resources/rules/md024/same_heading_in_siblings_setext.md:7:1: "
            +
            "MD024: Multiple headings cannot contain the same content. (no-duplicate-heading,no-duplicate-header)\n"
        )
        expected_error = ""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(expected_output, expected_error,
                                       expected_return_code)
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 22
0
def test_md002_bad_proper_setext_heading_start_with_alternate_configuration():
    """
    Test to make sure the rule does trigger with a level 1 SetExt Heading at the
    start of the document and configuration to change level to `2`.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_configuration = {"plugins": {"md002": {"level": 2}}}
    configuration_file = None
    try:
        configuration_file = write_temporary_configuration(
            supplied_configuration)
        supplied_arguments = [
            "--enable-rules",
            "MD002",
            "-c",
            configuration_file,
            "scan",
            "test/resources/rules/md002/proper_setext_heading_start.md",
        ]

        expected_return_code = 1
        expected_output = (
            "test/resources/rules/md002/proper_setext_heading_start.md:2:1: " +
            "MD002: First heading of the document should be a top level heading. "
            +
            "[Expected: h2; Actual: h1] (first-heading-h1,first-header-h1)\n")
        expected_error = ""

        # Act
        execute_results = scanner.invoke_main(arguments=supplied_arguments)

        # Assert
        execute_results.assert_results(expected_output, expected_error,
                                       expected_return_code)
    finally:
        if configuration_file and os.path.exists(configuration_file):
            os.remove(configuration_file)
Esempio n. 23
0
def test_markdown_with_dash_l_on_bad_path():
    """
    Test to make sure we get help if '-l' is supplied with a bad path.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["-l", "my-bad-path"]

    expected_return_code = 1
    expected_output = ""
    expected_error = """Provided path 'my-bad-path' does not exist. Skipping.
No Markdown files found.
"""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments,
                                          cwd=scanner.resource_directory)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 24
0
def test_md003_good_consistent_headings_setext():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md003 directory that has only setext headings.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "test/resources/rules/md003/headings_setext.md",
    ]

    expected_return_code = 0
    expected_output = CONSISTENT_SETEXT_HEADINGS_SAMPLE_OUTPUT
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 25
0
def test_markdown_with_dash_l_on_md_file():
    """
    Test to make sure we a single path to a file if '-l' is supplied with
    a file path that is a simple md file.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["scan", "-l", "simple/simple.md"]

    expected_return_code = 0
    expected_output = """simple/simple.md
"""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments,
                                          cwd=scanner.resource_directory)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 26
0
def test_md047_good_end_with_blank_line():
    """
    Test to make sure this rule does not trigger with a document that
    properly ends with a blank line.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "scan", "test/resources/rules/md047/end_with_blank_line.md"
    ]

    expected_return_code = 0
    expected_output = ""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 27
0
def test_md036_proper_headings_setext():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md036 directory that normal setext headings.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "test/resources/rules/md036/proper_headings_setext.md",
    ]

    expected_return_code = 0
    expected_output = ""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 28
0
def test_md001_good_proper_atx_heading_incrementing():
    """
    Test to make sure we get the expected behavior after scanning a good file from the
    test/resources/rules/md001 directory using atx headings.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "test/resources/rules/md001/proper_atx_heading_incrementing.md"
    ]

    expected_return_code = 0
    expected_output = ""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
Esempio n. 29
0
def test_pragmas_13():
    """
    Test the case where we specify a 'disable-next-line' pragma with a valid id to disable and extra whitespace
    after the pyml command.
    """
    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = [
        "scan",
        "test/resources/pragmas/atx_heading_with_multiple_spaces_disable_line_by_id_with_space_after_pyml_command.md",
    ]

    expected_return_code = 0
    expected_output = ""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(expected_output, expected_error,
                                   expected_return_code)
def test_markdown_with_extensions_list_only_all():
    """
    Test to make sure the command line interface to extensions
    only shows the installed extensions when asked for a list.
    With the -all flag.
    """

    # Arrange
    scanner = MarkdownScanner()
    supplied_arguments = ["extensions", "list", "--all"]

    expected_return_code = 0
    expected_output = """
  ID                     NAME                   ENABLED    ENABLED    VERSION
                                                (DEFAULT)  (CURRENT)

  front-matter           Front Matter Metadata  False      False      0.5.0
  linter-pragmas         Pragma Linter Instruc  True       True       0.5.0
                         tions
  markdown-disallow_raw  Markdown Disallow Raw  False      False      0.0.0
  _html                   HTML
  markdown-extended-aut  Markdown Extended Aut  False      False      0.0.0
  olinks                 olinks
  markdown-strikethroug  Markdown Strikethroug  False      False      0.0.0
  h                      h
  markdown-tables        Markdown Tables        False      False      0.0.0
  markdown-task-list-it  Markdown Task List It  False      False      0.0.0
  ems                    ems
"""
    expected_error = ""

    # Act
    execute_results = scanner.invoke_main(arguments=supplied_arguments)

    # Assert
    execute_results.assert_results(
        expected_output, expected_error, expected_return_code
    )