Exemplo n.º 1
0
    def test_common_free(self):
        year_common_free = datetime.now().year - 71
        article = Article()
        self.assertTrue(article.common_free)
        # long enough dead
        article["TODESJAHR"].value = str(year_common_free)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = False
        self.assertTrue(article.common_free)
        # author dead not 71 year or more ago
        article["TODESJAHR"].value = str(year_common_free + 10)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = False
        self.assertFalse(article.common_free)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = True
        self.assertTrue(article.common_free)

        article = Article()
        # author Geburtsjahr
        article["GEBURTSJAHR"].value = str(year_common_free - 80)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = False
        self.assertTrue(article.common_free)
        # author birth not 151 year or more ago
        article["GEBURTSJAHR"].value = str(year_common_free - 70)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = False
        self.assertFalse(article.common_free)
        article["KEINE_SCHÖPFUNGSHÖHE"].value = True
        self.assertTrue(article.common_free)
Exemplo n.º 2
0
    def test_bug_corrupt_start_template(self):
        with self.assertRaises(ReDatenException):
            test_string = """{{REDaten
|{BAND=V,1
|SPALTE_START=1128
|SPALTE_END=OFF
}}
'''6)'''  Zu unterscheiden von diesem D. ist Dioskorides von Nikopolis, von welchem Anth. Pal. VII 178 (ausserhalb der Reihen) ein Epigramm erhalten ist. Unsicher ist VII 167.
{{REAutor|[Reitzenstein.}}"""
            Article.from_text(test_string)
Exemplo n.º 3
0
 def test_properties_init(self):
     article = Article(re_daten_properties={
         "BAND": "I 1",
         "NACHTRAG": True
     })
     self.assertEqual(article["BAND"].value_to_string(), "I 1")
     self.assertEqual(article["NACHTRAG"].value_to_string(), "ON")
Exemplo n.º 4
0
 def _init_page_dict(self):
     # find the positions of all key templates
     template_finder = TemplateFinder(self.pre_text)
     try:
         re_daten_pos = template_finder.get_positions(RE_DATEN)
         re_abschnitt_pos = template_finder.get_positions(RE_ABSCHNITT)
         re_author_pos = template_finder.get_positions(RE_AUTHOR)
     except TemplateFinderException as error:
         raise ReDatenException("There are corrupt templates.") from error
     re_starts = re_daten_pos + re_abschnitt_pos
     re_starts.sort(key=lambda x: x["pos"][0])
     if not re_starts:
         raise ReDatenException("No single start template found.")
     if len(re_starts) != len(re_author_pos):
         raise ReDatenException(
             "The count of start templates doesn't match the count of end templates.")
     # iterate over start and end templates of the articles and create ReArticles of them
     last_handled_char = 0
     for pos_daten, pos_author in zip(re_starts, re_author_pos):
         if last_handled_char < pos_daten["pos"][0]:
             # there is plain text in front of the article
             text_to_handle = self.pre_text[last_handled_char:pos_daten["pos"][0]].strip()
             if text_to_handle:
                 # not just whitespaces
                 self._article_list.append(text_to_handle)
         self._article_list.append(
             Article.from_text(self.pre_text[pos_daten["pos"][0]:pos_author["pos"][1]]))
         last_handled_char = pos_author["pos"][1]
     # handle text after the last complete article
     if last_handled_char < len(self.pre_text):
         self._article_list.append(self.pre_text[last_handled_char:len(self.pre_text)].strip())
Exemplo n.º 5
0
 def test_from_text(self):
     article_text = "{{REDaten\n|BAND=III\n|SPALTE_START=1\n}}\ntext\n{{REAutor|Some Author.}}"
     article = Article.from_text(article_text)
     self.assertEqual(article.author, ("Some Author.", ""))
     self.assertEqual(article.text, "text")
     self.assertEqual(article.article_type, "REDaten")
     self.assertEqual(article["BAND"].value, "III")
     self.assertEqual(article["SPALTE_START"].value, "1")
Exemplo n.º 6
0
    def test_bug_2(self):
        test_string = """{{REDaten
|BAND=XIV,1
|SPALTE_START=46
|SPALTE_END=
|VORGÄNGER=Lysippe 7
|NACHFOLGER=Lysippos 2
|SORTIERUNG=
|KORREKTURSTAND=unkorrigiert
|KSCH=on
|TJ=1962
|WIKIPEDIA=
|WIKISOURCE=
|GND=
}}
'''Lysippos. 1)''' Spartaner, führt unter König Agis und als sein Nachfolger Truppen gegen Elis (400/399): Xen. hell. IH 2 29f.
{{REAutor|Kahrstedt.}}"""
        Article.from_text(test_string)
Exemplo n.º 7
0
 def test_append(self):
     self.text_mock.return_value = ARTICLE_TEMPLATE
     re_page = RePage(self.page_mock)
     self.assertEqual(1, len(re_page))
     article_text = "{{REAbschnitt}}\ntext\n{{REAutor|Some Author.}}"
     article = Article.from_text(article_text)
     re_page.append(article)
     self.assertEqual(2, len(re_page))
     with self.assertRaises(TypeError):
         re_page.append(1)
Exemplo n.º 8
0
    def test_bug_1(self):
        test_string = """{{REDaten
|BAND=IV,1
|SPALTE_START=610
|SPALTE_END=OFF
|VORGÄNGER=Cominius 23
|NACHFOLGER=Cominius 25
|SORTIERUNG=
|KORREKTURSTAND=Platzhalter
|KSCH=OFF
|TJ=1950
|WIKIPEDIA=
|WIKISOURCE=
|VW=
}}
'''24)''' ''L. Cominius Vipsanius Salutaris, domo Roma, subproc(urator) ludi magni, proc(urator) alimentor(um) per Apuliam Calabriam Lucaniam Bruttios, proc. prov(inciae) Sicil(iae), proc. capiend(orum) vec(tigalium) (?), proc. prov. Baet(icae), a cognitionib(us) domini n(ostri) Imp(eratoris) etc. etc. <!-- L. Septimi Severi Pertinac(is) Augusti, p(erfectissimus) v(ir), optimus vir et integrissimus'', CIL II 1085 = [[Hermann Dessau|{{SperrSchrift|Dessau}}]] 1406 (Ilipa); die Ehrung durch einen Untergebenen in der Baetica erfolgte bei seinem Abgang aus der Provinz, als er zu den Cognitiones des Kaisers berufen wurde. Die ''Cominia L. fil. Vipsania Dignitas c(larissima)f(emina)'', CIL IX 2336, könnte seine Tochter sein. -->

{{REAutor|Stein.}}"""
        Article.from_text(test_string)
Exemplo n.º 9
0
    def test_hash(self):
        self.text_mock.return_value = ARTICLE_TEMPLATE
        re_page = RePage(self.page_mock)

        pre_hash = hash(re_page)
        re_page[0].text = "bada"
        self.assertNotEqual(pre_hash, hash(re_page))

        pre_hash = hash(re_page)
        re_page[0]["BAND"].value = "tada"
        self.assertNotEqual(pre_hash, hash(re_page))

        pre_hash = hash(re_page)
        article_text = "{{REAbschnitt}}\ntext\n{{REAutor|Some Author.}}"
        article = Article.from_text(article_text)
        re_page.append(article)
        self.assertNotEqual(pre_hash, hash(re_page))
Exemplo n.º 10
0
 def test_from_text_short_keywords(self):
     article_text = "{{REDaten|BD=I|SS=1|SE=2|VG=A|NF=B|SRT=TADA|KOR=fertig|WS=BLUB|WP=BLAB" \
                    "|GND=1234|KSCH=OFF|TJ=1949|ÜB=ON|VW=OFF|NT=ON}}" \
                    "\ntext\n{{REAutor|Some Author.}}"
     article = Article.from_text(article_text)
     self.assertEqual("I", article["BAND"].value)
     self.assertEqual("1", article["SPALTE_START"].value)
     self.assertEqual("2", article["SPALTE_END"].value)
     self.assertEqual("A", article["VORGÄNGER"].value)
     self.assertEqual("B", article["NACHFOLGER"].value)
     self.assertEqual("TADA", article["SORTIERUNG"].value)
     self.assertEqual("fertig", article["KORREKTURSTAND"].value)
     self.assertEqual("BLUB", article["WIKISOURCE"].value)
     self.assertEqual("BLAB", article["WIKIPEDIA"].value)
     self.assertEqual("1234", article["GND"].value)
     self.assertEqual("1949", article["TODESJAHR"].value)
     self.assertFalse(article["KEINE_SCHÖPFUNGSHÖHE"].value)
     self.assertTrue(article["ÜBERSCHRIFT"].value)
     self.assertFalse(article["VERWEIS"].value)
     self.assertTrue(article["NACHTRAG"].value)
Exemplo n.º 11
0
 def test_bug_common_free(self):
     article = Article()
     article["TODESJAHR"].value = "bla1234"
     self.assertTrue(article.common_free)
Exemplo n.º 12
0
 def test_wrong_type_text(self):
     with self.assertRaisesRegex(ReDatenException,
                                 "Property text must be a string."):
         Article(text=1)
Exemplo n.º 13
0
 def test_from_text_wrong_order_of_templates(self):
     article_text = "{{REAutor}}{{REDaten}}\ntext"
     with self.assertRaisesRegex(
             ReDatenException,
             "Article has the wrong structure. Wrong order of templates."):
         Article.from_text(article_text)
Exemplo n.º 14
0
 def test_from_text_bug_bad_whitespace(self):
     article_text = "{{REDaten \n|BAND=I,1}}\ntext\n{{REAutor|Some Author.}}"
     article = Article.from_text(article_text)
     self.assertEqual(article.article_type, "REDaten")
Exemplo n.º 15
0
 def test_simple_article(self):
     article_text = "{{REDaten}}text{{REAutor|Autor.}}"
     article = Article.from_text(article_text)
     self.assertEqual("text", article.text)
Exemplo n.º 16
0
 def test_from_text_no_REAuthor_templates(self):
     article_text = "{{REDaten}}\ntext\n"
     with self.assertRaisesRegex(
             ReDatenException, "Article has the wrong structure. "
             "There must one stop template"):
         Article.from_text(article_text)
Exemplo n.º 17
0
 def test_correct_case(self):
     article_text = "{{REDaten\n|Nachtrag=OFF|Ksch=OFF\n}}\ntext\n{{REAutor|Autor.}}"
     article = Article.from_text(article_text)
     self.assertEqual(ARTICLE_TEMPLATE, article.to_text())
Exemplo n.º 18
0
 def test_complete_article(self):
     article_text = ARTICLE_TEMPLATE
     Article.from_text(article_text)
Exemplo n.º 19
0
 def test_set_text(self):
     self.assertEqual(self.article.text, "")
     self.article.text = "bla"
     self.assertEqual(self.article.text, "bla")
     article = Article(text="blub")
     self.assertEqual(article.text, "blub")
Exemplo n.º 20
0
 def test_from_text_REAbschnitt(self):
     article_text = "{{REAbschnitt}}\ntext\n{{REAutor|Some Author.}}"
     article = Article.from_text(article_text)
     self.assertEqual(article.article_type, "REAbschnitt")
Exemplo n.º 21
0
 def test_wrong_article_type(self):
     with self.assertRaisesRegex(
             ReDatenException, "ReStuff is not a permitted article type."):
         Article(article_type="ReStuff")
Exemplo n.º 22
0
 def test_set_author(self):
     self.assertEqual(self.article.author, ("", ""))
     self.article.author = "bla"
     self.assertEqual(self.article.author, ("bla", ""))
     article = Article(author=("blub", "II,2"))
     self.assertEqual(article.author, ("blub", "II,2"))
Exemplo n.º 23
0
 def test_wrong_type_author(self):
     with self.assertRaises(ReDatenException):
         Article(author=1)
Exemplo n.º 24
0
 def test_bug_dot_added_to_author(self):
     article_text = "{{REAbschnitt}}\ntext\n{{REAutor|S.A.†}}"
     article = Article.from_text(article_text)
     self.assertIn("{{REAutor|S.A.†}}", article.to_text())
Exemplo n.º 25
0
 def test_properties_exception(self):
     with self.assertRaises(ReDatenException):
         Article(re_daten_properties={"BAND": 1})
Exemplo n.º 26
0
 def test_bug_issue_number_deleted_from_author(self):
     article_text = "{{REAbschnitt}}\ntext\n{{REAutor|Some Author.|I,1}}"
     article = Article.from_text(article_text)
     compare("I,1", article.author[1])
     self.assertIn("{{REAutor|Some Author.|I,1}}", article.to_text())
Exemplo n.º 27
0
 def test_simple_article_with_whitespaces(self):
     article_text = "{{REDaten}}\n\n\t   text\t   {{REAutor|Autor.}}"
     article = Article.from_text(article_text)
     self.assertEqual("text", article.text)
Exemplo n.º 28
0
 def test_bug_issue_OFF_deleted_from_author_no_OFF(self):
     article_text = "{{REAbschnitt}}\ntext\n{{REAutor|A. Author.}}"
     article = Article.from_text(article_text)
     self.assertIn("{{REAutor|A. Author.}}", article.to_text())
Exemplo n.º 29
0
 def test_bug_shortened_parameter(self):
     article_text = "{{REDaten\n|GEBURTS=1900\n}}\ntest.\n{{REAutor|Author.}}"
     article = Article.from_text(article_text)
     self.assertEqual("1900", article["GEBURTSJAHR"].value)
Exemplo n.º 30
0
 def test_from_text_text_after_article(self):
     article_text = "{{REDaten}}text{{REAutor}}text"
     with self.assertRaisesRegex(
             ReDatenException, "Article has the wrong structure. "
             "There is text after the article."):
         Article.from_text(article_text)