def test_extract_labeled_paragraph(self): text = ('{first-label} First para\n\n' '{my-label} Second para\n\n' 'Third para\n\n' '{next-label}Fourth para') result = extract_labeled_paragraph('my-label', text) self.assertIn('Second para', result) self.assertIn('Third para', result)
def contents_resolver(reference): dest_section_label, dest_paragraph_label = resolve_reference(reference) try: dest_section = section_query.get(label=dest_section_label) except Section.DoesNotExist: return "" dest_paragraph = extract_labeled_paragraph(dest_paragraph_label, dest_section.contents, exact=False) return dest_paragraph
def test_extract_labeled_paragraph(self): text = ( "{first-label} First para\n\n" "{my-label} Second para\n\n" "Third para\n\n" "{next-label}Fourth para" ) result = extract_labeled_paragraph("my-label", text) self.assertIn("Second para", result) self.assertIn("Third para", result)
def test_extract_labeled_paragraph_startswith(self): text = ('{first-label} First para\n\n' '{my-label} Second para\n\n' 'Third para\n\n' '{my-label-1}Fourth para\n\n' '{my-label-2}Fifth para\n\n' '{next-label}Sixth para\n\n') result = extract_labeled_paragraph('my-label', text, exact=False) self.assertIn('Second para', result) self.assertIn('Third para', result) self.assertIn('Fourth para', result) self.assertIn('Fifth para', result)
def contents_resolver(reference): dest_section_label, dest_paragraph_label = resolve_reference(reference) try: dest_section = section_query.get(label=dest_section_label) except Section.DoesNotExist: return '' dest_paragraph = extract_labeled_paragraph( dest_paragraph_label, dest_section.contents, exact=False ) return dest_paragraph
def test_extract_labeled_paragraph_startswith(self): text = ( "{first-label} First para\n\n" "{my-label} Second para\n\n" "Third para\n\n" "{my-label-1}Fourth para\n\n" "{my-label-2}Fifth para\n\n" "{next-label}Sixth para\n\n" ) result = extract_labeled_paragraph("my-label", text, exact=False) self.assertIn("Second para", result) self.assertIn("Third para", result) self.assertIn("Fourth para", result) self.assertIn("Fifth para", result)
def test_extract_labeled_paragraph_not_found(self): text = ('{another-label} First para\n\n' '{next-label}Fourth para') result = extract_labeled_paragraph('my-label', text) self.assertEqual(result, '')
def test_extract_labeled_paragraph_not_found(self): text = "{another-label} First para\n\n" "{next-label}Fourth para" result = extract_labeled_paragraph("my-label", text) self.assertEqual(result, "")