def test_push_many_return_piece_of_data(self): node_a, node_b = MockNode(), MockNode() session_mock = MockSession(MockNetwork()) session_mock._id = "1" stream_mock = mock.MagicMock() def get_stream(_): return stream_mock def lambda_dummy(x, *_, **__): return x pipe = ZeroPipe(node_a, node_b, filters=[FNFilter(lambda_dummy)], filters_threshold=2) pipe.get_stream = mock.MagicMock(side_effect=get_stream) res = pipe.push(list(range(5)), session_mock, many=True, test_kw=1) assert res is True pipe.get_stream.assert_called_once_with(session_mock) stream_mock.write.assert_called_once_with(list(range(2, 5)), many=True, test_kw=1)
def test_push_many(self): node_a, node_b = MockNode(), MockNode() session_mock = MockSession(MockNetwork()) session_mock._id = "1" stream_mock = mock.MagicMock() def get_stream(_): return stream_mock pipe = ZeroPipe(node_a, node_b) pipe.get_stream = mock.MagicMock(side_effect=get_stream) res = pipe.push([...], session_mock, many=True, test_kw=1) assert res is True pipe.get_stream.assert_called_once_with(session_mock) stream_mock.write.assert_called_once_with([...], many=True, test_kw=1)
def test_push_many_return_empty(self): node_a, node_b = MockNode(), MockNode() session_mock = MockSession(MockNetwork()) session_mock._id = "1" stream_mock = mock.MagicMock() def get_stream(_): return stream_mock def lambda_null(*_, **__): return 0 pipe = ZeroPipe(node_a, node_b, filters=[FNFilter(lambda_null)]) pipe.get_stream = mock.MagicMock(side_effect=get_stream) res = pipe.push(list(range(5)), session_mock, many=True, test_kw=1) assert res is False pipe.get_stream.assert_not_called() stream_mock.write.assert_not_called()