How to use pyrsistent - 10 common examples

To help you get started, we’ve selected a few pyrsistent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github itamarst / eliot / eliot / testing.py View on Github external
def __new__(cls, message):
        return PClass.__new__(cls, message=message)
github tobgu / pyrsistent / tests / performance_run.py View on Github external
# Using ordinary set
    start = time.time()
    m1 = pmap(elements)
    print("Done initializing, time=%s s, count=%s" % (time.time() - start, COUNT))


    start = time.time()
    m2 = pmap()
    for x in test_range():
        m2 = m2.set(x, x)
    print("Done setting, time=%s s, count=%s" % (time.time() - start, COUNT))

    assert m1 == m2

    start = time.time()
    m3 = pmap()
    e3 = m3.evolver()
    for x in test_range():
        e3[x] = x
    m3 = e3.persistent()
    print("Done evolving, time=%s s, count=%s" % (time.time() - start, COUNT))

    assert m3 == m2

    start = time.time()
    m4 = pmap()
    m4 = m4.update(elements)
    m4 = m4.update(elements)
    print("Done updating, time=%s s, count=%s" % (time.time() - start, COUNT))

    assert m4 == m3
github ClusterHQ / flocker / flocker / node / functional / test_deploy.py View on Github external
application_name = random_name(self)

            docker_client = DockerClient()
            self.addCleanup(docker_client.remove, application_name)

            deployer = P2PNodeDeployer(
                u"localhost", volume_service, docker_client,
                node_uuid=uuid4())

            link = Link(alias=u"alias",
                        local_port=80,
                        remote_port=8080)

            dataset = Dataset(
                dataset_id=unicode(uuid4()),
                metadata=pmap({"name": application_name}))
            manifestation = Manifestation(dataset=dataset, primary=True)
            desired_state = Deployment(nodes=frozenset([
                Node(uuid=deployer.node_uuid,
                     applications=frozenset([Application(
                         name=application_name,
                         image=DockerImage.from_string(
                             image_name),
                         links=frozenset([link]),
                         volume=AttachedVolume(
                             manifestation=manifestation,
                             mountpoint=FilePath('/data'),
                         ),
                     )]),
                     manifestations={
                         manifestation.dataset_id: manifestation})]))
github twisted / txaws / txaws / testing / route53.py View on Github external
def get_rrsets(self, zone_id):
        """
        Retrieve all the rrsets that belong to the given zone.

        @param zone_id: The zone to inspect.
        @type zone_id: L{unicode}

        @return: L{None} if the zone is not found.  Otherwise, a L{PMap}
            mapping L{RRSetKey} to L{RRSet}.
        """
        if any(zone.identifier == zone_id for zone in self.zones):
            return self.rrsets.get(zone_id, pmap())
        # You cannot interact with rrsets unless a zone exists.
        return None
github ClusterHQ / flocker / flocker / acceptance / testtools.py View on Github external
def create_attached_volume(dataset_id, mountpoint, maximum_size=None,
                           metadata=pmap()):
    """
    Create an ``AttachedVolume`` instance with the supplied parameters and
    return it.

    :param unicode dataset_id: The unique identifier of the dataset of the
        attached volume.
    :param bytes mountpoint: The path at which the volume is attached.
    :param int maximum_size: An optional maximum size for the volume.

    :return: A new ``AttachedVolume`` instance referencing a primary
        manifestation of a dataset with the given unique identifier.
    """
    return AttachedVolume(
        manifestation=Manifestation(
            dataset=Dataset(
                dataset_id=dataset_id,
github tobgu / pyrsistent / tests / performance_run.py View on Github external
COUNT = 100000
    def test_range():
        prime = 317
        return range(0, prime*COUNT, prime)

    elements = {x: x for x in test_range()}

    # Using ordinary set
    start = time.time()
    m1 = pmap(elements)
    print("Done initializing, time=%s s, count=%s" % (time.time() - start, COUNT))


    start = time.time()
    m2 = pmap()
    for x in test_range():
        m2 = m2.set(x, x)
    print("Done setting, time=%s s, count=%s" % (time.time() - start, COUNT))

    assert m1 == m2

    start = time.time()
    m3 = pmap()
    e3 = m3.evolver()
    for x in test_range():
        e3[x] = x
    m3 = e3.persistent()
    print("Done evolving, time=%s s, count=%s" % (time.time() - start, COUNT))

    assert m3 == m2
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / workflows / test_init.py View on Github external
def test_add_meta_with_defaults(self, registry, mock_meta):
        from pyrsistent import freeze
        standard_meta = freeze(mock_meta.return_value)\
            .transform(['states', 'draft', 'acm', 'principals'], ['role:moderator'])
        registry.content.workflows_meta['standard'] = standard_meta
        mock_meta.return_value = {'defaults': 'standard'}
        self.call_fut(registry, 'package:dummy.yaml', 'dummy')
        meta = registry.content.workflows_meta['dummy']
        assert meta['states'] == standard_meta['states']
        assert meta['transitions'] == standard_meta['transitions']
        assert meta['initial_state'] == standard_meta['initial_state']
        assert meta['defaults'] == 'standard'
github tobgu / pyrsistent / tests / test_transform.py View on Github external
def test_new_elements_created_when_missing():
    m = freeze({})
    assert m.transform(['foo', 'bar', 'baz'], 7) == {'foo': {'bar': {'baz': 7}}}
github tobgu / pyrsistent / tests / test_transform.py View on Github external
def test_multiple_transformations():
    v = freeze([1, 2])
    assert v.transform([2, 'foo'], 3, [2, 'foo'], inc) == freeze([1, 2, {'foo': 4}])
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / workflows / test_init.py View on Github external
def test_add_meta_with_defaults_state_add_permission(self, registry,
                                                         mock_meta):
        from pyrsistent import freeze
        standard_meta = freeze(mock_meta.return_value)\
            .transform(['states', 'draft', 'acm', 'principals'], ['role:moderator'])
        registry.content.workflows_meta['standard'] = standard_meta
        mock_meta.return_value =\
            {'defaults': 'standard',
             'states': {'draft': {'acm': {'permissions':[['new', 'Added']]}}
             }}
        self.call_fut(registry, 'package:dummy.yaml', 'dummy')
        meta = registry.content.workflows_meta['dummy']
        assert meta['states']['draft']['acm']['permissions'] ==\
               [['view', 'Deny'],
                ['new', 'Added']]