import csv
import sys

import pytest
from mock import Mock

from datarobot_batch_scoring.reader import FastReader, SlowReader


class TestCSVReaderWithWideData(object):

    @pytest.fixture(autouse=True)
    def registered_dialect(self):
        # This was written weird
        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(sys.maxsize)
        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_cannot_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())

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

@@ -585,32 +585,45 @@
 d_fails_default(
+%0A            
 self, csv_file_h
@@ -702,33 +702,89 @@
 _wide_field,
- 'utf-8',
+%0A                            'utf-8',%0A                           
  ui=Mock())%0A
@@ -957,32 +957,45 @@
 rride_csv_width(
+%0A            
 self, csv_file_h
@@ -1074,33 +1074,89 @@
 _wide_field,
- 'utf-8',
+%0A                            'utf-8',%0A                           
  ui=Mock())%0A
@@ -1266,13 +1266,11 @@
 eld_
-canno
+won
 t_ev
@@ -1292,21 +1292,46 @@
 default(
-self,
+%0A            self,%0A           
  csv_fil
@@ -1590,21 +1590,46 @@
 v_width(
-self,
+%0A            self,%0A           
  csv_fil
@@ -1711,33 +1711,89 @@
 _wide_field,
- 'utf-8',
+%0A                            'utf-8',%0A                           
  ui=Mock())%0A

Fix line lengths