<s> import datetime <EOL> from unittest import TestCase <EOL> import pyexcel as pe <EOL> from base import clean_up_files <EOL> from nose . tools import raises <EOL> class TestToFormatFunction : <EOL> def test_none_2_str ( self ) : <EOL> value = None <EOL> n_value = pe . formatters . to_format ( str , value ) <EOL> assert n_value == "<STR_LIT>" <EOL> def test_string_2_float ( self ) : <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> float , value ) <EOL> assert n_value == <NUM_LIT> <EOL> value = "<STR_LIT:abc>" <EOL> n_value = pe . formatters . to_format ( <EOL> float , value ) <EOL> assert n_value == value <EOL> def test_string_to_string ( self ) : <EOL> value = "<STR_LIT:string>" <EOL> n_value = pe . formatters . to_format ( <EOL> str , value ) <EOL> assert n_value == value <EOL> def test_string_2_int_format ( self ) : <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> int , value ) <EOL> assert n_value == <NUM_LIT:11> <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> int , <EOL> value ) <EOL> assert n_value == <NUM_LIT:11> <EOL> value = "<STR_LIT:abc>" <EOL> n_value = pe . formatters . to_format ( <EOL> int , value ) <EOL> assert n_value == value <EOL> def test_float_2_string_format ( self ) : <EOL> value = <NUM_LIT:1.0> <EOL> n_value = pe . formatters . to_format ( <EOL> str , value ) <EOL> assert n_value == "<STR_LIT:1.0>" <EOL> def test_float_2_int_format ( self ) : <EOL> value = <NUM_LIT> <EOL> n_value = pe . formatters . to_format ( <EOL> int , value ) <EOL> assert type ( n_value ) == int <EOL> assert n_value == <NUM_LIT:1> <EOL> def test_float_2_date_format ( self ) : <EOL> value = <NUM_LIT> <EOL> n_value = pe . formatters . to_format ( <EOL> datetime . datetime , value ) <EOL> assert type ( n_value ) == float <EOL> assert n_value == value <EOL> def test_int_2_string_format ( self ) : <EOL> value = <NUM_LIT:11> <EOL> n_value = pe . formatters . to_format ( <EOL> str , value ) <EOL> assert n_value == "<STR_LIT>" <EOL> def test_int_2_float_format ( self ) : <EOL> value = <NUM_LIT:11> <EOL> n_value = pe . formatters . to_format ( <EOL> float , <EOL> value ) <EOL> assert type ( n_value ) == float <EOL> assert n_value == value <EOL> def test_int_2_date ( self ) : <EOL> value = <NUM_LIT:11> <EOL> n_value = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> value ) <EOL> assert type ( n_value ) == int <EOL> assert n_value == value <EOL> def test_date_conversion ( self ) : <EOL> d = datetime . datetime . now ( ) <EOL> new_d = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> d <EOL> ) <EOL> assert d == new_d <EOL> new_d = pe . formatters . to_format ( <EOL> str , <EOL> d <EOL> ) <EOL> assert d . strftime ( "<STR_LIT>" ) == new_d <EOL> new_d = pe . formatters . to_format ( <EOL> bool , <EOL> d <EOL> ) <EOL> assert d == new_d <EOL> t = datetime . time ( <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> ) <EOL> new_t = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> t <EOL> ) <EOL> assert t == new_t <EOL> new_t = pe . formatters . to_format ( <EOL> str , <EOL> t <EOL> ) <EOL> assert t . strftime ( "<STR_LIT>" ) == new_t <EOL> new_t = pe . formatters . to_format ( <EOL> bool , <EOL> t <EOL> ) <EOL> assert t == new_t <EOL> bad = "<STR_LIT>" <EOL> new_d = pe . formatters . to_format ( <EOL> str , <EOL> bad <EOL> ) <EOL> assert bad == new_d <EOL> def test_boolean_2_date ( self ) : <EOL> value = True <EOL> n_value = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> value ) <EOL> assert type ( n_value ) == bool <EOL> assert n_value == value <EOL> def test_boolean_2_float ( self ) : <EOL> value = True <EOL> n_value = pe . formatters . to_format ( <EOL> float , <EOL> value ) <EOL> assert n_value == <NUM_LIT:1> <EOL> def test_boolean_2_string ( self ) : <EOL> value = True <EOL> n_value = pe . formatters . to_format ( <EOL> str , <EOL> value ) <EOL> assert n_value == "<STR_LIT:true>" <EOL> value = False <EOL> n_value = pe . formatters . to_format ( <EOL> str , <EOL> value ) <EOL> assert n_value == "<STR_LIT:false>" <EOL> def test_empty_to_supported_types ( self ) : <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> float , <EOL> value ) <EOL> assert type ( n_value ) == float <EOL> assert n_value == <NUM_LIT:0> <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> int , <EOL> value ) <EOL> assert type ( n_value ) == int <EOL> assert n_value == <NUM_LIT:0> <EOL> value = "<STR_LIT>" <EOL> n_value = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> value ) <EOL> assert n_value == "<STR_LIT>" <EOL> def test_date_format ( self ) : <EOL> d = "<STR_LIT>" <EOL> n_d = pe . formatters . to_format ( <EOL> datetime . datetime , <EOL> d ) <EOL> assert d == n_d <EOL> class TestColumnFormatter ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = { <EOL> "<STR_LIT:1>" : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> "<STR_LIT:2>" : [ "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT:3>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT:4>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT:5>" : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , <EOL> "<STR_LIT>" : [ "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> } <EOL> self . io = pe . save_as ( dest_file_type = "<STR_LIT>" , adict = self . data ) <EOL> self . test_tuple = ( "<STR_LIT>" , self . io . getvalue ( ) ) <EOL> def test_general_usage ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> str ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ "<STR_LIT:2>" ] ) <EOL> def test_column_format_general_usage ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . column . format ( <EOL> <NUM_LIT:0> , <EOL> str ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ "<STR_LIT:2>" ] ) <EOL> def test_column_format_general_usage2 ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . column . format ( <EOL> <NUM_LIT:0> , <EOL> str , <EOL> on_demand = True ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:2>' ] ) <EOL> def test_column_format_specs ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . column . format ( format_specs = [ [ <NUM_LIT:0> , str ] , [ [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , float ] ] ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:2>' ] ) <EOL> c1 = r . column_at ( <NUM_LIT:3> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:3>' ] ) <EOL> def test_column_format_specs_on_demand ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . column . format ( format_specs = [ [ <NUM_LIT:0> , lambda v : int ( v ) + <NUM_LIT:1> ] , [ [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , float ] ] ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:5>' ] ) <EOL> c1 = r . column_at ( <NUM_LIT:3> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:3>' ] ) <EOL> def test_one_formatter_for_two_columns ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> [ <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> str ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:2>' ] ) <EOL> c1 = r . column_at ( <NUM_LIT:5> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT>' ] ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_invalid_input ( self ) : <EOL> pe . formatters . ColumnFormatter ( "<STR_LIT>" , str ) <EOL> @ raises ( IndexError ) <EOL> def test_invalid_input2 ( self ) : <EOL> """<STR_LIT>""" <EOL> pe . formatters . ColumnFormatter ( [ ] , str ) <EOL> @ raises ( IndexError ) <EOL> def test_float_in_list ( self ) : <EOL> pe . formatters . ColumnFormatter ( [ <NUM_LIT:1> , <NUM_LIT> ] , str ) <EOL> def test_two_formatters ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> str ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:2>' ] ) <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> int ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:1>' ] ) <EOL> def test_custom_func ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> f = lambda x : int ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> f ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:5>' ] ) <EOL> def test_custom_func_with_a_general_converter ( self ) : <EOL> r = pe . Reader ( self . test_tuple ) <EOL> f = lambda x : int ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> f ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT:5>' ] ) <EOL> r . add_formatter ( pe . formatters . ColumnFormatter ( <EOL> <NUM_LIT:0> , <EOL> str ) ) <EOL> c1 = r . column_at ( <NUM_LIT:0> ) [ <NUM_LIT:1> : ] <EOL> self . assertEqual ( c1 , self . data [ '<STR_LIT>' ] ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_named_formatter ( self ) : <EOL> """<STR_LIT>""" <EOL> nrf = pe . formatters . NamedColumnFormatter ( "<STR_LIT:abc>" , str ) <EOL> nrf . update_index ( "<STR_LIT:abc>" ) <EOL> class TestRowFormatter ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = { <EOL> "<STR_LIT:1>" : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> "<STR_LIT:2>" : [ "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT:3>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT:4>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT:5>" : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , <EOL> "<STR_LIT>" : [ "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> } <EOL> self . testfile = "<STR_LIT>" <EOL> pe . save_as ( dest_file_name = self . testfile , adict = self . data ) <EOL> def test_general_usage ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT:1>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_general_usage2 ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . testfile ) <EOL> r . row . format ( <EOL> <NUM_LIT:1> , <EOL> str ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT:1>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_general_usage3 ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . testfile ) <EOL> r . row . format ( <EOL> <NUM_LIT:1> , <EOL> str , on_demand = True ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT:1>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_one_formatter_for_two_rows ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ "<STR_LIT:2>" , "<STR_LIT:2>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:3>" , "<STR_LIT:3>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ '<STR_LIT:1>' , "<STR_LIT:1>" , '<STR_LIT>' , "<STR_LIT>" , '<STR_LIT:2>' , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_unacceptable_index ( self ) : <EOL> pe . formatters . RowFormatter ( <EOL> "<STR_LIT:hello>" , str ) <EOL> @ raises ( IndexError ) <EOL> def test_empty_list_as_input ( self ) : <EOL> pe . formatters . RowFormatter ( <EOL> [ ] , str <EOL> ) <EOL> @ raises ( IndexError ) <EOL> def test_float_in_row_formatter ( self ) : <EOL> pe . formatters . RowFormatter ( [ <NUM_LIT:1> , <NUM_LIT> ] , str ) <EOL> def test_remove_formatter ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> ft = pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> str ) <EOL> r . add_formatter ( ft ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT:1>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:2>" , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . remove_formatter ( ft ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT:1> , "<STR_LIT:1>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT:2> , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_two_formatters ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT:1> , "<STR_LIT:1>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT:2> , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> int ) ) <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:2>' ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_two_formatters_with_row_fomat ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT:1> , "<STR_LIT:1>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT:2> , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . row . format ( format_specs = [ [ <NUM_LIT:1> , int ] , [ <NUM_LIT:1> , str ] ] ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:2>' ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_two_formatters_with_row_fomat_custom_func ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT:1> , "<STR_LIT:1>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT:2> , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . row . format ( format_specs = [ [ <NUM_LIT:1> , lambda v : float ( v ) + <NUM_LIT:1> ] , [ <NUM_LIT:1> , str ] ] ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> f ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func_with_a_general_converter ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> f ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . add_formatter ( pe . formatters . RowFormatter ( <EOL> <NUM_LIT:1> , <EOL> str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_remove_formatter2 ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> ft = pe . formatters . RowFormatter ( <NUM_LIT:1> , f ) <EOL> r . add_formatter ( ft ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> r . remove_formatter ( ft ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT:1> , "<STR_LIT:1>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT:2> , "<STR_LIT:2>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_named_formatter ( self ) : <EOL> """<STR_LIT>""" <EOL> nrf = pe . formatters . NamedRowFormatter ( "<STR_LIT:abc>" , str ) <EOL> nrf . update_index ( "<STR_LIT:abc>" ) <EOL> def tearDown ( self ) : <EOL> clean_up_files ( [ self . testfile ] ) <EOL> class TestSheetFormatter ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = { <EOL> "<STR_LIT:1>" : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> "<STR_LIT:3>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT:5>" : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , <EOL> "<STR_LIT>" : [ <NUM_LIT:1> , '<STR_LIT>' , ] <EOL> } <EOL> self . testfile = "<STR_LIT>" <EOL> pe . save_as ( dest_file_name = self . testfile , adict = self . data ) <EOL> def test_general_usage ( self ) : <EOL> r = pe . SeriesReader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( <EOL> str ) ) <EOL> data = [ <EOL> [ "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] <EOL> c1 = r . column_at ( <NUM_LIT:0> ) <EOL> self . assertEqual ( c1 , data [ <NUM_LIT:0> ] ) <EOL> c1 = r . column_at ( <NUM_LIT:1> ) <EOL> self . assertEqual ( c1 , data [ <NUM_LIT:1> ] ) <EOL> def test_two_formatters ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( int ) ) <EOL> c1 = r . row_at ( <NUM_LIT:0> ) <EOL> c2 = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( float ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1.0> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func2 ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . format ( float ) <EOL> r . map ( f ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1.0> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func_with_a_general_converter ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( float ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:1.0>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> @ raises ( TypeError ) <EOL> def test_custom_func_with_a_general_converter2 ( self ) : <EOL> """<STR_LIT>""" <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> r . row_at ( <NUM_LIT:2> ) <EOL> def test_clear_formatters ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> r . clear_formatters ( ) <EOL> r . name_columns_by_row ( <NUM_LIT:0> ) <EOL> mydata = r . to_dict ( ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:1>' ] , self . data [ '<STR_LIT:1>' ] ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:3>' ] , self . data [ '<STR_LIT:3>' ] ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:5>' ] , self . data [ '<STR_LIT:5>' ] ) <EOL> def tearDown ( self ) : <EOL> clean_up_files ( [ self . testfile ] ) <EOL> class TestSheetFormatterInXLS ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data = { <EOL> "<STR_LIT:1>" : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> "<STR_LIT:3>" : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> "<STR_LIT:5>" : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , <EOL> } <EOL> self . testfile = "<STR_LIT>" <EOL> pe . save_as ( dest_file_name = self . testfile , adict = self . data ) <EOL> def test_general_usage ( self ) : <EOL> r = pe . SeriesReader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> self . data = [ <EOL> [ "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] <EOL> c1 = r . column_at ( <NUM_LIT:0> ) <EOL> self . assertEqual ( c1 , self . data [ <NUM_LIT:0> ] ) <EOL> c1 = r . column_at ( <NUM_LIT:1> ) <EOL> self . assertEqual ( c1 , self . data [ <NUM_LIT:1> ] ) <EOL> def test_two_formatters ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( int ) ) <EOL> c1 = r . row_at ( <NUM_LIT:0> ) <EOL> c2 = [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:4> ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_custom_func_with_a_general_converter ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> c1 = r . row_at ( <NUM_LIT:1> ) <EOL> c2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> c1 = r . row_at ( <NUM_LIT:2> ) <EOL> c2 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( c1 , c2 ) <EOL> def test_clear_formatters ( self ) : <EOL> r = pe . Reader ( self . testfile ) <EOL> f = lambda x : float ( x ) + <NUM_LIT:1> <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( f ) ) <EOL> r . add_formatter ( pe . formatters . SheetFormatter ( str ) ) <EOL> r . clear_formatters ( ) <EOL> r . name_columns_by_row ( <NUM_LIT:0> ) <EOL> mydata = r . to_dict ( ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:1>' ] , self . data [ '<STR_LIT:1>' ] ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:3>' ] , self . data [ '<STR_LIT:3>' ] ) <EOL> self . assertEqual ( mydata [ '<STR_LIT:5>' ] , self . data [ '<STR_LIT:5>' ] ) <EOL> def tearDown ( self ) : <EOL> clean_up_files ( [ self . testfile ] ) </s>
