Beispiel #1
0
 async def stream_items():
     yield ('k1', SetManagerOperation(
         action=SetAction.ADD,
         member='v',
     ))
     yield ('k2',
            SetManagerOperation(
                action=SetAction.DISCARD,
                member='v2',
            ))
     yield ('k3',
            SetManagerOperation(
                action=SetAction.DISCARD,
                member=X(10, 30).to_representation(),
            ))
     yield ('k4', unknown_set_op)
Beispiel #2
0
 async def test__send_operation__enabled(self, *, man):
     man.enabled = True
     man.topic.send = AsyncMock()
     await man._send_operation(SetAction.ADD, 'k', 'v')
     man.topic.send.assert_called_once_with(
         key='k',
         value=SetManagerOperation(action=SetAction.ADD, member='v'),
     )
Beispiel #3
0
    async def test__modify_set(self, *, man):
        stream = Mock()
        man.set_table = {
            'k1': Mock(),
            'k2': Mock(),
            'k3': Mock(),
            'k4': Mock(),
        }

        class X(faust.Record):
            x: int
            y: int

        unknown_set_op = SetManagerOperation(
            action=SetAction.ADD,
            member='v4',
        )
        unknown_set_op.action = 'UNKNOWN'

        async def stream_items():
            yield ('k1', SetManagerOperation(
                action=SetAction.ADD,
                member='v',
            ))
            yield ('k2',
                   SetManagerOperation(
                       action=SetAction.DISCARD,
                       member='v2',
                   ))
            yield ('k3',
                   SetManagerOperation(
                       action=SetAction.DISCARD,
                       member=X(10, 30).to_representation(),
                   ))
            yield ('k4', unknown_set_op)

        stream.items.side_effect = stream_items

        await man._modify_set(stream)

        man.set_table['k1'].add.assert_called_with('v')
        man.set_table['k2'].discard.assert_called_with('v2')
        man.set_table['k3'].discard.assert_called_with(X(10, 30))
Beispiel #4
0
 async def test__send_operation__enabled__iterator(self, *, man):
     man.enabled = True
     man.topic.send = AsyncMock()
     await man._send_operation(SetAction.ADD, "k", iter(["a", "b"]))
     man.topic.send.assert_called_once_with(
         key="k",
         value=SetManagerOperation(
             action=SetAction.ADD,
             members=["a", "b"],
         ),
     )
Beispiel #5
0
 async def stream_items():
     yield ('k1',
            SetManagerOperation(
                action=SetAction.ADD,
                members=['v'],
            ))
     yield ('k2',
            SetManagerOperation(
                action=SetAction.DISCARD,
                members=['v2'],
            ))
     yield ('k3',
            SetManagerOperation(
                action=SetAction.DISCARD,
                members=[X(10, 30).to_representation()],
            ))
     yield ('k4', unknown_set_op)
     yield ('k5',
            SetManagerOperation(
                action=SetAction.ADD,
                members=[
                    X(10, 30).to_representation(),
                    X(20, 40).to_representation(),
                    'v3',
                ],
            ))
     yield ('k6',
            SetManagerOperation(
                action=SetAction.INTERSECTION,
                members=[
                    X(10, 30).to_representation(),
                    X(20, 40).to_representation(),
                    'v3',
                ],
            ))
     yield ('k7',
            SetManagerOperation(
                action=SetAction.SYMDIFF,
                members=[
                    X(10, 30).to_representation(),
                    X(20, 40).to_representation(),
                    'v3',
                ],
            ))
     yield ('k8',
            SetManagerOperation(
                action=SetAction.CLEAR,
                members=[],
            ))
Beispiel #6
0
 async def stream_items():
     yield (
         "k1",
         SetManagerOperation(
             action=SetAction.ADD,
             members=["v"],
         ),
     )
     yield (
         "k2",
         SetManagerOperation(
             action=SetAction.DISCARD,
             members=["v2"],
         ),
     )
     yield (
         "k3",
         SetManagerOperation(
             action=SetAction.DISCARD,
             members=[X(10, 30).to_representation()],
         ),
     )
     yield ("k4", unknown_set_op)
     yield (
         "k5",
         SetManagerOperation(
             action=SetAction.ADD,
             members=[
                 X(10, 30).to_representation(),
                 X(20, 40).to_representation(),
                 "v3",
             ],
         ),
     )
     yield (
         "k6",
         SetManagerOperation(
             action=SetAction.INTERSECTION,
             members=[
                 X(10, 30).to_representation(),
                 X(20, 40).to_representation(),
                 "v3",
             ],
         ),
     )
     yield (
         "k7",
         SetManagerOperation(
             action=SetAction.SYMDIFF,
             members=[
                 X(10, 30).to_representation(),
                 X(20, 40).to_representation(),
                 "v3",
             ],
         ),
     )
     yield (
         "k8",
         SetManagerOperation(
             action=SetAction.CLEAR,
             members=[],
         ),
     )
Beispiel #7
0
    async def test__modify_set(self, *, man):
        stream = Mock()
        man.set_table = {
            "k1": Mock(name="k1"),
            "k2": Mock(name="k2"),
            "k3": Mock(name="k3"),
            "k4": Mock(name="k4"),
            "k5": Mock(name="k5"),
            "k6": Mock(name="k6"),
            "k7": Mock(name="k7"),
            "k8": Mock(name="k8"),
        }

        class X(faust.Record):
            x: int
            y: int

        unknown_set_op = SetManagerOperation(
            action=SetAction.ADD,
            members=["v4"],
        )
        unknown_set_op.action = "UNKNOWN"

        async def stream_items():
            yield (
                "k1",
                SetManagerOperation(
                    action=SetAction.ADD,
                    members=["v"],
                ),
            )
            yield (
                "k2",
                SetManagerOperation(
                    action=SetAction.DISCARD,
                    members=["v2"],
                ),
            )
            yield (
                "k3",
                SetManagerOperation(
                    action=SetAction.DISCARD,
                    members=[X(10, 30).to_representation()],
                ),
            )
            yield ("k4", unknown_set_op)
            yield (
                "k5",
                SetManagerOperation(
                    action=SetAction.ADD,
                    members=[
                        X(10, 30).to_representation(),
                        X(20, 40).to_representation(),
                        "v3",
                    ],
                ),
            )
            yield (
                "k6",
                SetManagerOperation(
                    action=SetAction.INTERSECTION,
                    members=[
                        X(10, 30).to_representation(),
                        X(20, 40).to_representation(),
                        "v3",
                    ],
                ),
            )
            yield (
                "k7",
                SetManagerOperation(
                    action=SetAction.SYMDIFF,
                    members=[
                        X(10, 30).to_representation(),
                        X(20, 40).to_representation(),
                        "v3",
                    ],
                ),
            )
            yield (
                "k8",
                SetManagerOperation(
                    action=SetAction.CLEAR,
                    members=[],
                ),
            )

        stream.items.side_effect = stream_items

        await man._modify_set(stream)

        man.set_table["k1"].update.assert_called_with(["v"])
        man.set_table["k2"].difference_update.assert_called_with(["v2"])
        man.set_table["k3"].difference_update.assert_called_with([X(10, 30)])
        man.set_table["k5"].update.assert_called_with([
            X(10, 30),
            X(20, 40),
            "v3",
        ])
        man.set_table["k6"].intersection_update.assert_called_with([
            X(10, 30),
            X(20, 40),
            "v3",
        ])
        man.set_table["k7"].symmetric_difference_update.assert_called_with([
            X(10, 30),
            X(20, 40),
            "v3",
        ])
        man.set_table["k8"].clear.assert_called_once_with()
Beispiel #8
0
    async def test__modify_set(self, *, man):
        stream = Mock()
        man.set_table = {
            'k1': Mock(name='k1'),
            'k2': Mock(name='k2'),
            'k3': Mock(name='k3'),
            'k4': Mock(name='k4'),
            'k5': Mock(name='k5'),
            'k6': Mock(name='k6'),
            'k7': Mock(name='k7'),
            'k8': Mock(name='k8'),
        }

        class X(faust.Record):
            x: int
            y: int

        unknown_set_op = SetManagerOperation(
            action=SetAction.ADD,
            members=['v4'],
        )
        unknown_set_op.action = 'UNKNOWN'

        async def stream_items():
            yield ('k1',
                   SetManagerOperation(
                       action=SetAction.ADD,
                       members=['v'],
                   ))
            yield ('k2',
                   SetManagerOperation(
                       action=SetAction.DISCARD,
                       members=['v2'],
                   ))
            yield ('k3',
                   SetManagerOperation(
                       action=SetAction.DISCARD,
                       members=[X(10, 30).to_representation()],
                   ))
            yield ('k4', unknown_set_op)
            yield ('k5',
                   SetManagerOperation(
                       action=SetAction.ADD,
                       members=[
                           X(10, 30).to_representation(),
                           X(20, 40).to_representation(),
                           'v3',
                       ],
                   ))
            yield ('k6',
                   SetManagerOperation(
                       action=SetAction.INTERSECTION,
                       members=[
                           X(10, 30).to_representation(),
                           X(20, 40).to_representation(),
                           'v3',
                       ],
                   ))
            yield ('k7',
                   SetManagerOperation(
                       action=SetAction.SYMDIFF,
                       members=[
                           X(10, 30).to_representation(),
                           X(20, 40).to_representation(),
                           'v3',
                       ],
                   ))
            yield ('k8',
                   SetManagerOperation(
                       action=SetAction.CLEAR,
                       members=[],
                   ))

        stream.items.side_effect = stream_items

        await man._modify_set(stream)

        man.set_table['k1'].update.assert_called_with(['v'])
        man.set_table['k2'].difference_update.assert_called_with(['v2'])
        man.set_table['k3'].difference_update.assert_called_with([X(10, 30)])
        man.set_table['k5'].update.assert_called_with([
            X(10, 30),
            X(20, 40),
            'v3',
        ])
        man.set_table['k6'].intersection_update.assert_called_with([
            X(10, 30),
            X(20, 40),
            'v3',
        ])
        man.set_table['k7'].symmetric_difference_update.assert_called_with([
            X(10, 30),
            X(20, 40),
            'v3',
        ])
        man.set_table['k8'].clear.assert_called_once_with()