<s> """<STR_LIT>""" <EOL> import json <EOL> import logging <EOL> from src import basetest <EOL> from src . clients import bigquery <EOL> from src . csvmatchreplace import transform <EOL> class TransformTest ( basetest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def testTransformRow ( self ) : <EOL> row1 = [ '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> config = { '<STR_LIT>' : [ { '<STR_LIT:type>' : bigquery . ColumnTypes . STRING , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:replace>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:replace>' : '<STR_LIT>' } ] } , <EOL> { '<STR_LIT:type>' : bigquery . ColumnTypes . STRING , <EOL> '<STR_LIT>' : False } , <EOL> { '<STR_LIT:type>' : bigquery . ColumnTypes . STRING , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT:replace>' : '<STR_LIT:k>' } ] } ] } <EOL> ( transformed_row , bad_columns ) = transform . TransformRow ( row1 , config ) <EOL> self . assertEqual ( len ( bad_columns ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( transformed_row ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( transformed_row , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> config [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] = True <EOL> ( transformed_row2 , bad_columns2 ) = transform . TransformRow ( row1 , config ) <EOL> self . assertEqual ( len ( bad_columns2 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( transformed_row2 ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( transformed_row2 , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def NOPEtestTransformRowWithBadData ( self ) : <EOL> row1 = [ '<STR_LIT:true>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> t = { } <EOL> t . column_types = [ bigquery . ColumnTypes . STRING , <EOL> bigquery . ColumnTypes . INTEGER , <EOL> bigquery . ColumnTypes . INTEGER ] <EOL> t . transformations = json . dumps ( [ <EOL> [ { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:replace>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:replace>' : '<STR_LIT>' } ] , <EOL> [ ] , <EOL> [ { '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT:replace>' : '<STR_LIT:k>' } ] ] ) <EOL> t . column_wanted = [ True , True , True ] <EOL> ( bad_columns , _ ) = t . TransformRow ( row1 ) <EOL> self . assertEqual ( len ( bad_columns ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( bad_columns [ <NUM_LIT:0> ] . index , <NUM_LIT:1> ) <EOL> self . assertEqual ( bad_columns [ <NUM_LIT:1> ] . index , <NUM_LIT:2> ) <EOL> class TestNormalizeCellByType ( basetest . TestCase ) : <EOL> def testNormalizeCellByType ( self ) : <EOL> types = bigquery . ColumnTypes <EOL> self . assertEqual ( '<STR_LIT>' , transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:0> , types . STRING ) ) <EOL> self . assertEqual ( '<STR_LIT>' , transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:1> , types . INTEGER ) ) <EOL> self . assertEqual ( '<STR_LIT:1>' , transform . NormalizeCellByType ( '<STR_LIT:1>' , <NUM_LIT:1> , types . INTEGER ) ) <EOL> self . assertRaises ( transform . CellError , <EOL> transform . NormalizeCellByType , '<STR_LIT>' , <NUM_LIT:1> , types . INTEGER ) <EOL> self . assertEqual ( '<STR_LIT>' , transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:2> , types . FLOAT ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:2> , types . FLOAT ) ) <EOL> self . assertRaises ( transform . CellError , <EOL> transform . NormalizeCellByType , '<STR_LIT>' , <NUM_LIT:2> , types . FLOAT ) <EOL> self . assertEqual ( '<STR_LIT>' , transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:3> , types . BOOLEAN ) ) <EOL> self . assertEqual ( '<STR_LIT:True>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT:true>' , <NUM_LIT:3> , types . BOOLEAN ) ) <EOL> self . assertEqual ( '<STR_LIT:True>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:3> , types . BOOLEAN ) ) <EOL> self . assertEqual ( '<STR_LIT:True>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT:1>' , <NUM_LIT:3> , types . BOOLEAN ) ) <EOL> self . assertEqual ( '<STR_LIT:False>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT:False>' , <NUM_LIT:3> , types . BOOLEAN ) ) <EOL> self . assertRaises ( transform . CellError , <EOL> transform . NormalizeCellByType , '<STR_LIT>' , <NUM_LIT:3> , types . BOOLEAN ) <EOL> self . assertEqual ( '<STR_LIT>' , transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:4> , types . TIMESTAMP ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> transform . NormalizeCellByType ( '<STR_LIT>' , <NUM_LIT:4> , <EOL> types . TIMESTAMP ) ) <EOL> self . assertRaises ( transform . CellError , <EOL> transform . NormalizeCellByType , '<STR_LIT>' , <NUM_LIT:4> , types . TIMESTAMP ) <EOL> def testCellsAsString ( self ) : <EOL> tests = ( ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT:a>' , [ '<STR_LIT:a>' ] ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:c>' ] ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:c>' ] ) , <EOL> ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:c>' ] ) , <EOL> ) <EOL> for expected , row in tests : <EOL> self . assertEquals ( expected , transform . CellsToCsvString ( row ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> basetest . main ( ) </s>
