Skip to content

Commit 225793b

Browse files
committed
fix dict_hash for None values; add more tests
1 parent 2aaa79d commit 225793b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

scrapy_splash/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def dict_hash(obj, start=''):
4040
value = str(obj)
4141
elif isinstance(obj, (six.text_type, bytes)):
4242
value = obj
43+
elif obj is None:
44+
value = b''
4345
else:
4446
raise ValueError("Unsupported value type: %s" % obj.__class__)
4547
h.update(to_bytes(value))

tests/test_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from hypothesis import given, assume
66
from hypothesis import strategies as st
77
from scrapy.http import Headers
8-
from scrapy_splash.utils import headers_to_scrapy, _fast_hash, json_based_hash
8+
from scrapy_splash.utils import (
9+
headers_to_scrapy,
10+
_fast_hash,
11+
json_based_hash,
12+
dict_hash
13+
)
914

1015

1116
def test_headers_to_scrapy():
@@ -56,6 +61,13 @@ def _dump(v):
5661
assert _fast_hash(val1) != _fast_hash(val2)
5762

5863

64+
@given(_data, _data)
65+
def test_dict_hash(val1, val2):
66+
assume(val1 != val2)
67+
assert dict_hash(val1) == dict_hash(val1)
68+
assert dict_hash(val1) != dict_hash(val2)
69+
70+
5971
@given(_data_notuples, _data_notuples)
6072
def test_json_based_hash(val1, val2):
6173
assume(val1 != val2)

0 commit comments

Comments
 (0)