def execute_twill_script(filename, inp=None, initial_url=None): if inp: inp_fp = StringIO(inp) old, sys.stdin = sys.stdin, inp_fp try: twill.execute_file(filename, initial_url=initial_url) finally: if inp: sys.stdin = old
def execute_twill_script(filename, inp=None, initial_url=None): global testdir if inp: inp_fp = StringIO(inp) old, sys.stdin = sys.stdin, inp_fp scriptfile = os.path.join(testdir, filename) try: twill.execute_file(filename, initial_url=initial_url) finally: if inp: sys.stdin = old
def test(): import twill global _server_url global testdir run_server(8000) #twill.execute_file(os.path.join(testdir,"test_create_account.twill"), initial_url=_server_url) twill.execute_file(os.path.join(testdir,"test_logout.twill"), initial_url=_server_url) twill.execute_file(os.path.join(testdir,"test_login.twill"), initial_url=_server_url) #twill.execute_file(os.path.join(testdir,"test_add_topic.twill"), initial_url=_server_url) #twill.execute_file(os.path.join(testdir,"test_add_message.twill"), initial_url=_server_url) #twill.execute_file(os.path.join(testdir,"test_delete_message.twill"), initial_url=_server_url) #twill.execute_file(os.path.join(testdir,"test_delete_topic.twill"), initial_url=_server_url) ### # TODO: kill server somehow # Also, not sure why these twill tests fail suddenly. ###
def execute_twill_script(filename, inp=None, initial_url=None): global testdir if inp: def new_getpass(*args): return "" inp_fp = StringIO(inp) old, sys.stdin = sys.stdin, inp_fp old_getpass, getpass.getpass = getpass.getpass, new_getpass scriptfile = os.path.join(testdir, filename) try: twill.execute_file(filename, initial_url=initial_url) finally: if inp: sys.stdin = old getpass.getpass = old_getpass
def csv_iterate(filename, scriptname): """ >> csv_iterate <csv_file> <script> For each line in <csv_file>, read in a list of comma-separated values, put them in $col1...$colN, and execute <script>. """ from twill import namespaces, execute_file global_dict, local_dict = namespaces.get_twill_glocals() reader = csv.reader(open(filename, "rb")) for i, row in enumerate(reader): logger.debug('csv_iterate: on row %d of %s', i, filename) for i, col in enumerate(row): global_dict["col%d" % (i + 1,)] = col execute_file(scriptname, no_reset=True)
def csv_iterate(filename, scriptname): """ >> csv_iterate <csv_file> <script> For each line in <csv_file>, read in a list of comma-separated values, put them in $col1...$colN, and execute <script>. """ from twill import namespaces, execute_file, commands global_dict, local_dict = namespaces.get_twill_glocals() reader = csv.reader(open(filename, "rb")) for i, row in enumerate(reader): if DEBUG: print >> commands.OUT, 'csv_iterate: on row %d of %s' % ( i, filename, ) for i, col in enumerate(row): global_dict["col%d" % (i + 1, )] = col execute_file(scriptname, no_reset=True)
def test_durus(): """ Test basic session handling with the durus session handler. """ try: import durus except ImportError: pass else: utils.setup_wsgi_intercept(test_session2.use_durus) try: old_err, sys.stderr = sys.stderr, StringIO() twill.execute_file('test/twill-tests/increment') twill.execute_file('test/twill-tests/increment+fail') twill.execute_file('test/twill-tests/logout') twill.execute_file('test/twill-tests/logout+fail') twill.execute_file('test/twill-tests/logout+nokeep') twill.execute_file('test/twill-tests/session_id') finally: sys.stderr = old_err utils.teardown_wsgi_intercept()
import twill from mysqlConnection import con, cur def resetDB(): cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM USER") con.commit() address = "http://localhost:8000" twill.execute_file("test_create_user.twill", initial_url=address) twill.execute_file("test_add_message.twill", initial_url=address) twill.execute_file("test_create_response.twill", initial_url=address) twill.execute_file("test_delete_response.twill", initial_url=address) twill.execute_file("test_initial_login.twill", initial_url=address) twill.execute_file("test_initial_logout.twill", initial_url=address) twill.execute_file("test_logged_in_postings.twill", initial_url=address) twill.execute_file("test_not_logged_in_postings.twill", initial_url=address) resetDB()
def test_05_confirm_sequence(self): twill.execute_file("tests/05ConfirmLoginLogoutSequence.twill", initial_url="http://localhost:8000")
def main(): global twillargs, interactive import sys from twill import TwillCommandLoop, execute_file, __version__ from twill.utils import gather_filenames from optparse import OptionParser from cStringIO import StringIO ### # make sure that the current working directory is in the path. does this # work on Windows?? if not '.' in sys.path: sys.path.append('.') ### #### OPTIONS parser = OptionParser() parser.add_option('-q', '--quiet', action="store_true", dest="quiet", help = 'do not show normal output') parser.add_option('-i', '--interactive', action="store_true", dest="interact", help = 'drop into an interactive shell after running files (if any)') parser.add_option('-f', '--fail', action="store_true", dest="fail", help = 'fail exit on first file to fail') parser.add_option('-n', '--never-fail', action="store_true", dest="never_fail", help = 'continue executing scripts past errors') parser.add_option('-v', '--version', action="store_true", dest="show_version", help = 'show version information and exit') parser.add_option('-u', '--url', nargs=1, action="store", dest="url", help="start at the given URL before each script") #### # parse arguments. sysargs = sys.argv[1:] if '--' in sysargs: found = False for last in range(len(sysargs) - 1, -1, -1): if sysargs[last] == '--': found = True break if found: twillargs = sysargs[last + 1:] sysargs = sysargs[:last] (options, args) = parser.parse_args(sysargs) if options.show_version: print 'twill version %s.' % (__version__,) sys.exit(0) if options.quiet: assert not options.interact, "interactive mode is incompatible with -q" assert args, "interactive mode is incompatible with -q" old_stdout = sys.stdout sys.stdout = StringIO() # If run from the command line, find & run any scripts put on the command # line. If none, drop into an interactive AutoShell. failed = False if len(args): success = [] failure = [] filenames = gather_filenames(args) for filename in filenames: print '>> EXECUTING FILE', filename try: interactive = False execute_file(filename, initial_url=options.url, never_fail=options.never_fail) success.append(filename) except Exception, e: if options.fail: # import pdb # _, _, tb = sys.exc_info() # pdb.post_mortem(tb) raise else: print '** UNHANDLED EXCEPTION:', str(e) failure.append(filename) print '--' print '%d of %d files SUCCEEDED.' % (len(success), len(success) + len(failure),) if len(failure): print 'Failed:\n\t', print "\n\t".join(failure) failed = True
import twill twill.execute_file("add_message.twill", initial_url="http://localhost:8008") twill.execute_file("add_user.twill", initial_url="http://localhost:8008") twill.execute_file("delete_message.twill", initial_url="http://localhost:8008") twill.execute_file("msg_reply.twill", initial_url="http://localhost:8008")
def test_03_reply_message(self): twill.execute_file("tests/03ReplyMessage.twill", initial_url="http://localhost:8000")
def test_search_messages(self): twill.execute_file("C:/Users/Paul/meep/test_search_messages.twill", initial_url='http://localhost:8000')
import twill twill.execute_file("twill_tests/add_message.twill", initial_url="http://localhost:8000") twill.execute_file("/twill_tests/add_user.twill", initial_url="http://localhost:8000") twill.execute_file("twill_tests/delete_message.twill", initial_url="http://localhost:8000") twill.execute_file("/twill_tests/msg_reply.twill", initial_url="http://localhost:8000")
def test_show_messages(self): twill.execute_file("C:/Users/Paul/meep/test_show_messages.twill", initial_url='http://localhost:8000')
def test_twill_index(self): twill.execute_file("C:/Users/Paul/meep/test_index.twill.txt", initial_url='http://localhost:8000')
def test_twill(self): def get_url(): if _server_url is None: raise Exception("server has not yet been started") return _server_url def run_server(PORT=8080): import time, tempfile global _server_url if PORT is None: PORT = int(os.environ.get('TWILL_TEST_PORT', '8000')) outfd = tempfile.mkstemp('twilltst')[0] print 'STARTING:', sys.executable, './servetest.py', os.getcwd() process = subprocess.Popen( [sys.executable, '-u', './servetest.py'], stderr=subprocess.STDOUT, stdout=outfd) time.sleep(1) _server_url = 'http://localhost:%d/' % (PORT, ) def kill_server(): """ Kill the previously started Quixote server. """ global _server_url if _server_url != None: try: fp = urllib.urlopen('%sexit' % (_server_url, )) except: pass _server_url = None run_server(8080) url = get_url() print url path = os.getcwd() + "/twill/" print path dir = os.listdir(path) twill.execute_file(path + "test_login.twill", initial_url=url) twill.execute_file(path + "test_add_user.twill", initial_url=url) twill.execute_file(path + "test_add_topic.twill", initial_url=url) twill.execute_file(path + "test_add_mesage.twill", initial_url=url) twill.execute_file(path + "test_reply_message.twill", initial_url=url) twill.execute_file(path + "test_delete_login.twill", initial_url=url) twill.execute_file(path + "test_delete_topic.twill", initial_url=url) kill_server()
def test_01_create_user(self): twill.execute_file("tests/01CreateUser.twill", initial_url="http://localhost:8000")
def test_twill(self): def get_url(): if _server_url is None: raise Exception("server has not yet been started") return _server_url def run_server(PORT=8080): import time, tempfile global _server_url if PORT is None: PORT = int(os.environ.get('TWILL_TEST_PORT', '8000')) outfd = tempfile.mkstemp('twilltst')[0] print 'STARTING:', sys.executable, './servetest.py', os.getcwd() process = subprocess.Popen([sys.executable, '-u', './servetest.py'], stderr=subprocess.STDOUT, stdout=outfd) time.sleep(1) _server_url = 'http://localhost:%d/' % (PORT,) def kill_server(): """ Kill the previously started Quixote server. """ global _server_url if _server_url != None: try: fp = urllib.urlopen('%sexit' % (_server_url,)) except: pass _server_url = None run_server(8080) url = get_url() print url path = os.getcwd() + "/twill/" print path dir = os.listdir(path) twill.execute_file(path + "test_login.twill", initial_url=url) twill.execute_file(path + "test_add_user.twill", initial_url=url) twill.execute_file(path + "test_add_topic.twill", initial_url=url) twill.execute_file(path + "test_add_mesage.twill", initial_url=url) twill.execute_file(path + "test_reply_message.twill", initial_url=url) twill.execute_file(path + "test_delete_login.twill", initial_url=url) twill.execute_file(path + "test_delete_topic.twill", initial_url=url) kill_server()
import twill twill.execute_file("tests/create_user.twill", initial_url="http://localhost:8000") twill.execute_file("tests/message_add.twill", initial_url="http://localhost:8000") twill.execute_file("tests/message_delete.twill", initial_url="http://localhost:8000") twill.execute_file("tests/message_reply.twill", initial_url="http://localhost:8000")
def test_shelve(): """ Test basic session handling with the shelve session handler. """ utils.setup_wsgi_intercept(test_session2.use_shelve) try: old_err, sys.stderr = sys.stderr, StringIO() twill.execute_file('test/twill-tests/increment') twill.execute_file('test/twill-tests/increment+fail') twill.execute_file('test/twill-tests/logout') twill.execute_file('test/twill-tests/logout+fail') twill.execute_file('test/twill-tests/logout+nokeep') twill.execute_file('test/twill-tests/session_id') finally: sys.stderr = old_err utils.teardown_wsgi_intercept()
def test_02_add_message(self): twill.execute_file("tests/02AddMessage.twill", initial_url="http://localhost:8000")
import twill twill.execute_file("test_create_user.twill", initial_url="http://localhost:8008") twill.execute_file("test_add_message.twill", initial_url="http://localhost:8008") twill.execute_file("test_delete_message.twill", initial_url="http://localhost:8008") twill.execute_file("test_reply.twill", initial_url="http://localhost:8008") twill.execute_file("test_SAM.twill", initial_url="http://localhost:8008") twill.execute_file("test_logout.twill", initial_url="http://localhost:8008")
def test_04_delete_message(self): twill.execute_file("tests/04DeleteMessage.twill", initial_url="http://localhost:8000")
def main(): global twillargs, interactive import sys from twill import TwillCommandLoop, execute_file, __version__ from twill.utils import gather_filenames from optparse import OptionParser from cStringIO import StringIO ### # make sure that the current working directory is in the path. does this # work on Windows?? if not '.' in sys.path: sys.path.append('.') ### #### OPTIONS parser = OptionParser() parser.add_option('-q', '--quiet', action="store_true", dest="quiet", help = 'do not show normal output') parser.add_option('-i', '--interactive', action="store_true", dest="interact", help = 'drop into an interactive shell after running files (if any)') parser.add_option('-f', '--fail', action="store_true", dest="fail", help = 'fail exit on first file to fail') parser.add_option('-n', '--never-fail', action="store_true", dest="never_fail", help = 'continue executing scripts past errors') parser.add_option('-v', '--version', action="store_true", dest="show_version", help = 'show version information and exit') parser.add_option('-u', '--url', nargs=1, action="store", dest="url", help="start at the given URL before each script") parser.add_option('-l', '--loglevel', nargs=1, action="store", dest="loglevel", help="set the log level") parser.add_option('-L', '--logfile', nargs=1, action="store", dest="logfile", help="use logfile as output for log, or discards log if value is 'none'") parser.add_option('-o', '--output', nargs=1, action="store", dest="outfile", help="print output to outfile, or discards output if value is 'none'") parser.add_option('-t', '--tidy', nargs=1, action="store", dest="tidycmd", help="uses tidycmd as the tidy command") #### # parse arguments. sysargs = sys.argv[1:] if '--' in sysargs: found = False for last in range(len(sysargs) - 1, -1, -1): if sysargs[last] == '--': found = True break if found: twillargs = sysargs[last + 1:] sysargs = sysargs[:last] (options, args) = parser.parse_args(sysargs) if options.show_version: print('twill version %s.' % __version__) sys.exit(0) if options.loglevel: if options.loglevel not in logconfig.loglevels: sys.exit("valid log levels are " + ", ".join(logconfig.loglevels.keys())) logconfig.logger.setLevel(logconfig.loglevels[options.loglevel]) if options.logfile: try: path = options.logfile if options.logfile != 'none' else os.devnull logfile = open(path, 'w') logfile.write('') logconfig.set_handler_for_stream(logfile) except IOError as e: sys.exit("Invalid logfile '%s': %s", options.logfile, e) if options.outfile: try: path = options.outfile if options.outfile != 'none' else os.devnull outfile = open(path, 'w') outfile.write('') sys.stdout = outfile except IOError as e: sys.exit("Invalid output file '%s': %s", options.logfile, e) if options.quiet: if options.interact: logger.critical("interactive mode is incompatible with -q") sys.exit(1) if not args: sys.exit("interactive mode is incompatible with -q") old_stdout = sys.stdout sys.stdout = open(os.devnull, 'w') logconfig.set_handler_for_stream(sys.stdout) if options.tidycmd: config.tidy_cmd = options.tidycmd # If run from the command line, find & run any scripts put on the command # line. If none, drop into an interactive AutoShell. failed = False if len(args): success = [] failure = [] filenames = gather_filenames(args) for filename in filenames: logger.info('>> EXECUTING FILE %s', filename) try: interactive = False execute_file(filename, initial_url=options.url, never_fail=options.never_fail) success.append(filename) except Exception, e: if options.fail: # import pdb # _, _, tb = sys.exc_info() # pdb.post_mortem(tb) raise else: logger.error('** UNHANDLED EXCEPTION: %s', str(e)) logger.debug(traceback.format_exc()) failure.append(filename) logger.info('--') logger.info('%d of %d files SUCCEEDED.', len(success), len(success) + len(failure)) if len(failure): logger.error('Failed:\n\t') logger.error("\n\t".join(failure)) failed = True