<commit_before>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<commit_msg>Fix line lengths<commit_after>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_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())

    @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
{'fraction_non_alphanumeric': 0.07882052736036292, 'fraction_numerical': 0.003402324922030054, 'mean_word_length': 3.1554770318021204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5133534', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1131, 'n_words': 161}