Beispiel #1
0
    def test_serializeOps(self):
        sb = Statebox(set(), _clock=mockClock())
        sb.modify(set.add, "foo")

        self.assertEquals(
            sb.serialize(sort_keys=True),
            (
                '{"last_modified": 1, "queue": [[1, "__builtin__.set.add", ["foo"], {}]], '
                '"value": {"__set__": ["foo"]}}'
            ),
        )
Beispiel #2
0
    def test_unseralizeOps(self):
        sb = Statebox.unserialize(
            (
                '{"last_modified": 1, "queue": '
                '[[1, "__builtin__.set.add", ["foo"], {}]], '
                '"value": {"__set__": ["foo"]}}'
            )
        )

        self.assertEquals(sb.value, set(["foo"]))
        self.assertEquals(sb.last_modified, 1)
        self.assertEquals(sb.queue, [(1, set.add, ["foo"], {})])
Beispiel #3
0
    def test_mergeBoxes(self):
        clock = mockClock()
        sb1 = Statebox(set(), _clock=clock)
        sb2 = Statebox(set(), _clock=clock)

        sb1.modify(set.add, "foo")
        sb2.modify(set.add, "bar")
        sb2.modify(set.add, "baz")

        sb1.merge(sb2)

        self.assertEquals(sb1.value, set(["foo", "bar", "baz"]))
        self.assertEquals(
            sorted(sb1.queue), [(2, set.add, ("foo",), {}), (3, set.add, ("bar",), {}), (4, set.add, ("baz",), {})]
        )

        self.assertEquals(sb1.last_modified, 4)
Beispiel #4
0
 def test_modifyValue(self):
     sb = Statebox(set(), _clock=mockClock())
     sb.modify(set.add, "foo")
     self.assertEquals(sb.value, set(["foo"]))
     self.assertEquals(sb.queue, [(1, set.add, ("foo",), {})])
Beispiel #5
0
 def test_serializeEmpty(self):
     sb = Statebox(_clock=mockClock())
     self.assertEquals(sb.serialize(sort_keys=True), '{"last_modified": 0, "queue": [], "value": null}')