Assignment: Args and Input
Test 1 for Java code

Tests included:
Does the program start? If not, perhaps the name is wrong?
Is output written immediately?
Does the program end when stdin ends?
Does the program write the correct output?
'''

import os, sys, time, subprocess
from within_file import WithinFile
from file_compare import FileCompare

withinFile = WithinFile()
compare = FileCompare()

shell_command = 'rm output.txt'
os.system(shell_command)

program_name = 'InputProgram'

#check whether the file is named correctly
try:
    file_stat = os.stat(program_name + '.class')
except FileNotFoundError:
    print(program_name +
          '.class does not exist; the name of your program must match exactly')
    sys.exit()
if file_stat.st_size == 0:
    print('Your program, ' + program_name + '.class, is an empty file')
1. Start the program with server command line args
2. Start the program with client command line args
3. Input data from standard input for the server and the client
4. Redirect standard output to files
5. Compare output files to input files
6. Compare transferred files to original files

14 points total
"""

import os, time
from file_compare import FileCompare
from within_file import WithinFile
points= 0
compare= FileCompare()
withinFile= WithinFile()

shell_command= 'cd server; rm one-liners.txt'
os.system( shell_command )
shell_command= 'cd client; rm Ameca_splendens.jpg'
os.system( shell_command )

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

shell_command= 'cd server; py ../input-writer.py 2 2 server-msg.txt 2>errors.txt | py -u ../messenger_with_files.py -l 6001 >server-recvd.txt &'
os.system( shell_command )

time.sleep( 1 ) 

shell_command= 'cd client; py ../input-writer.py 0 2 client-msg.txt 2>errors.txt | py -u ../messenger_with_files.py -l 6002 -p 6001 >client-recvd.txt'
Automated testing
Assignment: Messenger

1. Start the program with server command line args
2. Start the program with client command line args
3. Input data from standard input for the server and the client
4. Redirect standard output to files
5. Compare output files to input files

10 points total
"""

import os, time
from file_compare import FileCompare
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:
Assignment: Chat with file transfers

1. Start the server program
2. Start client programs
3. Input data from standard input for the clients
4. Redirect standard output to files
5. Compare transferred files to original files

24 points total
"""

import os, time, subprocess
from file_compare import FileCompare
from within_file import WithinFile
points = 0
compare = FileCompare()
withinFile = WithinFile()

shell_command = 'cd client1; rm one-liners.txt'
os.system(shell_command)
shell_command = 'cd client2; rm Ameca_splendens.jpg'
os.system(shell_command)
shell_command = 'cd client3; rm Ameca_splendens.jpg'
os.system(shell_command)

print('Executing multiple messages between clients...')

args = ['py', '-u', 'ChatServer.py', '6001']
server_errors = open('server-errors.txt', 'w')
server = subprocess.Popen(args, stderr=server_errors)
Example #5
0
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] + ' | 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
Example #6
0
Automated testing
Assignment: Messenger
Test 1 for Python code

Tests included:
Does the program start? If not, perhaps the name is wrong?
Is message transferred immediately?
Does the program end when stdin ends?
Does the program write the correct output?
'''

import os, sys, time, subprocess
from within_file import WithinFile
from file_compare import FileCompare
withinFile= WithinFile()
compare= FileCompare()

shell_command= 'rm server-recvd.txt'
os.system( shell_command )
shell_command= 'rm client-recvd.txt'
os.system( shell_command )

program_name = 'messenger.py'

#check whether the file is named correctly
try:
	file_stat= os.stat( program_name )
except FileNotFoundError:
	print( program_name + ' does not exist; the name of your program must match exactly' )
	sys.exit()
if file_stat.st_size == 0:
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