当前位置: 首页>>代码示例>>Python>>正文


Python orderedcollection.OrderedCollection类代码示例

本文整理汇总了Python中gnome.utilities.orderedcollection.OrderedCollection的典型用法代码示例。如果您正苦于以下问题:Python OrderedCollection类的具体用法?Python OrderedCollection怎么用?Python OrderedCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OrderedCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_callback

    def test_remove_callback(self):
        "test remove callback is invoked after removing an object"

        oc = OrderedCollection(dtype=ObjToAdd)  # lets work with a mutable type
        oc.register_callback(self._rm_callback, events="remove")
        oc.register_callback(self._add_callback, events="add")

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add

        del oc[s_id(self.to_add[0])]

        assert self.to_add[0].rm_callback
        assert self.to_add[0].add_callback
        assert not self.to_add[0].replace_callback

        self.to_add[0].reset()  # reset all to false
        oc += self.to_add[0]  # let's add this back in

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:26,代码来源:test_ordered_collection.py

示例2: test_add_replace_callback

    def test_add_replace_callback(self):
        "register one callback with multiple events (add, replace)"

        # lets work with a mutable type

        oc = OrderedCollection(dtype=ObjToAdd)
        oc.register_callback(self._add_callback, events=("add", "replace"))

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback

        rep = ObjToAdd()
        oc[s_id(self.to_add[0])] = rep

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:26,代码来源:test_ordered_collection.py

示例3: test_index

 def test_index(self):
     oc = OrderedCollection([1, 2, 3, 4, 5])
     assert oc.index(id(3)) == 2
     oc[id(3)] = 6
     assert oc.index(id(6)) == 2
     del oc[id(6)]
     assert oc.index(id(4)) == 2
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:7,代码来源:test_ordered_collection.py

示例4: __restore__

    def __restore__(self, time_step, start_time, duration, weathering_substeps, map, uncertain, cache_enabled):
        """
        Take out initialization that does not register the callback here.
        This is because new_from_dict will use this to restore the model _state
        when doing a midrun persistence.
        """

        # making sure basic stuff is in place before properties are set
        self.environment = OrderedCollection(dtype=Environment)
        self.movers = OrderedCollection(dtype=Mover)
        self.weatherers = OrderedCollection(dtype=Weatherer)

        # contains both certain/uncertain spills
        self.spills = SpillContainerPair(uncertain)

        self._cache = gnome.utilities.cache.ElementCache()
        self._cache.enabled = cache_enabled

        # list of output objects
        self.outputters = OrderedCollection(dtype=Outputter)

        # default to now, rounded to the nearest hour
        self._start_time = start_time
        self._duration = duration
        self.weathering_substeps = weathering_substeps
        self._map = map
        self.time_step = time_step  # this calls rewind() !
开发者ID:kthyng,项目名称:GNOME2,代码行数:27,代码来源:model.py

示例5: test_values

def test_values():
    'OrderedCollection().values() works like a dict.values()'
    x = range(5)
    oc = OrderedCollection(x)
    del x[-2]
    del oc[-2]
    for ix, v in enumerate(oc.values()):
        assert x[ix] == v
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:8,代码来源:test_ordered_collection.py

示例6: test_remake

def test_remake():
    'delete automatically remakes internal lists without None'
    oc = OrderedCollection(['p', 'q', 'ab', 'adsf', 'ss'])
    del oc[0]
    del oc[2]
    oc.remake()
    for ix, elem in enumerate(oc._elems):
        assert elem is not None
        assert oc._d_index[s_id(elem)] == ix
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:9,代码来源:test_ordered_collection.py

示例7: test_remake

def test_remake():
    "remakes internal lists without None enteries"
    oc = OrderedCollection(["p", "q", "ab", "adsf", "ss"])
    del oc[0]
    del oc[3]
    assert oc._elems[0] is None
    assert oc._elems[3] is None
    oc.remake()
    for ix, elem in enumerate(oc._elems):
        assert elem is not None
        assert oc._index[s_id(elem)] == ix
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:11,代码来源:test_ordered_collection.py

示例8: test_clear

def test_clear():
    'test clear()'
    oc = OrderedCollection(range(4))
    oc.clear()

    assert len(oc) == 0
    assert oc._elems == []   # there should be no None's
    assert oc._d_index == {}
    assert oc.dtype is int
    with raises(TypeError):
        oc += 1.0
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:11,代码来源:test_ordered_collection.py

示例9: test_int_to_dict

    def test_int_to_dict(self):
        '''added a to_dict() method - test this method for int dtype.
        Tests the try, except is working correctly'''
        items = range(5)
        oc = OrderedCollection(items)
        dict_ = oc.to_dict()

        assert dict_['dtype'] == int
        for (i, item) in enumerate(items):
            assert dict_['items'][i][0] \
                == '{0}'.format(item.__class__.__name__)
            assert dict_['items'][i][1] == i
开发者ID:kthyng,项目名称:GNOME2,代码行数:12,代码来源:test_ordered_collection.py

示例10: test_add

 def test_add(self):
     oc = OrderedCollection([1, 2, 3, 4, 5])
     oc.add(6)
     assert [i for i in oc] == [
         1,
         2,
         3,
         4,
         5,
         6,
         ]
     with pytest.raises(TypeError):
         oc.add('not an int')
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:13,代码来源:test_ordered_collection.py

示例11: test_to_dict

    def test_to_dict(self):
        'added a to_dict() method - test this method'

        items = [SimpleMover(velocity=(i * 0.5, -1.0, 0.0)) for i in
                 range(2)]
        items.extend([RandomMover() for i in range(2)])
        mymovers = OrderedCollection(items, dtype=Mover)
        dict_ = mymovers.to_dict()

        assert dict_['dtype'] == mymovers.dtype
        for (i, mv) in enumerate(items):
            assert dict_['items'][i][0] \
                == '{0}.{1}'.format(mv.__module__, mv.__class__.__name__)
            assert dict_['items'][i][1] == i
开发者ID:kthyng,项目名称:GNOME2,代码行数:14,代码来源:test_ordered_collection.py

示例12: test_replace

    def test_replace(self):
        oc = OrderedCollection([1, 2, 3, 4, 5])
        oc.replace(id(6), 6)
        assert [i for i in oc] == [
            1,
            2,
            3,
            4,
            5,
            6,
            ]
        oc.replace(id(4), 7)
        assert [i for i in oc] == [
            1,
            2,
            3,
            7,
            5,
            6,
            ]
        assert oc[id(7)] == 7
        with pytest.raises(KeyError):

            # our key should also be gone after the delete

            oc[id(4)]
        with pytest.raises(TypeError):
            oc.replace(id(7), 'not an int')
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:28,代码来源:test_ordered_collection.py

示例13: test_remove

    def test_remove(self):
        oc = OrderedCollection([1, 2, 3, 4, 5])
        with raises(KeyError):
            oc.remove(s_id(6))
        oc.remove(s_id(4))
        assert [i for i in oc] == [1, 2, 3, 5]

        oc.remove(2)
        assert [i for i in oc] == [1, 2, 5]
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:9,代码来源:test_ordered_collection.py

示例14: __init__

    def __init__(self, uncertain=False):
        super(SpillContainer, self).__init__(uncertain=uncertain)
        self.spills = OrderedCollection(dtype=gnome.spill.Spill)
        self.rewind()

        # don't want user to add to array_types in middle of run. Since its
        # not possible to throw an error in this case, let's just make it a
        # bit difficult to do.
        # dict must be updated via prepar_for_model_run() only at beginning of
        # run. Make self._array_types an an instance variable
        self._reset_arrays()
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:11,代码来源:spill_container.py

示例15: test_add_callback

    def test_add_callback(self):
        '''
            test add callback is invoked after adding an object or
            list of objects
        '''

        # lets work with a mutable type
        oc = OrderedCollection(dtype=ObjToAdd)
        oc.register_callback(self._add_callback, events='add')

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add
        oc += ObjToAdd()

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:21,代码来源:test_ordered_collection.py


注:本文中的gnome.utilities.orderedcollection.OrderedCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。