<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import tempfile <EOL> import random <EOL> import time <EOL> import fileinput <EOL> import subprocess <EOL> import imp <EOL> import envoy <EOL> import pytest <EOL> script_path = os . path . dirname ( os . path . dirname ( os . path . realpath ( ( __file__ ) ) ) ) <EOL> fq_pgm = os . path . join ( script_path , '<STR_LIT>' ) <EOL> import test_tools <EOL> def generate_test_file ( delim , record_cnt ) : <EOL> ( fd , fqfn ) = tempfile . mkstemp ( prefix = '<STR_LIT>' ) <EOL> fp = os . fdopen ( fd , "<STR_LIT:w>" ) <EOL> for i in range ( record_cnt ) : <EOL> fields = [ ] <EOL> fields . append ( str ( i ) ) <EOL> fields . append ( '<STR_LIT:A>' ) <EOL> fields . append ( '<STR_LIT:B>' ) <EOL> fields . append ( '<STR_LIT:C>' ) <EOL> fp . write ( delim . join ( fields ) + '<STR_LIT:\n>' ) <EOL> fp . close ( ) <EOL> return fqfn <EOL> class TestCommandLine ( object ) : <EOL> def setup_method ( self , method ) : <EOL> self . in_fqfn = generate_test_file ( delim = '<STR_LIT:|>' , record_cnt = <NUM_LIT:100> ) <EOL> self . empty_fqfn = generate_test_file ( delim = '<STR_LIT:|>' , record_cnt = <NUM_LIT:0> ) <EOL> ( dummy , self . out_fqfn ) = tempfile . mkstemp ( prefix = '<STR_LIT>' ) <EOL> def teardown_method ( self , method ) : <EOL> os . remove ( self . in_fqfn ) <EOL> os . remove ( self . out_fqfn ) <EOL> test_tools . temp_file_remover ( os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) ) <EOL> def test_easy_file ( self ) : <EOL> cmd = '<STR_LIT>' % ( fq_pgm , self . in_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> p_recs = [ ] <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> p_recs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert len ( p_recs ) == <NUM_LIT:4> <EOL> assert p_recs [ <NUM_LIT:0> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert p_recs [ <NUM_LIT:0> ] . strip ( ) . endswith ( '<STR_LIT>' ) <EOL> assert p_recs [ <NUM_LIT:1> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert p_recs [ <NUM_LIT:1> ] . strip ( ) . endswith ( '<STR_LIT:A>' ) <EOL> assert p_recs [ <NUM_LIT:2> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert p_recs [ <NUM_LIT:2> ] . strip ( ) . endswith ( '<STR_LIT:B>' ) <EOL> assert p_recs [ <NUM_LIT:3> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert p_recs [ <NUM_LIT:3> ] . strip ( ) . endswith ( '<STR_LIT:C>' ) <EOL> def test_bad_recnum ( self ) : <EOL> """<STR_LIT>""" <EOL> p_outrecs = [ ] <EOL> cmd = '<STR_LIT>' % ( fq_pgm , self . in_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> p_outrecs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert '<STR_LIT>' in r . std_out <EOL> assert len ( p_outrecs ) == <NUM_LIT:0> <EOL> def test_empty_file ( self ) : <EOL> cmd = "<STR_LIT>" % ( fq_pgm , self . empty_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> out_recs = [ ] <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> out_recs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert len ( out_recs ) == <NUM_LIT:0> <EOL> def test_full_multiple_files ( self ) : <EOL> cmd = "<STR_LIT>" % ( fq_pgm , self . in_fqfn , self . in_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> out_recs = [ ] <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> out_recs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert len ( out_recs ) == <NUM_LIT:4> <EOL> assert out_recs [ <NUM_LIT:0> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert out_recs [ <NUM_LIT:0> ] . strip ( ) . endswith ( '<STR_LIT>' ) <EOL> def test_full_multiple_empty_files ( self ) : <EOL> cmd = "<STR_LIT>" % ( fq_pgm , self . empty_fqfn , self . empty_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> out_recs = [ ] <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> out_recs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert len ( out_recs ) == <NUM_LIT:0> <EOL> def dtest_full_multiple_empty_and_full_files ( self ) : <EOL> cmd = "<STR_LIT>" % ( fq_pgm , self . empty_fqfn , self . in_fqfn , self . out_fqfn ) <EOL> r = envoy . run ( cmd ) <EOL> out_recs = [ ] <EOL> for rec in fileinput . input ( self . out_fqfn ) : <EOL> out_recs . append ( rec ) <EOL> fileinput . close ( ) <EOL> assert len ( out_recs ) == <NUM_LIT:4> <EOL> assert out_recs [ <NUM_LIT:0> ] . strip ( ) . startswith ( '<STR_LIT>' ) <EOL> assert out_recs [ <NUM_LIT:0> ] . strip ( ) . endswith ( '<STR_LIT>' ) </s>
