Skip to content

Commit

Permalink
sanest.wrap() is no longer public api
Browse files Browse the repository at this point in the history
...since it encourages bad coding practices: "i have no idea whether
this is a dict or a list" will typically lead to either a bug or a
type check in the calling code, so there is not much point encouraging this.
  • Loading branch information
wbolster committed Jun 26, 2017
1 parent 27ad4a5 commit 710f66b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/sanest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .sanest import ( # noqa: F401
dict,
list,
wrap,
DataError,
InvalidPathError,
InvalidStructureError,
Expand Down
14 changes: 7 additions & 7 deletions test_sanest.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,18 +903,18 @@ def test_dict_validate_assigned_values():

def test_dict_wrap_validation():
with pytest.raises(sanest.InvalidPathError) as excinfo:
sanest.wrap({123: True})
sanest.dict.wrap({123: True})
assert str(excinfo.value) == (
"invalid dict key: 123")

with pytest.raises(sanest.InvalidValueError) as excinfo:
sanest.wrap({"foo": MyClass()})
sanest.dict.wrap({"foo": MyClass()})
assert str(excinfo.value) == "invalid value of type MyClass: <MyClass>"


def test_dict_wrap_skip_validation():
invalid_dict = {True: False}
wrapped = sanest.wrap(invalid_dict, check=False)
wrapped = sanest.dict.wrap(invalid_dict, check=False)
unwrapped = wrapped.unwrap()
assert unwrapped is invalid_dict

Expand Down Expand Up @@ -1545,7 +1545,7 @@ def test_list_set_slice():
l[:] = ['p', 'q', 'r']
assert l == ['p', 'q', 'r']
with pytest.raises(sanest.InvalidValueError) as excinfo:
sanest.wrap([MyClass()])
l[:3] = [MyClass()]
assert str(excinfo.value) == "invalid value of type MyClass: <MyClass>"
assert l == ['p', 'q', 'r']
l[:2] = sanest.list([{}, []])
Expand All @@ -1572,12 +1572,12 @@ def test_list_del_slice():


def test_wrap():
l = sanest.wrap([1, 2])
l = _sanest.list.wrap([1, 2])
assert isinstance(l, sanest.list)
d = sanest.wrap({'a': 1})
d = _sanest.wrap({'a': 1})
assert isinstance(d, sanest.dict)
with pytest.raises(TypeError) as excinfo:
sanest.wrap(MyClass())
_sanest.wrap(MyClass())
assert str(excinfo.value) == "not a dict or list: <MyClass>"


Expand Down

0 comments on commit 710f66b

Please sign in to comment.