Beispiel #1
0
    async def test_unshift_works(self):
        oaq = aggregates.ObservableAsyncQueue()
        await oaq.put("9")
        await oaq.put("18")
        await oaq.put("27")
        await oaq.put("36")

        await oaq.unshift("0")
        self.assertListEqual(["0", "9", "18", "27", "36"], list(oaq.view))
Beispiel #2
0
 async def test_getter_does_cache(self):
     oaq = aggregates.ObservableAsyncQueue()
     await oaq.put("9")
     await oaq.put("18")
     await oaq.put("27")
     await oaq.put("36")
     view1 = oaq.view
     view2 = oaq.view
     self.assertIs(view1, view2)
Beispiel #3
0
 async def test_putter_does_uncache(self):
     oaq = aggregates.ObservableAsyncQueue()
     await oaq.put("9")
     await oaq.put("18")
     await oaq.put("27")
     await oaq.put("36")
     view1 = oaq.view
     await oaq.put("45")
     view2 = oaq.view
     self.assertNotEqual(view1, view2)
Beispiel #4
0
    async def test_getitem_uses_view(self):
        oaq = aggregates.ObservableAsyncQueue()
        await oaq.put("9")
        await oaq.put("18")
        await oaq.put("27")
        await oaq.put("36")

        view = oaq.view
        view.append("0")

        self.assertEqual("0", oaq[4])
Beispiel #5
0
    async def test_pop_works(self):
        oaq = aggregates.ObservableAsyncQueue()
        await oaq.put("9")
        await oaq.put("18")
        await oaq.put("27")
        await oaq.put("36")

        self.assertEqual("36", await oaq.pop())
        self.assertEqual("27", await oaq.pop())
        self.assertEqual("18", await oaq.pop())
        self.assertEqual("9", await oaq.pop())

        with self.assertRaises(IndexError):
            await oaq.pop()
Beispiel #6
0
    async def test_view_is_shallow_copy(self):
        oaq = aggregates.ObservableAsyncQueue()
        await oaq.put("9")
        await oaq.put("18")
        await oaq.put("27")
        await oaq.put("36")

        view = oaq.view
        self.assertListEqual(list(view), list(oaq._queue))
        self.assertEqual(view, oaq._queue)
        self.assertIsNot(view, oaq._queue)

        # Shallow copy should use the same inner refs. If they are not equal though,
        # we know that the order is messed up or items are not copied over right, as opposed
        # to it being a messed up shallow-copy issue.
        self.assertEqual(list(view)[2], list(oaq._queue)[2])
        self.assertIs(list(view)[2], list(oaq._queue)[2])