Ejemplo n.º 1
0
class MemoryTarget(Target):
    """
    Knows how to talk to fake devices as if they were on the network.
    """

    devices = dictobj.Field(sb.listof(sb.any_spec()), wrapper=sb.required)
    default_broadcast = dictobj.Field(
        sb.defaulted(sb.string_spec(), "255.255.255.255"))

    session_kls = makeMemorySession(NetworkSession)
Ejemplo n.º 2
0
class MemoryTarget(LanTarget):
    """
    Knows how to talk to fake devices as if they were on the network.
    """

    gaps = dictobj.Field(
        Gaps(gap_between_results=0.05,
             gap_between_ack_and_res=0.05,
             timeouts=[(0.2, 0.2)]))
    io_service = dictobj.Field(sb.any_spec, default=MemoryService)
    transport_kls = dictobj.Field(sb.any_spec, default=MemoryTransport)

    devices = dictobj.Field(sb.listof(sb.any_spec()), wrapper=sb.required)
    default_broadcast = dictobj.Field(
        sb.defaulted(sb.string_spec(), "255.255.255.255"))

    session_kls = makeMemorySession(NetworkSession)
Ejemplo n.º 3
0
 def normalise_filled(self, meta, val):
     val = sized_list_spec(sb.any_spec(), 4).normalise(meta, val)
     res = []
     for i, (v, s) in enumerate(zip(val, self.specs)):
         res.append(s.normalise(meta.at(i), v))
     return res
Ejemplo n.º 4
0
    ("Uint16", 16, "<H", int),
    ("Int32", 32, "<i", int),
    ("Uint32", 32, "<I", int),
    ("Int64", 64, "<q", int),
    ("Uint64", 64, "<Q", int),
    ("Float", 32, "<f", float),
    ("Double", 64, "<d", float),
    ("Bytes", None, None, bytes),
    ("String", None, None, str),
    ("Reserved", None, None, bytes),
    ("CSV", None, None, (list, str, ",")),
    ("JSON", None, None, json),
)

json_spec = sb.match_spec(
    (bool, sb.any_spec()),
    (int, sb.any_spec()),
    (float, sb.any_spec()),
    (str, sb.any_spec()),
    (list, lambda: sb.listof(json_spec)),
    (type(None), sb.any_spec()),
    fallback=lambda: sb.dictof(sb.string_spec(), json_spec),
)

# Here so we don't have to instantiate these every time we get a value from a packet
static_conversion_from_spec = {
    any: sb.any_spec(),
    bool: boolean(),
    float: float_spec(),
    (bool, int): boolean_as_int_spec(),
    json: json_spec,
Ejemplo n.º 5
0
    it "knows about string_spec":
        self.assertSignature(sb.string_spec(), "string")

    it "knows about boolean":
        self.assertSignature(sb.boolean(), "boolean")

    it "knows about dictionary_spec":
        self.assertSignature(sb.dictionary_spec(), "dictionary")

    it "knows about string_choice_spec":
        self.assertSignature(sb.string_choice_spec(["one", "two"]), "choice of (one | two)")

    it "knows about optional_spec":
        self.assertSignature(sb.optional_spec(sb.integer_spec()), "integer (optional)")
        self.assertSignature(sb.optional_spec(sb.any_spec()), "(optional)")

    it "knows about defaulted":
        self.assertSignature(sb.defaulted(sb.integer_spec(), 20), "integer (default 20)")
        self.assertSignature(sb.defaulted(sb.any_spec(), True), "(default True)")

    it "knows about required":
        self.assertSignature(sb.required(sb.integer_spec()), "integer (required)")
        self.assertSignature(sb.required(sb.any_spec()), "(required)")

    it "knows about listof":
        self.assertSignature(sb.listof(sb.integer_spec()), "[ integer , ... ]")
        self.assertSignature(sb.listof(sb.any_spec()), "[ <item> , ... ]")

    it "knows about dictof":
        self.assertSignature(sb.dictof(sb.string_spec(), sb.integer_spec()), "{ string : integer }")
Ejemplo n.º 6
0
from photons_app.errors import BadTarget, BadOption, BadTask
from photons_app.tasks.tasks import Task, GracefulTask

from delfick_project.norms import sb, dictobj
from collections import namedtuple

artifact_spec = lambda: sb.optional_spec(sb.any_spec())


class target_spec(sb.Spec):
    def setup(self, restrictions, *, mandatory=True):
        self.mandatory = mandatory
        self.restrictions = restrictions

    def normalise_empty(self, meta):
        if not self.mandatory:
            return sb.NotSpecified

        usage = "lifx <target>:<task> <reference> <artifact> -- '{{<options>}}'"
        raise BadTarget("This task requires you specify a target",
                        usage=usage,
                        meta=meta)

    def normalise(self, meta, val):
        if val in ("", None, sb.NotSpecified):
            return self.normalise_empty(meta)

        collector = meta.everything["collector"]
        target_register = collector.configuration["target_register"]
        return target_register.restricted(**self.restrictions).resolve(val)
Ejemplo n.º 7
0
 class Options(dictobj.Spec):
     got_event_fut = dictobj.NullableField(sb.any_spec())
     record_annotations = dictobj.Field(sb.boolean, default=False)
     record_events_store = dictobj.Field(sb.any_spec(), wrapper=sb.required)
Ejemplo n.º 8
0
        it "calls post_register":
            register = mock.Mock(name="register")
            collector = Collector()
            collector.register = register

            final_future = hp.create_future()
            photons_app = mock.Mock(name="photons_app", final_future=final_future)

            configuration = MergedOptions.using({"photons_app": photons_app}, dont_prefix=[dictobj])
            args_dict = mock.Mock(name="args_dict")

            # Necessary setup for extra_prepare_after_activation
            collector.extra_configuration_collection(configuration)
            collector.register_converters(
                {
                    "photons_app": sb.any_spec(),
                },
                configuration=configuration,
            )
            configuration.converters._converters.insert(
                0, configuration.converters._converters.pop()
            )
            configuration.converters.activate()

            collector.extra_prepare_after_activation(configuration, args_dict)
            assert configuration["final_future"] is final_future

            register.post_register.assert_called_once_with({"lifx.photons": {}})

        it "creates and sets up a task finder":
            final_future = hp.create_future()