Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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, '')
Ejemplo n.º 8
0
 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, "")