def test_markdown_with_extensions_value_error_during_configuration(): """ Test to make sure the command line interface to extensions shows the exception text when the configuration fails due to an exception. """ # Arrange scanner = MarkdownScanner() supplied_configuration = { "extensions": {"debug-extension": {"enabled": True, "debug_mode": 2}} } configuration_file = None try: configuration_file = write_temporary_configuration(supplied_configuration) supplied_arguments = ["-c", configuration_file, "extensions", "list", "f*r"] expected_return_code = 1 expected_output = "" expected_error = """Configuration error ValueError encountered while initializing extensions: blah """ # 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_md002_good_improper_atx_heading_start_with_alternate_configuration(): """ Test to make sure the rule does not trigger with a level 2 Atx Heading at the start of the document and configuration to match. """ # 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/improper_atx_heading_start.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)
def test_markdown_with_extensions_list_and_filter_by_id_ends_with_r_and_configuration_false(): """ Test to make sure the command line interface to extensions only shows the installed extensions when asked for a list. With globbed and disabled extension. """ # Arrange scanner = MarkdownScanner() supplied_configuration = {"extensions": {"front-matter": {"enabled": False}}} configuration_file = None try: configuration_file = write_temporary_configuration(supplied_configuration) supplied_arguments = ["-c", configuration_file, "extensions", "list", "f*r"] expected_return_code = 0 expected_output = """ ID NAME ENABLED ENABLED VERSION (DEFAULT) (CURRENT) front-matter Front Matter Metadata False False 0.5.0 """ 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)
def test_md024_good_same_heading_content_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 = [ "-c", configuration_file, "scan", "test/resources/rules/md024/same_heading_content_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) finally: if configuration_file and os.path.exists(configuration_file): os.remove(configuration_file)
def test_md036_bad_proper_emphasis_ending_with_punctuation_with_configuration( ): """ Test to make sure this rule does trigger with a document that contains an emphasis "heading" ending with punctuation, but not punctuation according to configuration. """ # Arrange scanner = MarkdownScanner() supplied_configuration = {"plugins": {"md036": {"punctuation": ".!"}}} configuration_file = None try: configuration_file = write_temporary_configuration( supplied_configuration) supplied_arguments = [ "-c", configuration_file, "scan", "test/resources/rules/md036/proper_emphasis_ending_with_punctuation.md", ] expected_return_code = 1 expected_output = ( "test/resources/rules/md036/proper_emphasis_ending_with_punctuation.md:1:1: " + "MD036: Emphasis possibly used instead of a heading element. (no-emphasis-as-heading,no-emphasis-as-header)\n" + "test/resources/rules/md036/proper_emphasis_ending_with_punctuation.md:5:1: " + "MD036: Emphasis possibly used instead of a heading element. (no-emphasis-as-heading,no-emphasis-as-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)
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_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)
def test_md024_bad_same_heading_in_siblings_atx_with_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": {"siblings_only": True}}} configuration_file = None try: configuration_file = write_temporary_configuration( supplied_configuration) supplied_arguments = [ "-c", configuration_file, "scan", "test/resources/rules/md024/same_heading_in_siblings_atx.md", ] expected_return_code = 1 expected_output = ( "test/resources/rules/md024/same_heading_in_siblings_atx.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)
def test_markdown_with_extensions_and_no_error_during_configuration(): """ Test to make sure the command line interface to extensions list the exception text when the initialization does not fail. """ # Arrange scanner = MarkdownScanner() supplied_configuration = { "extensions": {"debug-extension": {"enabled": True, "debug_mode": 0}} } configuration_file = None try: configuration_file = write_temporary_configuration(supplied_configuration) supplied_arguments = ["-c", configuration_file, "extensions", "list", "f*r"] expected_return_code = 0 expected_output = """ ID NAME ENABLED ENABLED VERSION (DEFAULT) (CURRENT) front-matter Front Matter Metadata False False 0.5.0 """ 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)