Exemplo n.º 1
0
def test_auto_fields_other_sentinel():
    other_sentinel = sentinel.create("other_sentinel")

    class User(pydantic.BaseModel):
        age: int
        password: Optional[str]
        other: int

    @strawberry.experimental.pydantic.type(User)
    class UserType:
        age: strawberry.auto
        password: strawberry.auto
        other: other_sentinel  # this should be a private field, not an auto field

    definition: TypeDefinition = UserType._type_definition
    assert definition.name == "UserType"

    [field1, field2, field3] = definition.fields

    assert field1.python_name == "age"
    assert field1.graphql_name is None
    assert field1.type is int

    assert field2.python_name == "other"
    assert field2.graphql_name is None
    assert field2.type is other_sentinel

    assert field3.python_name == "password"
    assert field3.graphql_name is None
    assert isinstance(field3.type, StrawberryOptional)
    assert field3.type.of_type is str
Exemplo n.º 2
0
    'iter_subclasses',
    'get_subclasses',
    'get_attributes',
    'get_abstract_method_names',
    'safe_is_subclass',
    'iter_slots',
    'get_slot_names',
    'get_slot_counts',
    'get_slots',
    'get_implicit_method_type',
    'fit_to_class',
    'add_method_to_class',
    'wrap_method',
]

auto = sentinel.create('auto')


def iter_subclasses(cls: type,
                    include_abstract: bool = False) -> Iterator[type]:
    """
    Yields subclasses of the given class.
    
    .. versionadded:: 1.5

    :param cls: A base class
    :param include_abstract: Whether abstract base classes should be included
    :return: An iterator yielding subclasses
    """
    seen = set()
    queue = cls.__subclasses__()
 def test_init(self):
     tabs_path = sentinel.create('tabs_path')
     file_list_path = sentinel.create('file_list_path')
     generator = TabBookGenerator(tabs_path, file_list_path)
     assert tabs_path == generator.tabs_path
     assert file_list_path == generator.file_list_path
Exemplo n.º 4
0
"""Datastructures for representing the resources available in a machine when
performing placement, allocation and routing.
"""

from rig.links import Links

import sentinel

Cores = sentinel.create("Cores")
"""Resource identifier for (monitor and application) processor cores.

Note that this identifier does not trigger any kind of special-case behaviour
in library functions. Users are free to define their own alternatives.

In early versions of Rig this object was called ``rig.machine.Cores``.
"""

SDRAM = sentinel.create("SDRAM")
"""Resource identifier for shared off-die SDRAM (in bytes).

Note that this identifier does not trigger any kind of special-case behaviour
in library functions. Users are free to define their own alternatives.

.. note::

    In early versions of Rig this object was called ``rig.machine.SDRAM``.
"""

SRAM = sentinel.create("SRAM")
"""Resource identifier for shared on-die SRAM (in bytes).
Exemplo n.º 5
0
import functools
import sentinel

__names__ = [
    "NoValue",
    "Value",
    "value_list",
    "value_tuple",
    "value_dict",
    "ensure_value",
    "make_instantaneous",
    "make_persistent",
]

NoValue = sentinel.create("NoValue")
"""
A special value indicating that a ``yarp`` value has not been assigned a value.
"""


class Value(object):
    """
    A continuous or instantaneous value which can be read and set.
    
    This base class defines the fundamental type in ``yarp``: the 'value'.
    
    The actual data contained by this object should be regarded as immutable
    with changes being made by replacing the Python object with a new one to
    affect changes.
    """
Exemplo n.º 6
0
import sentinel

auto = sentinel.create("auto")
Exemplo n.º 7
0
This module provides decorators for functions so that they can use contextual
arguments and a mixin for classes that provides a `get_new_context` method
which could be mapped to `__call__` to produce and use concepts as in the
previous example.

This module was originally developed as part of Rig (https://github.com/project-rig/rig)
and was developed by Andrew Mundy ([email protected])
"""
import collections
import inspect
import functools
import sentinel
from six import iteritems

Required = sentinel.create('Required')
"""Allow specifying keyword arguments as required, i.e., they must be satisfied
by either the context OR by the caller.

This is useful when a method has optional parameters and contextual arguments::

    @ContextMixin.use_contextual_arguments()
    def sdram_alloc(self, size, tag=0, x=Required, y=Required):
        # ...

And also when using non-default keyword-only are required::

    @ContextMixin.use_contextual_arguments(app_id=Required)
    def example(*args, **kwargs):
        app_id = kwargs.pop(app_id)  # Must always be given
        # ...
Exemplo n.º 8
0
import itertools
import os
import sentinel
import sys
import time

from multiprocessing import Queue


_pid = None
_qout = Queue(maxsize=1000)
_processes = 0

EndOfQueue = "End of queue"
FeederThread = sentinel.create('FeederThread')
ConsumerThread = sentinel.create('ConsumerThread')


def log(task, item):
    if False:
        print "[{pid}] [{task}]: {item}".format(pid=_pid,
                                                task=task,
                                                item=item)


def split(data, processes):
    '''
    Fork off a number of processes. The data processing will be split
    among those processes.
Exemplo n.º 9
0
#!/usr/bin/env python

import sentinel
"""
TODO: Turn this into test suite.
TODO: pickling test
TODO: copy() and deepcopy() tests
"""

Leaf = sentinel.create('Leaf',
                       extra_methods={'is_leaf': property(lambda self: True)})


class Node(object):
    def __init__(self, payload, left=Leaf, right=Leaf):
        self.__left = left
        self.__right = right
        # Only non-rewritable attribute.
        self.payload = payload

    left = property(lambda self: self.__left)
    right = property(lambda self: self.__right)

    @property
    def is_leaf(self):
        return False

    def __repr__(self):
        attrs = ('payload', 'left', 'right')
        props = ('%s=%r' % (attr, getattr(self, attr)) for attr in attrs)
        return 'Node(' + ', '.join(props) + ')'
Exemplo n.º 10
0
import time
import sentinel
from collections import OrderedDict
from datetime import timedelta


class TimeError(Exception):
    """ Custom exception for timer based exceptions """


class StopWatchTimerError(Exception):
    """ Custom  exception for stopwatch based exceptions """


# Sentinels to use as default empty values
Nothing = sentinel.create('Nothing')
Empty = sentinel.create('Empty')


class StopWatchTimer:
    """ Stop Watch class which sort of mimics a stop watch (think apple iphone stop watch).
        With laps and reset
        Usage:

        At initialisation the timer starts, unless you pass defer=True, in which case an 
        instantiaited object exists to be started at your convenience with start()
    """
    def __init__(self, name: str = Empty, defer: bool = False) -> None:
        self.stopped_value: float = 0
        self.defer: bool = defer
        self.stopped: bool = self.defer