# Path: datarobot_batch_scoring/reader.py
# class FastReader(CSVReader):
#     """A reader that only reads the file in text mode but not parses it. """
# 
#     def __init__(self, fd, encoding, ui):
#         super(FastReader, self).__init__(fd, encoding, ui)
#         self._check_for_multiline_input()
#         reader = self._create_reader()
#         self.header = next(reader)
#         self.fieldnames = [c.strip() for c in self.header]
# 
#     def __iter__(self):
#         fd = Recoder(self.fd, self.encoding)
#         it = iter(fd)
#         next(it)  # skip header
#         return it
# 
#     def _check_for_multiline_input(self, peek_size=100):
#         # peek the first `peek_size` records for multiline CSV
#         reader = self._create_reader()
#         i = 0
#         for line in reader:
#             i += 1
#             if i == peek_size:
#                 break
# 
#         peek_size = min(i, peek_size)
# 
#         if reader.line_num != peek_size:
#             self._ui.fatal('Detected multiline CSV format'
#                            ' -- dont use flag `--fast` '
#                            'to force CSV parsing. '
#                            'Note that this will slow down scoring.')
# 
# class SlowReader(CSVReader):
#     """The slow reader does actual CSV parsing.
#     It supports multiline csv and can be a factor of 50 slower. """
# 
#     def __init__(self, fd, encoding, ui):
#         super(SlowReader, self).__init__(fd, encoding, ui)
#         reader = self._create_reader()
#         self.header = next(reader)
#         self.fieldnames = [c.strip() for c in self.header]
# 
#     def __iter__(self):
#         self.reader = self._create_reader()
#         warned = False
#         for i, row in enumerate(self.reader):
#             if i == 0:
#                 # skip header
#                 continue
# 
#             if len(row) == 0:
#                 if not warned:
#                     self._ui.warning('Detected empty rows in the CSV file. '
#                                      'These rows will be discarded.')
#                     warned = True
#                 continue
# 
#             yield row


import csv
import pytest
from mock import Mock
from datarobot_batch_scoring.reader import FastReader, SlowReader
        csv.register_dialect('dataset_dialect', csv.excel)

    @pytest.yield_fixture
    def really_big_fields_enabled(self):
        old_limit = csv.field_size_limit()
        csv.field_size_limit(2 ** 28)
        yield
        csv.field_size_limit(old_limit)

    def test_slow_reader_with_really_wide_field_fails_default(
            self, csv_file_handle_with_wide_field):
        reader = SlowReader(csv_file_handle_with_wide_field,
                            'utf-8',
                            ui=Mock())
        with pytest.raises(csv.Error):
            list(reader)

    @pytest.mark.usefixtures('really_big_fields_enabled')
    def test_slow_reader_can_succeed_if_override_csv_width(
            self, csv_file_handle_with_wide_field):
        reader = SlowReader(csv_file_handle_with_wide_field,
                            'utf-8',
                            ui=Mock())
        data = list(reader)
        assert len(data) == 4

    def test_fast_reader_with_really_wide_field_wont_even_instantiate_default(
            self,
            csv_file_handle_with_wide_field):
        with pytest.raises(csv.Error):

# Path: datarobot_batch_scoring/reader.py
# class FastReader(CSVReader):
#     """A reader that only reads the file in text mode but not parses it. """
# 
#     def __init__(self, fd, encoding, ui):
#         super(FastReader, self).__init__(fd, encoding, ui)
#         self._check_for_multiline_input()
#         reader = self._create_reader()
#         self.header = next(reader)
#         self.fieldnames = [c.strip() for c in self.header]
# 
#     def __iter__(self):
#         fd = Recoder(self.fd, self.encoding)
#         it = iter(fd)
#         next(it)  # skip header
#         return it
# 
#     def _check_for_multiline_input(self, peek_size=100):
#         # peek the first `peek_size` records for multiline CSV
#         reader = self._create_reader()
#         i = 0
#         for line in reader:
#             i += 1
#             if i == peek_size:
#                 break
# 
#         peek_size = min(i, peek_size)
# 
#         if reader.line_num != peek_size:
#             self._ui.fatal('Detected multiline CSV format'
#                            ' -- dont use flag `--fast` '
#                            'to force CSV parsing. '
#                            'Note that this will slow down scoring.')
# 
# class SlowReader(CSVReader):
#     """The slow reader does actual CSV parsing.
#     It supports multiline csv and can be a factor of 50 slower. """
# 
#     def __init__(self, fd, encoding, ui):
#         super(SlowReader, self).__init__(fd, encoding, ui)
#         reader = self._create_reader()
#         self.header = next(reader)
#         self.fieldnames = [c.strip() for c in self.header]
# 
#     def __iter__(self):
#         self.reader = self._create_reader()
#         warned = False
#         for i, row in enumerate(self.reader):
#             if i == 0:
#                 # skip header
#                 continue
# 
#             if len(row) == 0:
#                 if not warned:
#                     self._ui.warning('Detected empty rows in the CSV file. '
#                                      'These rows will be discarded.')
#                     warned = True
#                 continue
# 
#             yield row


# Path: tests/test_reader.py
import csv
import pytest
from mock import Mock
from datarobot_batch_scoring.reader import FastReader, SlowReader

        csv.register_dialect('dataset_dialect', csv.excel)

    @pytest.yield_fixture
    def really_big_fields_enabled(self):
        old_limit = csv.field_size_limit()
        csv.field_size_limit(2 ** 28)
        yield
        csv.field_size_limit(old_limit)

    def test_slow_reader_with_really_wide_field_fails_default(
            self, csv_file_handle_with_wide_field):
        reader = SlowReader(csv_file_handle_with_wide_field,
                            'utf-8',
                            ui=Mock())
        with pytest.raises(csv.Error):
            list(reader)

    @pytest.mark.usefixtures('really_big_fields_enabled')
    def test_slow_reader_can_succeed_if_override_csv_width(
            self, csv_file_handle_with_wide_field):
        reader = SlowReader(csv_file_handle_with_wide_field,
                            'utf-8',
                            ui=Mock())
        data = list(reader)
        assert len(data) == 4

    def test_fast_reader_with_really_wide_field_wont_even_instantiate_default(
            self,
            csv_file_handle_with_wide_field):
        with pytest.raises(csv.Error):

            FastReader(csv_file_handle_with_wide_field, 'utf-8', ui=Mock())