def test_insert_rewrite():
    n = SegmentSplicer().insert_blank_segment_after(Ref("Shabbat 45b:11"))
    assert n._needs_rewrite(Ref("Shabbat 45b:15"))
    assert n._needs_rewrite(Ref("Shabbat 45b:12"))
    assert not n._needs_rewrite(Ref("Shabbat 45b:9"))
    assert not n._needs_rewrite(Ref("Shabbat 45b:11"))
    assert not n._needs_rewrite(Ref("Shabbat 45b"))
    assert not n._needs_rewrite(Ref("Shabbat 44b:11"))
    assert not n._needs_rewrite(Ref("Shabbat 46b:11"))

    assert not n._needs_rewrite(Ref("Rif Shabbat 45b:15"))

    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:15"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:12"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:15:2"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:12:1"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b:9"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b:11"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 44b:11"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 46b:11"), commentary=True)

    assert n._rewrite(Ref("Shabbat 45b:15")) == Ref("Shabbat 45b:16")
    assert n._rewrite(Ref("Shabbat 45b:12")) == Ref("Shabbat 45b:13")

    assert n._rewrite(Ref("Rashi on Shabbat 45b:15:1"), commentary=True) == Ref("Rashi on Shabbat 45b:16:1")
    assert n._rewrite(Ref("Rashi on Shabbat 45b:15"), commentary=True) == Ref("Rashi on Shabbat 45b:16")
    assert n._rewrite(Ref("Rashi on Shabbat 45b:12:1"), commentary=True) == Ref("Rashi on Shabbat 45b:13:1")
def test_join_rewrite():
    n = SegmentSplicer().splice_next_into_this(Ref("Shabbat 45b:11"))
    assert n._needs_rewrite(Ref("Shabbat 45b:15"))
    assert n._needs_rewrite(Ref("Shabbat 45b:12"))
    assert not n._needs_rewrite(Ref("Shabbat 45b:9"))
    assert not n._needs_rewrite(Ref("Shabbat 45b:11"))
    assert not n._needs_rewrite(Ref("Shabbat 45b"))
    assert not n._needs_rewrite(Ref("Shabbat 44b:11"))
    assert not n._needs_rewrite(Ref("Shabbat 46b:11"))

    assert not n._needs_rewrite(Ref("Rif Shabbat 45b:15"))

    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:15"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:12"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:15:2"), commentary=True)
    assert n._needs_rewrite(Ref("Rashi on Shabbat 45b:12:1"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b:9"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b:11"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 45b"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 44b:11"), commentary=True)
    assert not n._needs_rewrite(Ref("Rashi on Shabbat 46b:11"), commentary=True)

    assert n._rewrite(Ref("Shabbat 45b:15")) == Ref("Shabbat 45b:14")
    assert n._rewrite(Ref("Shabbat 45b:12")) == Ref("Shabbat 45b:11")

    assert n._rewrite(Ref("Rashi on Shabbat 45b:15:1"), commentary=True) == Ref("Rashi on Shabbat 45b:14:1")
    assert n._rewrite(Ref("Rashi on Shabbat 45b:15"), commentary=True) == Ref("Rashi on Shabbat 45b:14")
    assert n._rewrite(Ref("Rashi on Shabbat 45b:12:1"), commentary=True) == Ref("Rashi on Shabbat 45b:11:2")  # There's already one comment on 11
def test_page_spanning_range():
    n = SegmentSplicer().insert_blank_segment_after(Ref("Chagigah 20b:13"))
    assert n._needs_rewrite(Ref("Chagigah 20b:14-21a:1"))
    assert n._rewrite(Ref("Chagigah 20b:14-21a:1")) == Ref("Chagigah 20b:15-21a:1")

    n = SegmentSplicer().splice_this_into_next(Ref("Chagigah 20b:13"))
    assert n._needs_rewrite(Ref("Chagigah 20b:14-21a:1"))
    assert n._rewrite(Ref("Chagigah 20b:14-21a:1")) == Ref("Chagigah 20b:13-21a:1")
def test_page_spanning_rewrite():
    n = SegmentSplicer().splice_this_into_next(Ref("Meilah 19b:1"))
    assert n._needs_rewrite(Ref("Meilah 19b:41-20a:5"))
    assert n._rewrite(Ref("Meilah 19b:41-20a:5")) == Ref("Meilah 19b:40-20a:5")

    n = SegmentSplicer().insert_blank_segment_after(Ref("Meilah 19b:1"))
    assert n._needs_rewrite(Ref("Meilah 19b:41-20a:5"))
    assert n._rewrite(Ref("Meilah 19b:41-20a:5")) == Ref("Meilah 19b:42-20a:5")
                            needs_refresh = True
                        except Exception as e:
                            print "(gf) Failed to splice {} into next: {}".format(current["ref"].normal(), e)
                else:
                    print u"(g0) Did not match 'Gemara' in {}".format(current["ref"].normal())
            else:
                print "Unexpect type: {}".format(current["type"])
                exit()

            # Adjust any later elements
            # Any element that needs adjustment, pop from booklist and put in next_list
            if change_made:
                for i, item in enumerate(booklist):
                    if splc._needs_rewrite(item["ref"]):
                        print "* Rewriting ref {} ...".format(item["ref"])
                        item["ref"] = splc._rewrite(item["ref"])
                        print "...to {}".format(item["ref"])
                        next_list.append(item)
                        booklist[i] = None
                booklist = [n for n in booklist if n is not None]

        except IndexError:
            # once booklist is done, refresh counts, move next_list to booklist, start again
            if splc:
                refresh_count += 1
                if live:
                    splc.refresh_states()
                    Ref.clear_cache()
            needs_refresh = False
            booklist = next_list
            next_list = []
Exemple #6
0
                            print "(gf) Failed to splice {} into next: {}".format(
                                current["ref"].normal(), e)
                else:
                    print u"(g0) Did not match 'Gemara' in {}".format(
                        current["ref"].normal())
            else:
                print "Unexpect type: {}".format(current["type"])
                exit()

            # Adjust any later elements
            # Any element that needs adjustment, pop from booklist and put in next_list
            if change_made:
                for i, item in enumerate(booklist):
                    if splc._needs_rewrite(item["ref"]):
                        print "* Rewriting ref {} ...".format(item["ref"])
                        item["ref"] = splc._rewrite(item["ref"])
                        print "...to {}".format(item["ref"])
                        next_list.append(item)
                        booklist[i] = None
                booklist = [n for n in booklist if n is not None]

        except IndexError:
            # once booklist is done, refresh counts, move next_list to booklist, start again
            if splc:
                refresh_count += 1
                if live:
                    splc.refresh_states()
                    Ref.clear_cache()
            needs_refresh = False
            booklist = next_list
            next_list = []