def test_multiset_change(counter_type): ent1 = FeatureCollection() ent1['bow'] += counter_type(Counter(['big', 'dog'])) ent1.pop('bow') assert dict(ent1.items()) == dict() ## can pop empty -- fails #ent1.pop('foo') ## set equal to test_data = ['big2', 'dog2'] ent1['bow'] = counter_type(Counter(test_data)) assert list(map(abs,ent1['bow'].values())) == [1,1] ent1['bow'] += counter_type(Counter(test_data)) assert list(map(abs,ent1['bow'].values())) == [2,2]
def test_read_only(): fcwork = FeatureCollection({'feat': {'foo': 1}}) fc = FeatureCollection() fc['feat']['foo'] += 1 fc.read_only = True with pytest.raises(ReadOnlyException): fc += fcwork with pytest.raises(ReadOnlyException): fc -= fcwork with pytest.raises(ReadOnlyException): fc -= fcwork with pytest.raises(ReadOnlyException): del fc['feat'] with pytest.raises(ReadOnlyException): fc.pop('feat')