Skip to content

Commit

Permalink
Merge pull request swcarpentry#115 from abought/114_errmsg_fixes
Browse files Browse the repository at this point in the history
Validator logging QA bugfixes
  • Loading branch information
Raniere Silva committed Jan 7, 2015
2 parents 3600079 + 8fd487b commit 40c84e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
42 changes: 19 additions & 23 deletions tools/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _validate_doc_headers(self):
for h in missing_headings:
logging.error("In {0}: "
"Header section is missing expected "
"row {1}".format(self.filename, h))
"row '{1}'".format(self.filename, h))

return has_hrs and all(test_headers) and only_headers

Expand Down Expand Up @@ -371,9 +371,9 @@ def _validate_learning_objective(self):
if node_tests is False:
logging.error(
"In {0}: "
"Learning Objectives should not be empty.".format(
self.filename))

"Page should contain a blockquoted section with level 2 "
"title 'Learning Objectives'. Section should not "
"be empty.".format(self.filename))
return node_tests

def _validate_has_no_headings(self):
Expand All @@ -385,17 +385,13 @@ def _validate_has_no_headings(self):
if len(heading_nodes) == 0:
return True

# Individual heading msgs are logged by validate_section_heading_order
logging.error(
"In {0}: "
"The topic page should not have sub-headings "
"outside of special blocks. "
"If a topic needs sub-headings, "
"it should be broken into multiple topics.".format(self.filename))
for n in heading_nodes:
logging.warning(
"In {0}: "
"The following sub-heading should be removed: {1}".format(
self.filename, n.strings[0]))
return False

def _run_tests(self):
Expand Down Expand Up @@ -433,31 +429,31 @@ def _validate_glossary_entry(self, glossary_entry):
glossary_keyword = glossary_entry[0]
if len(glossary_entry) < 2:
logging.error(
"In {0}:"
"Glossary entry '{1}' must have at least two lines- "
"a term and a definition.".format(
glossary_keyword, self.filename))
"In {0}: "
"Glossary entry '{1}' must have at least two lines- "
"a term and a definition.".format(
self.filename, glossary_keyword))
return False

entry_is_valid = True
for line_index, line in enumerate(glossary_entry):
if line_index == 1:
if not re.match("^: ", line):
logging.error(
"In {0}:"
"At glossary entry '{1}' "
"First line of definition must "
"start with ': '.".format(
glossary_keyword, self.filename))
"In {0}: "
"At glossary entry '{1}' "
"First line of definition must "
"start with ': '.".format(
self.filename, glossary_keyword))
entry_is_valid = False
elif line_index > 1:
if not re.match("^ ", line):
logging.error(
"In {0}:"
"At glossary entry '{1}' "
"Subsequent lines of definition must "
"start with ' '.".format(
glossary_keyword, self.filename))
"In {0}: "
"At glossary entry '{1}' "
"Subsequent lines of definition must "
"start with ' '.".format(
self.filename, glossary_keyword, ))
entry_is_valid = False
return entry_is_valid

Expand Down
8 changes: 8 additions & 0 deletions tools/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ def test_headers_fail_because_invalid_content(self):
---""")
self.assertFalse(validator._validate_doc_headers())

def test_topic_page_should_have_no_headings(self):
"""Requirement according to spec; may be relaxed in future"""
validator = self._create_validator("""
## Heading that should not be present
Some text""")
self.assertFalse(validator._validate_has_no_headings())

def test_sample_file_passes_validation(self):
sample_validator = self.VALIDATOR(self.SAMPLE_FILE)
res = sample_validator.validate()
Expand Down

0 comments on commit 40c84e1

Please sign in to comment.