示例#1
0
文件: store.py 项目: delfick/photons
from photons_app.formatter import MergedOptionStringFormatter

from whirlwind.store import Store

store = Store(default_path="/v1/lifx/command",
              formatter=MergedOptionStringFormatter)


def load_commands():
    __import__("arranger.commander.commands")
示例#2
0
# coding: spec

from whirlwind.commander import Commander
from whirlwind import test_helpers as thp
from whirlwind.store import Store

from delfick_project.option_merge import MergedOptionStringFormatter, BadOptionFormat, MergedOptions
from delfick_project.norms import dictobj, sb, BadSpecValue
from delfick_project.errors_pytest import assertRaises
from unittest import mock
import uuid

store = Store(default_path="/v1", formatter=MergedOptionStringFormatter)


@store.command("fields_are_required")
class FieldsRequired(store.Command):
    notexisting = store.injected("notexisting")

    async def execute(self):
        assert False, "Shouldn't make it this far"


@store.command("injected_can_have_format_into")
class InjectedHaveFormatInto(store.Command):
    option = store.injected("option", format_into=sb.integer_spec)

    async def execute(self):
        assert False, "Shouldn't make it this far"

示例#3
0
from whirlwind.request_handlers.base import MessageFromExc
from whirlwind.request_handlers.command import WSHandler
from whirlwind.commander import Commander
from whirlwind.store import Store

from delfick_project.option_merge.formatter import MergedOptionStringFormatter
from delfick_project.errors import DelfickError
from delfick_project.norms import dictobj, sb
from unittest import mock
import asyncio
import pytest
import time
import uuid


store = Store(formatter=MergedOptionStringFormatter)


@store.command("interactive")
class Interactive(store.Command):
    progress_cb = store.injected("progress_cb")

    async def execute(self, messages):
        self.progress_cb("started")
        async for message in messages:
            message.no_process()
            if isinstance(message.command, Stop):
                break


@store.command("stop", parent=Interactive)
示例#4
0
from delfick_project.option_merge import MergedOptionStringFormatter
from delfick_project.norms import dictobj, sb, Meta, BadSpecValue
from delfick_project.errors_pytest import assertRaises
from unittest import mock
import inspect
import asyncio
import uuid
import sys

describe "Store":
    it "takes in some things":
        prefix = mock.Mock(name="prefix")
        formatter = mock.Mock(name="formatter")
        default_path = mock.Mock(name="default_path")

        store = Store(prefix=prefix, default_path=default_path, formatter=formatter)

        assert store.prefix is prefix
        assert store.default_path is default_path
        assert store.formatter is formatter
        assert isinstance(store.command_spec, command_spec)
        assert store.command_spec.paths is store.paths

        assert dict(store.paths) == {}

    it "has defaults":
        store = Store()

        assert store.prefix == ""
        assert store.default_path == "/v1"
        assert store.formatter is None
示例#5
0
# coding: spec

from whirlwind.request_handlers.command import WSHandler
from whirlwind.server import Server, wait_for_futures
from whirlwind import test_helpers as thp
from whirlwind.commander import Commander
from whirlwind.store import Store

import asyncio
import pytest
import time

store = Store()


@store.command("blah")
class Blah(store.Command):
    async def execute(self):
        return {"hello": "there"}


@store.command("meh")
class Meh(store.Command):
    async def execute(self):
        return {"good": "bye"}


def tornado_routes(server):
    return [
        (
            "/v1/ws",