Пример #1
0
def main():
    """A simple test runner.

    This test runner is essentially equivalent to `unittest.main` from
    the standard library, but adds support for tornado-style option
    parsing and log formatting.

    The easiest way to run a test is via the command line::

        python -m anzu.testing anzu.test.stack_context_test

    See the standard library unittest module for ways in which tests can
    be specified.

    Projects with many tests may wish to define a test script like
    anzu/test/runtests.py.  This script should define a method all()
    which returns a test suite and then call anzu.testing.main().
    Note that even when a test script is used, the all() test suite may
    be overridden by naming a single test on the command line::

        # Runs all tests
        tornado/test/runtests.py
        # Runs one test
        tornado/test/runtests.py anzu.test.stack_context_test

    """
    from anzu.options import define, options, parse_command_line

    define('autoreload', type=bool, default=False,
           help="DEPRECATED: use anzu.autoreload.main instead")
    define('httpclient', type=str, default=None)
    argv = [sys.argv[0]] + parse_command_line(sys.argv)

    if options.httpclient:
        from anzu.httpclient import AsyncHTTPClient
        AsyncHTTPClient.configure(options.httpclient)

    if __name__ == '__main__' and len(argv) == 1:
        print >> sys.stderr, "No tests specified"
        sys.exit(1)
    try:
        # In order to be able to run tests by their fully-qualified name
        # on the command line without importing all tests here,
        # module must be set to None.  Python 3.2's unittest.main ignores
        # defaultTest if no module is given (it tries to do its own
        # test discovery, which is incompatible with auto2to3), so don't
        # set module if we're not asking for a specific test.
        if len(argv) > 1:
            unittest.main(module=None, argv=argv)
        else:
            unittest.main(defaultTest="all", argv=argv)
    except SystemExit, e:
        if e.code == 0:
            logging.info('PASS')
        else:
            logging.error('FAIL')
        if not options.autoreload:
            raise
Пример #2
0
def main():
    """A simple test runner.

    This test runner is essentially equivalent to `unittest.main` from
    the standard library, but adds support for tornado-style option
    parsing and log formatting.

    The easiest way to run a test is via the command line::

        python -m anzu.testing anzu.test.stack_context_test

    See the standard library unittest module for ways in which tests can
    be specified.

    Projects with many tests may wish to define a test script like
    anzu/test/runtests.py.  This script should define a method all()
    which returns a test suite and then call anzu.testing.main().
    Note that even when a test script is used, the all() test suite may
    be overridden by naming a single test on the command line::

        # Runs all tests
        tornado/test/runtests.py
        # Runs one test
        tornado/test/runtests.py anzu.test.stack_context_test

    """
    from anzu.options import define, options, parse_command_line

    define("autoreload", type=bool, default=False, help="DEPRECATED: use anzu.autoreload.main instead")
    define("httpclient", type=str, default=None)
    argv = [sys.argv[0]] + parse_command_line(sys.argv)

    if options.httpclient:
        from anzu.httpclient import AsyncHTTPClient

        AsyncHTTPClient.configure(options.httpclient)

    if __name__ == "__main__" and len(argv) == 1:
        print >>sys.stderr, "No tests specified"
        sys.exit(1)
    try:
        # In order to be able to run tests by their fully-qualified name
        # on the command line without importing all tests here,
        # module must be set to None.  Python 3.2's unittest.main ignores
        # defaultTest if no module is given (it tries to do its own
        # test discovery, which is incompatible with auto2to3), so don't
        # set module if we're not asking for a specific test.
        if len(argv) > 1:
            unittest.main(module=None, argv=argv)
        else:
            unittest.main(defaultTest="all", argv=argv)
    except SystemExit, e:
        if e.code == 0:
            logging.info("PASS")
        else:
            logging.error("FAIL")
        if not options.autoreload:
            raise
Пример #3
0
def main():
    from anzu.options import define, options, parse_command_line
    define("print_headers", type=bool, default=False)
    define("print_body", type=bool, default=True)
    define("follow_redirects", type=bool, default=True)
    args = parse_command_line()
    client = HTTPClient()
    for arg in args:
        try:
            response = client.fetch(arg,
                                    follow_redirects=options.follow_redirects)
        except HTTPError, e:
            if e.response is not None:
                response = e.response
            else:
                raise
        if options.print_headers:
            print response.headers
        if options.print_body:
            print response.body
Пример #4
0
# python -m cProfile -o /tmp/prof demos/benchmark/benchmark.py
# python -m pstats /tmp/prof
# % sort time
# % stats 20

from anzu.ioloop import IOLoop
from anzu.options import define, options, parse_command_line
from anzu.web import RequestHandler, Application, location

import random
import signal
import subprocess

# choose a random port to avoid colliding with TIME_WAIT sockets left over
# from previous runs.
define("min_port", type=int, default=8000)
define("max_port", type=int, default=9000)

# Increasing --n without --keepalive will eventually run into problems
# due to TIME_WAIT sockets
define("n", type=int, default=15000)
define("c", type=int, default=25)
define("keepalive", type=bool, default=False)
define("quiet", type=bool, default=False)

# Repeat the entire benchmark this many times (on different ports)
# This gives JITs time to warm up, etc.  Pypy needs 3-5 runs at
# --n=15000 for its JIT to reach full effectiveness
define("num_runs", type=int, default=1)

Пример #5
0
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import os.path
import anzu.auth
import anzu.escape
import anzu.httpserver
import anzu.ioloop
import anzu.options
import anzu.web

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)
define("facebook_api_key",
       help="your Facebook application API key",
       default="9e2ada1b462142c4dfcc8e894ea1e37c")
define("facebook_secret",
       help="your Facebook application secret",
       default="32fc6114554e3c53d5952594510021e2")


class Application(anzu.web.Application):
    def __init__(self):
        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
Пример #6
0
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import os.path
import anzu.auth
import anzu.escape
import anzu.httpserver
import anzu.ioloop
import anzu.options
import anzu.web

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)
define("facebook_api_key", help="your Facebook application API key",
       default="9e2ada1b462142c4dfcc8e894ea1e37c")
define("facebook_secret", help="your Facebook application secret",
       default="32fc6114554e3c53d5952594510021e2")


class Application(anzu.web.Application):
    def __init__(self):
        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/auth/login",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            facebook_api_key=options.facebook_api_key,
Пример #7
0
# python -m cProfile -o /tmp/prof demos/benchmark/benchmark.py
# python -m pstats /tmp/prof
# % sort time
# % stats 20

from anzu.ioloop import IOLoop
from anzu.options import define, options, parse_command_line
from anzu.web import RequestHandler, Application, location

import random
import signal
import subprocess

# choose a random port to avoid colliding with TIME_WAIT sockets left over
# from previous runs.
define("min_port", type=int, default=8000)
define("max_port", type=int, default=9000)

# Increasing --n without --keepalive will eventually run into problems
# due to TIME_WAIT sockets
define("n", type=int, default=15000)
define("c", type=int, default=25)
define("keepalive", type=bool, default=False)
define("quiet", type=bool, default=False)

# Repeat the entire benchmark this many times (on different ports)
# This gives JITs time to warm up, etc.  Pypy needs 3-5 runs at
# --n=15000 for its JIT to reach full effectiveness
define("num_runs", type=int, default=1)

@location('/')
Пример #8
0
Authentication, error handling, etc are left as an exercise for the reader :)
"""

import logging
import anzu.escape
import anzu.ioloop
import anzu.options
import anzu.web
import anzu.websocket
import os.path
import uuid

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)


class Application(anzu.web.Application):
    def __init__(self):
        handlers = [
            (r"/", MainHandler),
            (r"/chatsocket", ChatSocketHandler),
        ]
        settings = dict(
            cookie_secret="43oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=True,
            autoescape=None,
        )
Пример #9
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import anzu.httpserver
import anzu.ioloop
import anzu.options
import anzu.web

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)


@anzu.web.location('/')
class MainHandler(anzu.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


def main():
    anzu.options.parse_command_line()
    application = anzu.web.Application()
    http_server = anzu.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    anzu.ioloop.IOLoop.instance().start()
Пример #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from os import urandom

from anzu.options import define

__all__ = []

define("port", default=8080, help="run on the given port", type=int)
define("debug", default=False, help="enables Anzu's debugging options", type=bool)
define("compress_whitespace", default=True, help="eliminates unnecessary whitespace within Mako's templates", type=bool)
define("cookie_secret", default=urandom(8192), help="seed and key for various cookie securing functions")
define("login_url", default="/login", help="where unauthenticated users shall be send to")

define("database", default="sqlite:////var/lib/evedir/data.sqlite3", help="the database connection string that will be passed to SQL-Alchemy")
define("hostname", help="public hostname (including http:// or https://) of this installation - without port")

define("file_storage", default="/var/lib/evedir", help="this directory will be used to store files related to capaigns")

define("sync_wallets_every", default=8, help="hours to wait between wallet synchronization runs")
Пример #11
0
#!/usr/bin/env python
#
# A simple benchmark of tornado template rendering, based on
# https://github.com/mitsuhiko/jinja2/blob/master/examples/bench.py

import sys
from timeit import Timer

from anzu.options import options, define, parse_command_line
from anzu.template import Template

define('num', default=100, help='number of iterations')
define('dump', default=False, help='print template generated code and exit')

context = {
    'page_title': 'mitsuhiko\'s benchmark',
    'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) for x in range(1000)]
}

tmpl = Template("""\
<!doctype html>
<html>
  <head>
    <title>{{ page_title }}</title>
  </head>
  <body>
    <div class="header">
      <h1>{{ page_title }}</h1>
    </div>
    <ul class="navigation">
    {% for href, caption in [ \
Пример #12
0
# -*- coding: utf-8 -*-
#
# Copyright 2010 W-Mark Kubacki; [email protected]
#

__all__ = []

from anzu.options import define

# default options
define("cookie_secret", default="srdfERGdfgERTdrgdfg", help="seed and key for various cookie securing functions")
define("debug", default=False, help="enables Anzu's debugging options", type=bool)
define("port", default=8888, help="run on the given port", type=int)
Пример #13
0
# under the License.

import markdown
import os.path
import re
import anzu.auth
import anzu.database
import anzu.httpserver
import anzu.ioloop
import anzu.options
import anzu.web
import unicodedata

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)
define("mysql_host", default="127.0.0.1:3306", help="blog database host")
define("mysql_database", default="blog", help="blog database name")
define("mysql_user", default="blog", help="blog database user")
define("mysql_password", default="blog", help="blog database password")


class Application(anzu.web.Application):
    def __init__(self):
        settings = dict(
            blog_title=u"Anzu Blog",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules={"Entry": EntryModule},
            xsrf_cookies=True,
            cookie_secret="11oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
Пример #14
0
#!/usr/bin/env python
#
# A simple benchmark of tornado template rendering, based on
# https://github.com/mitsuhiko/jinja2/blob/master/examples/bench.py

import sys
from timeit import Timer

from anzu.options import options, define, parse_command_line
from anzu.template import Template

define('num', default=100, help='number of iterations')
define('dump', default=False, help='print template generated code and exit')

context = {
    'page_title':
    'mitsuhiko\'s benchmark',
    'table': [
        dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10)
        for x in range(1000)
    ]
}

tmpl = Template("""\
<!doctype html>
<html>
  <head>
    <title>{{ page_title }}</title>
  </head>
  <body>
    <div class="header">
Пример #15
0
Файл: blog.py Проект: wmark/anzu
# under the License.

import markdown
import os.path
import re
import anzu.auth
import anzu.database
import anzu.httpserver
import anzu.ioloop
import anzu.options
import anzu.web
import unicodedata

from anzu.options import define, options

define("port", default=8888, help="run on the given port", type=int)
define("mysql_host", default="127.0.0.1:3306", help="blog database host")
define("mysql_database", default="blog", help="blog database name")
define("mysql_user", default="blog", help="blog database user")
define("mysql_password", default="blog", help="blog database password")


class Application(anzu.web.Application):
    def __init__(self):
        settings = dict(
            blog_title=u"Anzu Blog",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            ui_modules={"Entry": EntryModule},
            xsrf_cookies=True,
            cookie_secret="11oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",