Skip to content

Commit 5f66551

Browse files
Extended tests to check consistency of __eq__ and __hash__
1 parent 0b42803 commit 5f66551

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

dpctl/tests/test_sycl_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test_context_not_equals():
7676
except ValueError:
7777
pytest.skip()
7878
assert ctx_cpu != ctx_gpu
79+
assert hash(ctx_cpu) != hash(ctx_gpu)
7980

8081

8182
def test_context_not_equals2():
@@ -94,6 +95,7 @@ def test_context_equals():
9495
except ValueError:
9596
pytest.skip()
9697
assert ctx0 == ctx1
98+
assert hash(ctx0) == hash(ctx1)
9799

98100

99101
def test_name():

dpctl/tests/test_sycl_device.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ def test_filter_string_property():
615615
dev_id = d.filter_string
616616
d_r = dpctl.SyclDevice(dev_id)
617617
assert d == d_r
618+
assert hash(d) == hash(d_r)
618619

619620

620621
def test_filter_string_method():
@@ -631,6 +632,9 @@ def test_filter_string_method():
631632
)
632633
d_r = dpctl.SyclDevice(dev_id)
633634
assert d == d_r, "Failed "
635+
assert hash(d) == hash(
636+
d_r
637+
), "Hash equality is inconsistent with __eq__"
634638

635639

636640
def test_hashing_of_device():

dpctl/tests/test_sycl_queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def test_context_not_equals():
358358
pytest.skip()
359359
ctx_cpu = cpuQ.get_sycl_context()
360360
assert ctx_cpu != ctx_gpu
361+
assert hash(ctx_cpu) != hash(ctx_gpu)
361362

362363

363364
def test_context_equals():
@@ -369,6 +370,7 @@ def test_context_equals():
369370
ctx0 = gpuQ0.get_sycl_context()
370371
ctx1 = gpuQ1.get_sycl_context()
371372
assert ctx0 == ctx1
373+
assert hash(ctx0) == hash(ctx1)
372374

373375

374376
def test_hashing_of_queue():

0 commit comments

Comments
 (0)