Don't make ExpectedRequest orderable

Instead, make it hashable and use collections.Counter instead of sorted
lists. This actually produces a nicer output for differences between
the counters.
This commit is contained in:
Daniel Schadt 2015-11-21 00:20:09 +01:00
parent c12011c84d
commit c7294781f5
2 changed files with 6 additions and 9 deletions

View File

@ -22,6 +22,7 @@
import os
import re
import os.path
import collections
import pytest
@ -102,7 +103,8 @@ def test_mhtml(test_name, download_dir, quteproc, httpbin):
expected_requests.append(httpbin.ExpectedRequest('GET', path))
actual_requests = httpbin.get_requests()
# Requests are unorderable, we need to convert to ExpectedRequests
# Requests are not hashable, we need to convert to ExpectedRequests
actual_requests = map(httpbin.ExpectedRequest.from_request,
actual_requests)
assert sorted(actual_requests) == sorted(expected_requests)
assert (collections.Counter(actual_requests) ==
collections.Counter(expected_requests))

View File

@ -26,7 +26,6 @@ import re
import sys
import socket
import os.path
import functools
import pytest
from PyQt5.QtCore import pyqtSignal
@ -90,7 +89,6 @@ class Request(testprocess.Line):
return NotImplemented
@functools.total_ordering
class ExpectedRequest:
"""Class to compare expected requests easily."""
@ -111,11 +109,8 @@ class ExpectedRequest:
else:
return NotImplemented
def __lt__(self, other):
if isinstance(other, (Request, ExpectedRequest)):
return (self.verb, self.path) < (other.verb, other.path)
else:
return NotImplemented
def __hash__(self):
return hash(('ExpectedRequest', self.verb, self.path))
def __repr__(self):
return ('ExpectedRequest(verb={!r}, path={!r})'