當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。