<s> import os <EOL> import unittest <EOL> from types import NoneType <EOL> from flimp . parser import parse_json , parse_csv , parse_yaml <EOL> PATH_TO_FILES = os . path . join ( os . getcwd ( ) , os . path . dirname ( __file__ ) ) <EOL> GOOD_JSON = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> BAD_JSON = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> EMPTY_JSON = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> GOOD_CSV = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> BAD_CSV = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> HEADER_ONLY_CSV = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> EMPTY_CSV = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> BLANK_CSV = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> GOOD_YAML = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> BAD_YAML = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> EMPTY_YAML = os . path . join ( PATH_TO_FILES , '<STR_LIT>' ) <EOL> class TestParseJson ( unittest . TestCase ) : <EOL> def test_parse ( self ) : <EOL> good = open ( GOOD_JSON , '<STR_LIT:r>' ) <EOL> bad = open ( BAD_JSON , '<STR_LIT:r>' ) <EOL> empty = open ( EMPTY_JSON , '<STR_LIT:r>' ) <EOL> self . assertTrue ( isinstance ( parse_json . parse ( good ) , list ) ) <EOL> self . assertRaises ( TypeError , parse_json . parse , bad ) <EOL> self . assertRaises ( ValueError , parse_json . parse , empty ) <EOL> class TestParseCsv ( unittest . TestCase ) : <EOL> def test_parse ( self ) : <EOL> good = open ( GOOD_CSV , '<STR_LIT:r>' ) <EOL> bad = open ( BAD_CSV , '<STR_LIT:r>' ) <EOL> header = open ( HEADER_ONLY_CSV , '<STR_LIT:r>' ) <EOL> empty = open ( EMPTY_CSV , '<STR_LIT:r>' ) <EOL> blank = open ( BLANK_CSV , '<STR_LIT:r>' ) <EOL> result = parse_csv . parse ( good ) <EOL> self . assertTrue ( isinstance ( result , list ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( result ) ) <EOL> self . assertTrue ( isinstance ( result [ <NUM_LIT:0> ] , dict ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( result [ <NUM_LIT:0> ] ) ) <EOL> self . assertRaises ( ValueError , parse_csv . parse , header ) <EOL> self . assertRaises ( Exception , parse_csv . parse , empty ) <EOL> result = parse_csv . parse ( bad ) <EOL> for item in result [ : - <NUM_LIT:1> ] : <EOL> self . assertEqual ( <NUM_LIT:3> , len ( item ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result [ <NUM_LIT:3> ] ) ) <EOL> result = parse_csv . parse ( blank ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( result ) ) <EOL> for item in result : <EOL> self . assertEqual ( <NUM_LIT:3> , len ( item ) ) <EOL> def test_clean_header ( self ) : <EOL> header = "<STR_LIT>" <EOL> self . assertEqual ( "<STR_LIT>" , parse_csv . clean_header ( header ) ) <EOL> def test_clean_row_item ( self ) : <EOL> test_items = { <EOL> "<STR_LIT>" : str , <EOL> u"<STR_LIT>" : unicode , <EOL> "<STR_LIT:1>" : int , <EOL> "<STR_LIT>" : int , <EOL> "<STR_LIT>" : float , <EOL> "<STR_LIT>" : float , <EOL> "<STR_LIT:True>" : bool , <EOL> "<STR_LIT:False>" : bool , <EOL> "<STR_LIT:true>" : bool , <EOL> "<STR_LIT:false>" : bool , <EOL> "<STR_LIT>" : NoneType , <EOL> } <EOL> for key , value in test_items . iteritems ( ) : <EOL> self . assertTrue ( isinstance ( parse_csv . clean_row_item ( key ) , value ) ) <EOL> class TestParseYaml ( unittest . TestCase ) : <EOL> def test_parse ( self ) : <EOL> good = open ( GOOD_YAML , '<STR_LIT:r>' ) <EOL> bad = open ( BAD_YAML , '<STR_LIT:r>' ) <EOL> empty = open ( EMPTY_YAML , '<STR_LIT:r>' ) <EOL> self . assertTrue ( isinstance ( parse_yaml . parse ( good ) , list ) ) <EOL> self . assertRaises ( TypeError , parse_yaml . parse , bad ) <EOL> self . assertRaises ( ValueError , parse_yaml . parse , empty ) </s>
