Example #1
0
    def __init__(self, ss, silent = False):
        """The main entry point for VariantSpark functionality.
        :param ss: SparkSession
        :type ss: :class:`.pyspark.SparkSession`
        :param bool silent: Do not produce welcome info.
        """
        self.sc = ss.sparkContext
        self.silent = silent
        self.sql = SQLContext.getOrCreate(self.sc)
        self._jsql = self.sql._jsqlContext
        self._jvm = self.sc._jvm
        self._vs_api = getattr(self._jvm, 'au.csiro.variantspark.api')
        jss = ss._jsparkSession
        self._jvsc = self._vs_api.VSContext.apply(jss)

        setup_typecheck()

        if not self.silent:
            sys.stderr.write('Running on Apache Spark version {}\n'.format(self.sc.version))
            if self.sc._jsc.sc().uiWebUrl().isDefined():
                sys.stderr.write('SparkUI available at {}\n'.format(
                        self.sc._jsc.sc().uiWebUrl().get()))
            sys.stderr.write(
                'Welcome to\n'
                ' _    __           _             __  _____                  __    \n'
                '| |  / /___ ______(_)___ _____  / /_/ ___/____  ____ ______/ /__  \n'
                '| | / / __ `/ ___/ / __ `/ __ \/ __/\__ \/ __ \/ __ `/ ___/ //_/  \n'
                '| |/ / /_/ / /  / / /_/ / / / / /_ ___/ / /_/ / /_/ / /  / ,<     \n'
                '|___/\__,_/_/  /_/\__,_/_/ /_/\__//____/ .___/\__,_/_/  /_/|_|    \n'
                '                                      /_/                         \n')
Example #2
0
    def test_custom_exceptions(self):
        class MyError(Exception):
            pass

        setup_typecheck(exception=MyError)

        @returns(int)
        def foo():
            pass

        self.assertRaises(MyError, lambda: foo())
Example #3
0
    def test_custom_exceptions(self):
        class MyError(Exception):
            pass

        setup_typecheck(exception=MyError)

        @returns(int)
        def foo():
            pass

        self.assertRaises(MyError, lambda: foo())
Example #4
0
    def test_disabled_exception(self):
        setup_typecheck()

        @returns(int)
        def foo():
            pass

        self.assertRaises(TypeError, lambda: foo())

        setup_typecheck(exception=None)

        # should not raise anything any more
        foo()
Example #5
0
    def test_disabled_exception(self):
        setup_typecheck()

        @returns(int)
        def foo():
            pass

        self.assertRaises(TypeError, lambda: foo())

        setup_typecheck(exception=None)

        # should not raise anything any more
        foo()
Example #6
0
 def setUp(self):
     setup_typecheck()
Example #7
0
from functools import partial
import os

import pytest
from typedecorator import setup_typecheck

from finance import create_app
from finance.models import Account, Asset, Portfolio
from finance.models import db as _db

setup_typecheck()


@pytest.fixture(scope='module')
def app(request):
    """Session-wide test `Flask` application."""
    settings_override = {
        'TESTING': True,
    }
    if 'TEST_DB_URI' in os.environ:
        settings_override['SQLALCHEMY_DATABASE_URI'] = \
            os.environ.get('TEST_DB_URI')
    app = create_app(__name__, config=settings_override)

    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()
Example #8
0
import json
import logging
import types

import requests
import typedecorator

from urconf.uptimerobot_syncable import Contact, Monitor

logger = logging.getLogger("urconf")
typedecorator.setup_typecheck()

DEFAULT_INTERVAL = 5  # minutes

# There are some error codes that mean that mean there is no objects of a given
# type (alert contacts or monitors) defined in the account yet. They are:
# 212: The account has no monitors
# 221: The account has no alert contacts
NO_OBJECTS_ERROR_CODES = ["212", "221"]


class UptimeRobotAPIError(Exception):
    """An exception which is raised when Uptime Robot API returns an error."""
    pass


class UptimeRobot(object):
    """UptimeRobot is the main object used to sync configuration.

    It keeps alert contacts and monitors defined by the user in
    `self._contacts` and `self_monitors` lists.
Example #9
0
def main():
    parser = OptionParser(usage="usage: python %prog [options] text")
    parser.add_option("-f",
                      "--file",
                      dest="input",
                      type=str,
                      help="input file path; takes precedence over `text` arg")
    parser.add_option("-o",
                      "--output",
                      dest="output",
                      type=str,
                      help="output file path")
    parser.add_option(
        "--show",
        dest="show",
        action="store_true",
        help="show image (defaults to true if no output specified)")
    parser.add_option("--width",
                      dest="width",
                      type=int,
                      default=10,
                      help="grid width in braille characters; default=10")
    parser.add_option("--margin",
                      dest="margin",
                      type=int,
                      default=1,
                      help="margin in dots")
    parser.add_option("--padding",
                      dest="padding",
                      type=int,
                      default=1,
                      help="padding in dots")
    parser.add_option("--dotsize",
                      dest="dot_size",
                      type=int,
                      default=10,
                      help="dot size in pixels")
    (options, args) = parser.parse_args()

    # Obtain text input
    text_lines = args
    if options.input:
        if len(args) > 0:
            print "Ignoring text input; using file"
        text_lines = [
            line.strip() for line in open(options.input, 'r').readlines()
        ]
    else:
        assert len(args) == 1, "Must provide input"

    # Setup
    setup_typecheck()
    gen = BrailleImageGenerator()

    # Generate image
    im = gen.convert(
        text_lines,
        char_width=options.width,
        dot_margin=options.margin,
        dot_padding=options.padding,
    )
    im = im.resize(
        (im.size[0] * options.dot_size, im.size[1] * options.dot_size))
    if options.output:
        im.save(options.output)
    if options.show or not options.output:
        im.show()
Example #10
0
 def setUp(self):
     setup_typecheck()
Example #11
0
import json
import logging
import types

import requests
import typedecorator

from urconf.uptimerobot_syncable import Contact, Monitor

logger = logging.getLogger("urconf")
typedecorator.setup_typecheck()

DEFAULT_INTERVAL = 5  # minutes

# There are some error codes that mean that mean there is no objects of a given
# type (alert contacts or monitors) defined in the account yet. They are:
# 212: The account has no monitors
# 221: The account has no alert contacts
NO_OBJECTS_ERROR_CODES = ["212", "221"]


class UptimeRobotAPIError(Exception):
    """An exception which is raised when Uptime Robot API returns an error."""
    pass


class UptimeRobot(object):
    """UptimeRobot is the main object used to sync configuration.

    It keeps alert contacts and monitors defined by the user in
    `self._contacts` and `self_monitors` lists.