time.sleep(3)
found = withinFile.searchText('input1.txt', 'output.txt')
if not found:
    print('output must be written immediately; your program must be revised')
    sys.exit()

# wait until the input pipe closes; then, check whether the process terminated
try:
    input_program.wait(2)
    if input_program.returncode != 0:
        print(program_name + ' returned: ' + str(input_program.returncode) +
              '; your program must be revised')
        sys.exit()
except subprocess.TimeoutExpired:
    print(
        program_name +
        ' has not exited within the expected timeframe; your program must be revised'
    )
    input_program.kill()  # terminate process
    sys.exit()

# check output
differ = compare.textFiles('output.txt', 'ref1.txt', True)
if differ:
    print(
        'Output of your program does not match expected output; your program must be revised. Pay close attention to detail, including the case (upper/lower) of text.'
    )
    sys.exit()

print('test1 terminated properly')
points= 0
compare= FileCompare()

print( 'Executing server and client with a single message...' )

shell_command= 'py input-writer.py 2 2 server-msg.txt | java Messenger -l 6001 >server-recvd.txt &'
os.system( shell_command )

time.sleep( 1 )

shell_command= 'py input-writer.py 0 2 client-msg.txt | java Messenger 6001 >client-recvd.txt'
os.system( shell_command )

print( 'execution completed; grading...' )

differ= compare.textFiles( 'server-msg.txt', 'client-recvd.txt', True )
if differ is False:
	points+= 1
	
differ= compare.textFiles( 'client-msg.txt', 'server-recvd.txt', True )
if differ is False: 
	points+= 1

print( 'Executing server and client with multiple messages...' )

shell_command= 'py input-writer.py 2 2 server-msgs.txt | java Messenger -l 6001 >server-recvd.txt &'
os.system( shell_command )

time.sleep( 1 ) 

shell_command= 'py input-writer.py 0 2 client-msgs.txt | java Messenger 6001 >client-recvd.txt'
Ejemplo n.º 3
0
	client_messenger.kill()
	sys.exit()

# wait until the client input pipe closes; then, check whether the client process terminated
try:
	client_messenger.wait( 2 ) #CHANGED FROM 0 TO 2
	if client_messenger.returncode != 0:
		print( 'client ' + program_name + ' returned: ' + str(client_messenger.returncode) + '; your program must be revised' )
		sys.exit()
except subprocess.TimeoutExpired:
	print( 'client sending messages, ' + program_name + ', has not exited within the expected timeframe; your program must be revised' )
	client_messenger.kill()
	sys.exit()

# check output
differ= compare.textFiles( 'client-msgs.txt', 'server-recvd.txt', True )
if differ:
	print( 'Server did not receive messages sent by client as expected; your program must be revised. Pay close attention to detail.' )
	sys.exit()

# create the input for the pipe to the server
args= ['py','-u','input-writer.py','1', '1', 'server-msgs.txt']
server_input_writer= subprocess.Popen( args, stdout=subprocess.PIPE)

# start the program as a server
args= ['py','-u', program_name, '-l', '6001' ]
server_output_text= open( 'server-recvd.txt', 'w' )
server_messenger= subprocess.Popen( args, stdin= server_input_writer.stdout, stdout=server_output_text)

# create blank input for the pipe to the client
args= ['py','-u','input-writer.py','5', '0', 'blank.txt']
Ejemplo n.º 4
0
from file_compare import FileCompare

option_args = ['-h -t giraffe', '-t lion -h -o elephant', '-o tiger']
input_files = ['input1.txt', 'input2.txt', 'input3.txt']
ref_files= ['ref1.txt', 'ref2.txt', 'ref3.txt', 'ref4.txt', 'ref5.txt', \
 'ref6.txt', 'ref7.txt', 'ref8.txt', 'ref9.txt' ]

points = 0
size = len(option_args)
ref_index = 0
for input_index in range(size):
    shell_command = 'py input-writer.py 0 0 ' + input_files[
        input_index] + ' | java InputProgram >output.txt'
    os.system(shell_command)
    compare = FileCompare()
    differ = compare.textFiles('output.txt', ref_files[ref_index], True)
    if differ is False:
        points += 1
    ref_index += 1

for input_index in range(size):
    shell_command = 'py input-writer.py 0 0 blank.txt | java InputProgram ' + option_args[
        input_index] + ' >output.txt'
    os.system(shell_command)
    compare = FileCompare()
    differ = compare.textFiles('output.txt', ref_files[ref_index], True)
    if differ is False:
        points += 1
    ref_index += 1

for input_index in range(size):
import os
from file_compare import FileCompare

option_args= ['-h -t giraffe', '-t lion -h -o elephant', '-o tiger' ]
input_files= ['input1.txt', 'input2.txt', 'input3.txt' ]
ref_files= ['ref1.txt', 'ref2.txt', 'ref3.txt', 'ref4.txt', 'ref5.txt', \
 'ref6.txt', 'ref7.txt', 'ref8.txt', 'ref9.txt' ]

points= 0
size= len(option_args)
ref_index= 0
for input_index in range(size):
	shell_command= 'py input-writer.py 0 0 ' + input_files[input_index] + ' | py input_program.py >output.txt'
	os.system( shell_command )
	compare= FileCompare()
	differ= compare.textFiles( 'output.txt', ref_files[ref_index], True )
	if differ is False:
		points+= 1
	ref_index+= 1
	
for input_index in range(size):
	shell_command= 'py input-writer.py 0 0 blank.txt | py input_program.py ' + option_args[input_index] + ' >output.txt'
	os.system( shell_command )
	compare= FileCompare()
	differ= compare.textFiles( 'output.txt', ref_files[ref_index], True )
	if differ is False:
		points+= 1
	ref_index+= 1


for input_index in range(size):