<commit_before>import os
import sys
from unittest import TestCase
from pyexcel_io.deprecated import load_data, get_writer
import pyexcel_io.manager as manager
from pyexcel_io._compact import StringIO, BytesIO, is_string
from pyexcel_io._compact import OrderedDict
from pyexcel_io import save_data, get_data
from pyexcel_io.io import load_data_new, get_writer_new
from nose.tools import raises, eq_
from zipfile import BadZipfile


PY2 = sys.version_info[0] == 2


@raises(NotImplementedError)
def test_not_implemented_1():
    load_data("something")


@raises(NotImplementedError)
def test_not_implemented_2():
    get_writer("something")


@raises(IOError)
def test_no_valid_parameters():
    load_data_new()


@raises(IOError)
def test_no_valid_parameters_2():
    get_writer_new()


@raises(IOError)
def test_none_type_load_data():
    get_data(None)


@raises(Exception)
def test_wrong_parameter_to_get_data():
    get_data(1)


@raises(Exception)
def test_wrong_parameter_to_get_writer():
    get_writer_new(1)


@raises(NotImplementedError)
def test_wrong_parameter_to_get_writer2():
    get_writer_new(1, file_type="csv")


@raises(IOError)
def test_load_ods_data():
    get_data("test.ods")


@raises(IOError)
def test_load_ods_data_from_memory():
    io = BytesIO()
    get_data(io, file_type="ods")


@raises(IOError)
def test_load_unknown_data():
    get_data("test.unknown")


@raises(IOError)
def test_load_unknown_data_from_memory():
    io = BytesIO()
    get_data(io, file_type="unknown")


@raises(BadZipfile)
def test_load_csvz_data_from_memory():
    if not PY2:
        io = StringIO()
        get_data(io, file_type="csvz")
    else:
        raise BadZipfile("pass it")


@raises(IOError)
def test_write_xlsx_data():
    get_data("test.xlsx")


@raises(IOError)
def test_write_unknown_data():
    get_data("test.unknown")


@raises(TypeError)
def test_writer_csvz_data_from_memory():
    if not PY2:
        io = StringIO()
        writer = get_writer_new(io, file_type="csvz")
        writer.write({'adb': [[2, 3]]})
    else:
        raise TypeError("pass it")


@raises(IOError)
def test_writer_xlsm_data_from_memory2():
    io = BytesIO()
    get_writer_new(io, file_type="xlsms")


@raises(IOError)
def test_writer_unknown_data_from_memory2():
    io = BytesIO()
    # mock it
    manager.register_file_type_as_binary_stream('unknown1')
    get_writer_new(io, file_type="unknown1")


def test_get_io():
    io = manager.get_io("hello")
    assert io is None


def test_default_csv_format():
    data = [['1', '2', '3']]
    io = manager.get_io("csv")
    # test default format for saving is 'csv'
    save_data(io, data)
    io.seek(0)
    # test default format for reading is 'csv'
    result = get_data(io)<commit_msg>update test case for python3<commit_after>import os
import sys
from unittest import TestCase
from pyexcel_io.deprecated import load_data, get_writer
import pyexcel_io.manager as manager
from pyexcel_io._compact import StringIO, BytesIO, is_string
from pyexcel_io._compact import OrderedDict
from pyexcel_io import save_data, get_data
from pyexcel_io.io import load_data_new, get_writer_new
from nose.tools import raises, eq_
from zipfile import BadZipfile


PY2 = sys.version_info[0] == 2


@raises(NotImplementedError)
def test_not_implemented_1():
    load_data("something")


@raises(NotImplementedError)
def test_not_implemented_2():
    get_writer("something")


@raises(IOError)
def test_no_valid_parameters():
    load_data_new()


@raises(IOError)
def test_no_valid_parameters_2():
    get_writer_new()


@raises(IOError)
def test_none_type_load_data():
    get_data(None)


@raises(Exception)
def test_wrong_parameter_to_get_data():
    get_data(1)


@raises(Exception)
def test_wrong_parameter_to_get_writer():
    get_writer_new(1)


@raises(NotImplementedError)
def test_wrong_parameter_to_get_writer2():
    get_writer_new(1, file_type="csv")


@raises(IOError)
def test_load_ods_data():
    get_data("test.ods")


@raises(IOError)
def test_load_ods_data_from_memory():
    io = BytesIO()
    get_data(io, file_type="ods")


@raises(IOError)
def test_load_unknown_data():
    get_data("test.unknown")


@raises(IOError)
def test_load_unknown_data_from_memory():
    io = BytesIO()
    get_data(io, file_type="unknown")


@raises(BadZipfile)
def test_load_csvz_data_from_memory():
    if not PY2:
        io = StringIO()
        get_data(io, file_type="csvz")
    else:
        raise BadZipfile("pass it")


@raises(IOError)
def test_write_xlsx_data():
    get_data("test.xlsx")


@raises(IOError)
def test_write_unknown_data():
    get_data("test.unknown")


@raises(NotImplementedError)
def test_writer_csvz_data_from_memory():
    if not PY2:
        io = StringIO()
        writer = get_writer_new(io, file_type="csvz")
        writer.write({'adb': [[2, 3]]})
    else:
        raise NotImplementedError("pass it")


@raises(IOError)
def test_writer_xlsm_data_from_memory2():
    io = BytesIO()
    get_writer_new(io, file_type="xlsms")


@raises(IOError)
def test_writer_unknown_data_from_memory2():
    io = BytesIO()
    # mock it
    manager.register_file_type_as_binary_stream('unknown1')
    get_writer_new(io, file_type="unknown1")


def test_get_io():
    io = manager.get_io("hello")
    assert io is None


def test_default_csv_format():
    data = [['1', '2', '3']]
    io = manager.get_io("csv")
    # test default format for saving is 'csv'
    save_data(io, data)
    io.seek(0)
    # test default format for reading is 'csv'
    result = get_data(io)
{'fraction_non_alphanumeric': 0.11036728785959833, 'fraction_numerical': 0.008141849104396599, 'mean_word_length': 4.9122994652406415, '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': '6464129', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2022, 'n_words': 395}