def test_update_lines_raises_exception_if_invalid_signs(
        corpus, text_repository, bibliography, when) -> None:
    lines = LinesUpdate([], set(), dict(enumerate(CHAPTER.lines)))
    when(text_repository).find_chapter(
        CHAPTER.id_).thenReturn(CHAPTER_WITHOUT_DOCUMENTS)
    expect_bibliography(bibliography, when)

    with pytest.raises(DataError):
        corpus.update_lines(CHAPTER.id_, lines, ANY_USER)
Esempio n. 2
0
def update_text(corpus: Corpus, text: Text) -> None:
    user = ApiUser("update_texts.py")
    for chapter_listing in text.chapters:
        chapter_id = ChapterId(text.id, chapter_listing.stage,
                               chapter_listing.name)
        chapter = corpus.find_chapter(chapter_id)
        corpus.update_lines(
            chapter_id,
            LinesUpdate([], set(), dict(enumerate(chapter.lines))),
            user,
        )
def test_updating_lines_edit(corpus, text_repository, bibliography, changelog,
                             signs, sign_repository, user, when) -> None:
    updated_chapter = attr.evolve(
        CHAPTER,
        lines=(attr.evolve(
            CHAPTER.lines[0],
            number=LineNumber(1, True),
            variants=(attr.evolve(
                CHAPTER.lines[0].variants[0],
                manuscripts=(attr.evolve(
                    CHAPTER.lines[0].variants[0].manuscripts[0],
                    line=TextLine.of_iterable(
                        LineNumber(1, True),
                        (Word.of([
                            Reading.of_name("nu"),
                            Joiner.hyphen(),
                            BrokenAway.open(),
                            Reading.of_name("ku"),
                            Joiner.hyphen(),
                            Reading.of_name("ši"),
                            BrokenAway.close(),
                        ]), ),
                    ),
                ), ),
            ), ),
        ), ),
        signs=("ABZ075 KU ABZ207a\\u002F207b\\u0020X\nKU\nABZ075", ),
        parser_version=ATF_PARSER_VERSION,
    )
    expect_find_and_update_chapter(
        bibliography,
        changelog,
        CHAPTER_WITHOUT_DOCUMENTS,
        updated_chapter,
        signs,
        sign_repository,
        text_repository,
        user,
        when,
    )

    assert (corpus.update_lines(
        CHAPTER.id_, LinesUpdate([], set(), {0: updated_chapter.lines[0]}),
        user) == updated_chapter)
def test_updating_lines_delete(corpus, text_repository, bibliography,
                               changelog, signs, sign_repository, user,
                               when) -> None:
    updated_chapter = attr.evolve(
        CHAPTER,
        lines=CHAPTER.lines[1:],
        signs=("KU\nABZ075", ),
        parser_version=ATF_PARSER_VERSION,
    )
    expect_find_and_update_chapter(
        bibliography,
        changelog,
        CHAPTER_WITHOUT_DOCUMENTS,
        updated_chapter,
        signs,
        sign_repository,
        text_repository,
        user,
        when,
    )

    assert (corpus.update_lines(CHAPTER.id_, LinesUpdate([], {0}, {}),
                                user) == updated_chapter)
Esempio n. 5
0
 def import_lines(self, id_: ChapterId, atf: str, user: User) -> Chapter:
     chapter = self.find_chapter(id_)
     lines = parse_chapter(atf, chapter.manuscripts)
     return self.update_lines(id_, LinesUpdate(lines, set(), {}), user)
def test_merging_lines(corpus, text_repository, bibliography, changelog, signs,
                       sign_repository, user, when) -> None:
    reconstruction = (
        LanguageShift.normalized_akkadian(),
        AkkadianWord.of((ValueToken.of("buāru"), )),
    )
    is_second_line_of_parallelism = False
    is_beginning_of_section = False
    text_line = TextLine.of_iterable(
        LineNumber(1),
        (
            Word.of([Reading.of_name("ku")],
                    unique_lemma=(WordId("word1"), ),
                    alignment=0),
            Word.of([Reading.of_name("nu")],
                    unique_lemma=(WordId("word2"), ),
                    alignment=1),
        ),
    )
    manuscript_id = CHAPTER_WITHOUT_DOCUMENTS.manuscripts[0].id
    line = Line(
        LineNumber(1),
        (LineVariant(
            reconstruction,
            None,
            (ManuscriptLine(manuscript_id, tuple(), text_line), ),
        ), ),
        not is_second_line_of_parallelism,
        not is_beginning_of_section,
    )
    new_text_line = TextLine.of_iterable(
        LineNumber(1),
        (Word.of([Reading.of_name("ku")]), Word.of([Reading.of_name("ba")])),
    )
    new_line = Line(
        LineNumber(1),
        (LineVariant(
            reconstruction,
            None,
            (ManuscriptLine(manuscript_id, tuple(),
                            text_line.merge(new_text_line)), ),
        ), ),
        is_second_line_of_parallelism,
        is_beginning_of_section,
    )
    old_chapter = attr.evolve(CHAPTER_WITHOUT_DOCUMENTS, lines=(line, ))
    updated_chapter = attr.evolve(
        CHAPTER,
        lines=(new_line, ),
        signs=("KU BA\nKU\nABZ075", ),
        parser_version=ATF_PARSER_VERSION,
    )
    expect_find_and_update_chapter(
        bibliography,
        changelog,
        old_chapter,
        updated_chapter,
        signs,
        sign_repository,
        text_repository,
        user,
        when,
    )

    assert (corpus.update_lines(
        CHAPTER.id_,
        LinesUpdate(
            [],
            set(),
            {
                0:
                Line(
                    LineNumber(1),
                    (LineVariant(
                        reconstruction,
                        None,
                        (ManuscriptLine(manuscript_id, tuple(),
                                        new_text_line), ),
                    ), ),
                    is_second_line_of_parallelism,
                    is_beginning_of_section,
                )
            },
        ),
        user,
    ) == updated_chapter)
 def make_lines_update(self, data: dict, **kwargs) -> LinesUpdate:
     return LinesUpdate(data["new"], set(data["deleted"]),
                        dict(data["edited"]))