-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model.Object is the dict with deprecation warnings class.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Fiona data model""" | ||
|
||
from collections.abc import MutableMapping | ||
from warnings import warn | ||
|
||
from fiona.errors import FionaDeprecationWarning | ||
|
||
|
||
class Object(MutableMapping): | ||
|
||
def __init__(self, **data): | ||
self._data = data.copy() | ||
|
||
def __getitem__(self, item): | ||
return self._data[item] | ||
|
||
def __iter__(self): | ||
return iter(self._data) | ||
|
||
def __len__(self): | ||
return len(self._data) | ||
|
||
def __setitem__(self, key, value): | ||
warn("Object will become immutable in version 2.0", FionaDeprecationWarning, stacklevel=2) | ||
self._data[key] = value | ||
|
||
def __delitem__(self, key): | ||
warn("Object will become immutable in version 2.0", FionaDeprecationWarning, stacklevel=2) | ||
del self._data[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Test of deprecations following RFC 1""" | ||
|
||
import pytest | ||
|
||
from fiona.errors import FionaDeprecationWarning | ||
from fiona.model import Object | ||
|
||
|
||
def test_setitem_warning(): | ||
"""Warn about __setitem__""" | ||
obj = Object() | ||
with pytest.warns(FionaDeprecationWarning): | ||
obj['g'] = 1 | ||
assert obj['g'] == 1 | ||
|
||
|
||
def test_delitem_warning(): | ||
"""Warn about __delitem__""" | ||
obj = Object(g=1) | ||
with pytest.warns(FionaDeprecationWarning): | ||
del obj['g'] | ||
assert 'g' not in obj |