[3] | 1 | # This file is part of the twill source distribution. |
---|
| 2 | # |
---|
| 3 | # twill is a extensible scriptlet language for testing Web apps, |
---|
| 4 | # available at http://twill.idyll.org/. |
---|
| 5 | # |
---|
| 6 | # Contact author: C. Titus Brown, titus@idyll.org. |
---|
| 7 | # |
---|
| 8 | # This program and all associated source code files are Copyright (C) |
---|
| 9 | # 2005-2007 by C. Titus Brown. It is released under the MIT license; |
---|
| 10 | # please see the included LICENSE.txt file for more information, or |
---|
| 11 | # go to http://www.opensource.org/licenses/mit-license.php. |
---|
| 12 | |
---|
| 13 | """ |
---|
| 14 | twill Web testing language & associated utilities. |
---|
| 15 | """ |
---|
| 16 | |
---|
| 17 | __version__ = "0.9" |
---|
| 18 | |
---|
| 19 | #import warnings |
---|
| 20 | #warnings.defaultaction = "error" |
---|
| 21 | |
---|
| 22 | #import pychecker.checker |
---|
| 23 | |
---|
| 24 | __all__ = [ "TwillCommandLoop", |
---|
| 25 | "execute_file", |
---|
| 26 | "execute_string", |
---|
| 27 | "get_browser", |
---|
| 28 | "add_wsgi_intercept", |
---|
| 29 | "remove_wsgi_intercept", |
---|
| 30 | "set_output", |
---|
| 31 | "set_errout"] |
---|
| 32 | |
---|
| 33 | # |
---|
| 34 | # add extensions (twill/extensions) and the the wwwsearch & pyparsing |
---|
| 35 | # stuff from twill/included-packages/. NOTE: this works with eggs! hooray! |
---|
| 36 | # |
---|
| 37 | |
---|
| 38 | import sys, os.path |
---|
| 39 | thisdir = os.path.dirname(__file__) |
---|
| 40 | |
---|
| 41 | # add extensions directory at the *end* of sys.path. This means that |
---|
| 42 | # user extensions will take priority over twill extensions. |
---|
| 43 | extensions = os.path.join(thisdir, 'extensions') |
---|
| 44 | sys.path.append(extensions) |
---|
| 45 | |
---|
| 46 | # add other_packages in at the *beginning*, so that the correct |
---|
| 47 | # (patched) versions of pyparsing and mechanize get imported. |
---|
| 48 | wwwsearchlib = os.path.join(thisdir, 'other_packages') |
---|
| 49 | sys.path.insert(0, wwwsearchlib) |
---|
| 50 | |
---|
| 51 | # the two core components of twill: |
---|
| 52 | from shell import TwillCommandLoop |
---|
| 53 | from parse import execute_file, execute_string |
---|
| 54 | |
---|
| 55 | # convenience function or two... |
---|
| 56 | from commands import get_browser |
---|
| 57 | |
---|
| 58 | def get_browser_state(): |
---|
| 59 | import warnings |
---|
| 60 | warnings.warn("""\ |
---|
| 61 | get_browser_state is deprecated; use 'twill.get_browser() instead. |
---|
| 62 | """, DeprecationWarning) |
---|
| 63 | return get_browser() |
---|
| 64 | |
---|
| 65 | # initialize global dict |
---|
| 66 | import namespaces |
---|
| 67 | namespaces.init_global_dict() |
---|
| 68 | |
---|
| 69 | from wsgi_intercept import add_wsgi_intercept, remove_wsgi_intercept |
---|
| 70 | |
---|
| 71 | def set_output(fp): |
---|
| 72 | """ |
---|
| 73 | Have standard output from twill go to the given fp instead of |
---|
| 74 | stdout. fp=None will reset to stdout. |
---|
| 75 | """ |
---|
| 76 | import commands, browser |
---|
| 77 | commands.OUT = browser.OUT = fp |
---|
| 78 | |
---|
| 79 | def set_errout(fp): |
---|
| 80 | """ |
---|
| 81 | Have error output from twill go to the given fp instead of stderr. |
---|
| 82 | fp=None will reset to stderr. |
---|
| 83 | """ |
---|
| 84 | import commands |
---|
| 85 | if fp: |
---|
| 86 | commands.ERR = fp |
---|
| 87 | else: |
---|
| 88 | commands.ERR = sys.stderr |
---|