def test_golden_master(self): original_out = sys.stdout for i in range(0, 10): out_content = StringIO() sys.stdout = out_content run(i) sys.stdout = original_out result = GoldenMaster().get_result(i) self.assertEqual(str(out_content.getvalue()), result)
def characterization_test(self, filename, rnd_seq): oldstdout = sys.stdout sys.stdout = StringIO.StringIO() rnd = trivia.Random(rnd_seq) trivia.run(rnd) actual = sys.stdout.getvalue() sys.stdout = oldstdout expected = self.get_expected_characterization_value(filename) self.assertEqual(expected, actual)
def generate_expected_result(self, i): result = None sys.stdout = self.out_content trivia.run(i) file_name = './resources/output%d.txt' % i with open(file_name, 'w') as master: result = self.out_content.getvalue() master.write(result) sys.stdout = self.original_out self.out_content.close() return result
def run(): #GPIO.setmode(GPIO.BOARD) # pin 25= Juego trivia # pin 24 = juego Top padPin = 25 GPIO.setup(padPin, GPIO.IN) print "welcome to controller" padPin2 = 24 GPIO.setup(padPin2, GPIO.IN) ##redes="Si deseas escuchar tu música escanea el código QR" opciones="Tenemos dos juegos para ti, selecciona el boton de interrogación para Trivias, y el martillo para wack a mole" ocupada=0 ##Parte para la música ##tts = gTTS(text=redes, lang='es') ##tts.save("redes.mp3") ##os.system('mplayer '+ "redes.mp3") ##Seleccioón del juego tts = gTTS(text=opciones, lang='es') tts.save("opciones.mp3") os.system('mplayer '+ "opciones.mp3") while True: padPressed = GPIO.input(padPin) padPressed2 = GPIO.input(padPin2) if padPressed: print "Trivia" trivia.run() #os.system ("/usr/bin/python /home/pi/Desktop/program/trivia.py") #os.system("clear") GPIO.cleanup() if padPressed2: print "Top" top.run() #os.system ("/usr/bin/python /home/pi/Desktop/program/top.py") #os.system("clear") GPIO.cleanup()
def main(): cmds = [ "rm -rf %s" % BUILD_PATH, "cmake -H. -B%s" % BUILD_PATH, "cmake --build %s" % BUILD_PATH, ] if sys.platform == "win32": cmds[1] = "cmake -H. -Bbuild -G \"Visual Studio 12 2013\"" index = None if len(sys.argv) == 2: index = int(sys.argv[1]) if index != None and index >= 0 and index < len(cmds): cmd = cmds[index] trivia.run(cmd) return for cmd in cmds: succ = run_and_check(cmd) if not succ: return
def main(): print_with_frame("test") path = "./tmp" print trivia.abspath(path) print "trivia.exists:" + str(trivia.exists(path)) print "trivia.isdir:" + str(trivia.isdir(path)) print "trivia.isfile:" + str(trivia.isfile(path)) print_with_frame("trivia.mkdir:" + path) trivia.mkdir(path) print "trivia.exists:" + str(trivia.exists(path)) print "trivia.isdir:" + str(trivia.isdir(path)) print "trivia.isfile:" + str(trivia.isfile(path)) print_with_frame("trivia.mkdir and trivia.remove:" + path) trivia.mkdir(path) trivia.remove(path) print "trivia.exists:" + str(trivia.exists(path)) print "trivia.isdir:" + str(trivia.isdir(path)) print "trivia.isfile:" + str(trivia.isfile(path)) print_with_frame("create file:" + path) trivia.run("touch " + path) print "trivia.exists:" + str(trivia.exists(path)) print "trivia.isdir:" + str(trivia.isdir(path)) print "trivia.isfile:" + str(trivia.isfile(path)) print_with_frame("trivia.remove:" + path) trivia.remove(path) print "trivia.exists:" + str(trivia.exists(path)) print "trivia.isdir:" + str(trivia.isdir(path)) print "trivia.isfile:" + str(trivia.isfile(path)) print_with_frame("test files_filter") path = "/Users/xxx/Documents/tmp" def foo(path): return path[-4:] == ".jar" # filepaths = trivia.files_filter(path, foo) filepaths = trivia.files_filter(path, lambda path: path[-4:] == ".jar") print filepaths print_with_frame("test trivia.popen") r, out, err = trivia.popen("ls -al") print "r:\n" + str(r) print "out:\n" + out print "err:\n" + err r, out, err = trivia.popen("ls -z") print "r:\n" + str(r) print "out:\n" + out print "err:\n" + err print_with_frame("test trivia.md5") content = "" result = trivia.md5(content) print "string:%s, md5:%s" % (content, result) content = "test" result = trivia.md5(content) print "string:%s, md5:%s" % (content, result) print_with_frame("test trivia.dirname") print trivia.dirname("./a/b/c/d") print_with_frame("test trivia.mkdirs") trivia.mkdirs("./a/b/c/d") if trivia.exists("./a/b/c/d") and trivia.isdir("./a/b/c/d"): print "trivia.mkdirs ok" trivia.remove("./a/") print_with_frame("test trivia.copy/move") trivia.run("touch c") trivia.copy("c", "trivia_copy/a/b/") trivia.move("c", "trivia_move/a/b") if trivia.exists("trivia_copy/a/b/c") and trivia.isfile( "trivia_copy/a/b/c"): print "trivia.copy ok" if trivia.exists("trivia_move/a/b/c") and trivia.isfile( "trivia_move/a/b/c"): print "trivia.move ok" trivia.remove("trivia_copy") trivia.remove("trivia_move") print_with_frame("test path") print trivia.path_join("hello", "world") print trivia.path_split("hello/world") print trivia.path_fix("hello\\world")
def run(cmd): return trivia.run(cmd)
def run_and_check(cmd): r = trivia.run(cmd) if r != 0: print "[error]cmd:" + cmd return False return True