コード例 #1
0
    def test_basic(self) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)
        assert len(dm) == 0

        # module manager should only hold a weak ref
        assert len(gc.get_referrers(d)) == 0
コード例 #2
0
    def test_contains(self) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)
        assert len(dm) == 0

        m = Div(id="foo")

        dm["foo"] = m

        assert "foo" in dm
        assert "junk" not in dm
コード例 #3
0
    def test_invalidate(self, mock_recompute: MagicMock) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)

        with dm.freeze():
            dm.invalidate()
            assert not mock_recompute.called

        assert mock_recompute.call_count == 1

        dm.invalidate()
        assert mock_recompute.call_count == 2
コード例 #4
0
    def test_setitem_getitem(self) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)
        assert len(dm) == 0

        m = Div(id="foo")

        dm["foo"] = m
        assert len(dm) == 1

        assert dm["foo"] is m

        with pytest.raises(KeyError):
            dm["junk"]
コード例 #5
0
    def test_iter(self) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)
        assert len(dm) == 0

        m1 = Div()
        m2 = Div()
        m3 = Div()

        dm["m1"] = m1
        dm["m2"] = m2
        dm["m3"] = m3

        result = set()
        for m in dm:
            result.add(m)

        assert result == {m1, m2, m3}
コード例 #6
0
    def test_freeze(self, mock_recompute: MagicMock) -> None:
        d = Document()
        dm = bdm.DocumentModelManager(d)

        assert dm._freeze_count == 0

        with dm.freeze():
            assert dm._freeze_count == 1
            assert not mock_recompute.called

            with dm.freeze():
                assert dm._freeze_count == 2
                assert not mock_recompute.called

            assert dm._freeze_count == 1
            assert not mock_recompute.called

        assert dm._freeze_count == 0
        assert mock_recompute.called  # called here