Skip to content

Commit

Permalink
fix dict_hash for None values; add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Jan 18, 2018
1 parent 2aaa79d commit 225793b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scrapy_splash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def dict_hash(obj, start=''):
value = str(obj)
elif isinstance(obj, (six.text_type, bytes)):
value = obj
elif obj is None:
value = b''
else:
raise ValueError("Unsupported value type: %s" % obj.__class__)
h.update(to_bytes(value))
Expand Down
14 changes: 13 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from hypothesis import given, assume
from hypothesis import strategies as st
from scrapy.http import Headers
from scrapy_splash.utils import headers_to_scrapy, _fast_hash, json_based_hash
from scrapy_splash.utils import (
headers_to_scrapy,
_fast_hash,
json_based_hash,
dict_hash
)


def test_headers_to_scrapy():
Expand Down Expand Up @@ -56,6 +61,13 @@ def _dump(v):
assert _fast_hash(val1) != _fast_hash(val2)


@given(_data, _data)
def test_dict_hash(val1, val2):
assume(val1 != val2)
assert dict_hash(val1) == dict_hash(val1)
assert dict_hash(val1) != dict_hash(val2)


@given(_data_notuples, _data_notuples)
def test_json_based_hash(val1, val2):
assume(val1 != val2)
Expand Down

0 comments on commit 225793b

Please sign in to comment.