# Path: featureflow/datawriter.py
# class BytesIODataWriter(BaseDataWriter):
#     def __init__(
#             self,
#             needs=None,
#             _id=None,
#             feature_name=None,
#             feature_version=None,
#             key_builder=None,
#             database=None,
#             event_log=None,
#             buffer_size_limit=None):
#         
#         super(BytesIODataWriter, self).__init__(
#             needs=needs,
#             key_builder=key_builder,
#             database=database)
# 
#         # set the buffer size limit to int32 max size if it isn't explicitly
#         # provided
#         self.buffer_size_limit = buffer_size_limit or (2 ** 31)
#         self.event_log = event_log
#         self.feature_version = feature_version
#         self._id = _id
#         self.feature_name = feature_name
#         self.content_type = needs.content_type
#         self._stream = BytesIO()
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         del self._stream
# 
#     def _process(self, data):
#         if len(data) < self.buffer_size_limit:
#             try:
#                 yield self._stream.write(data)
#             except TypeError:
#                 yield self._stream.write(data.encode())
#         else:
#             chunksize = self.buffer_size_limit // 2
#             for i in range(0, len(data), chunksize):
#                 yield self._stream.write(data[i: i + chunksize])
# 
# Path: featureflow/encoder.py
# class IdentityEncoder(Node):
#     content_type = 'application/octet-stream'
# 
#     def __init__(self, needs=None):
#         super(IdentityEncoder, self).__init__(needs=needs)
# 
#     def _seed(self):
#         return b''
# 
#     def _enqueue(self, data, pusher):
#         self._cache = data if data else self._seed()


import unittest2
from .datawriter import BytesIODataWriter
from .encoder import IdentityEncoder


class StringIODataWriterTests(unittest2.TestCase):
    def test_overflow(self):
        buffer_size_limit = 128
        writer = BytesIODataWriter(
            needs=IdentityEncoder(), buffer_size_limit=buffer_size_limit)

# Path: featureflow/datawriter.py
# class BytesIODataWriter(BaseDataWriter):
#     def __init__(
#             self,
#             needs=None,
#             _id=None,
#             feature_name=None,
#             feature_version=None,
#             key_builder=None,
#             database=None,
#             event_log=None,
#             buffer_size_limit=None):
#         
#         super(BytesIODataWriter, self).__init__(
#             needs=needs,
#             key_builder=key_builder,
#             database=database)
# 
#         # set the buffer size limit to int32 max size if it isn't explicitly
#         # provided
#         self.buffer_size_limit = buffer_size_limit or (2 ** 31)
#         self.event_log = event_log
#         self.feature_version = feature_version
#         self._id = _id
#         self.feature_name = feature_name
#         self.content_type = needs.content_type
#         self._stream = BytesIO()
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         del self._stream
# 
#     def _process(self, data):
#         if len(data) < self.buffer_size_limit:
#             try:
#                 yield self._stream.write(data)
#             except TypeError:
#                 yield self._stream.write(data.encode())
#         else:
#             chunksize = self.buffer_size_limit // 2
#             for i in range(0, len(data), chunksize):
#                 yield self._stream.write(data[i: i + chunksize])
# 
# Path: featureflow/encoder.py
# class IdentityEncoder(Node):
#     content_type = 'application/octet-stream'
# 
#     def __init__(self, needs=None):
#         super(IdentityEncoder, self).__init__(needs=needs)
# 
#     def _seed(self):
#         return b''
# 
#     def _enqueue(self, data, pusher):
#         self._cache = data if data else self._seed()


# Path: featureflow/test_datawriter.py
import unittest2
from .datawriter import BytesIODataWriter
from .encoder import IdentityEncoder



class StringIODataWriterTests(unittest2.TestCase):
    def test_overflow(self):
        buffer_size_limit = 128
        writer = BytesIODataWriter(
            needs=IdentityEncoder(), buffer_size_limit=buffer_size_limit)

        data = b'a' * buffer_size_limit