#!/usr/bin/python # # Block header comment # # import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) #pulling in the regular expression and other definitions definitions_scriptname = sys.argv[1] def_module = imp.load_source('', definitions_scriptname) logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile #spawn an instance of the shell c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile, args=['-p', 'plugins/']) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 5 # ensure that shell prints expected prompt #c.sendline("fcp -s fuck") #assert c.expect_exact("Change 'fuck' to 'fornicate'") != 0, "fcc executed without proper call" c.sendline("fcc fuck") assert c.expect_exact("fcc - Insufficient arguments provided") == 0, "fcc executed with invalid args" ################################## -s mode ################################ c.sendline("fcc -s ass") assert c.expect_exact("Change 'ass' to 'butt'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s bastard") assert c.expect_exact("Change 'bastard' to 'illegitimate child'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s bitch") assert c.expect_exact("Change 'bitch' to 'female dog'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s cock") assert c.expect_exact("Change 'cock' to 'male genitalia'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s cunt") assert c.expect_exact("Change 'cunt' to 'female genitalia'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s dick") assert c.expect_exact("Change 'dick' to 'male genitalia'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s douche") assert c.expect_exact("Change 'douche' to 'female hygine product'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s fag") assert c.expect_exact("Change 'fag' to 'cigarette'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s fuck") assert c.expect_exact("Change 'fuck' to 'fornicate'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s piss") assert c.expect_exact("Change 'piss' to 'urine'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s prick") assert c.expect_exact("Change 'prick' to 'male genitalia'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s pussy") assert c.expect_exact("Change 'pussy' to 'female genitalia'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s shit") assert c.expect_exact("Change 'shit' to 'feces'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s slut") assert c.expect_exact("Change 'slut' to 'loose woman'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s tit") assert c.expect_exact("Change 'tit' to 'female breast'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s wanker") assert c.expect_exact("Change 'wanker' to 'gentleman of self-pleasure'") == 0, "Shell did not execute fcc as expected" c.sendline("fcc -s whore") assert c.expect_exact("Change 'whore' to 'lady of the evening'") == 0, "Shell did not execute fcc as expected" ####################################### -f mode ############################### f = open("__fcc_nantucket.txt", 'w') f.write("There once was a man from Nantucket\n") f.write("Whose dick was so long he could suck it.\n") f.write("And he said with a grin\n") f.write("As he wiped off his chin\n") f.write("\"If my ear were a cunt, I would fuck it.\"\n") #f.write("\n") f.close() c.sendline("fcc -f ATotallyMadeUpFileThatShouldNotExistAnywhere.Nope") assert c.expect_exact("fcc - Cannot open file: ATotallyMadeUpFileThatShouldNotExistAnywhere.Nope") == 0, "fcc opened invalid file" c.sendline("fcc -f __fcc_nantucket.txt") assert c.expect_exact("Censored version of {__fcc_nantucket.txt} saved to {__fcc_nantucket.txt.fcc}") == 0, "fcc failed to execute file operation" os.remove("__fcc_nantucket.txt") os.remove("__fcc_nantucket.txt.fcc") # exit c.sendline("exit"); assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters" shellio.success()