Last active
August 27, 2017 15:06
-
-
Save pluto-atom-4/1c5c8337f0c70884f5186c9f346b168e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .test_list import TextsToBeInspect | |
def pytest_assertrepr_compare(op, left, right): | |
def details(*args): | |
details = [] | |
details.append('----') | |
for i in args: | |
details.append('%s: ' % i.context) | |
details.extend([' %s' % i for i in i.texts]) | |
return details | |
def unmatched(left, right): | |
unmatched = [] | |
unmatched.append('--- unmatched ---') | |
for value in right.texts: | |
if value.startswith('invalid.data.'): | |
continue | |
if left.texts[right.texts.index(value)] != value: | |
unmatched.append('%s: %s: ' % (left.context, left.texts[right.texts.index(value)])) | |
unmatched.append('%s: %s: ' % (right.context, value)) | |
return unmatched | |
explanation = [] | |
if isinstance(left, TextsToBeInspect) and isinstance(right, TextsToBeInspect) and op == "==": | |
explanation.append('Comparing TextsToBeInspect instances: ') | |
explanation.extend(unmatched(left, right)) | |
explanation.extend(details(left, right)) | |
return explanation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def runtests(args=None): | |
import pytest | |
result = pytest.main(['-vv', 'test_list.py', 'test_time.py']) | |
sys.exit(result) | |
runtests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pprint | |
class TextsToBeInspect(object): | |
def __init__(self, context, texts): | |
self.context = context[:] | |
self.texts = texts[:] | |
def __eq__(self, other): | |
if not isinstance(other, TextsToBeInspect): | |
return 0 | |
unmatched_found = False | |
for value in other.texts: | |
if value.startswith('invalid.data.'): | |
continue | |
if self.texts[other.texts.index(value)] != value: | |
unmatched_found = True | |
if unmatched_found: | |
return 0 | |
return 1 | |
def texts(self): | |
return self.texts[:] | |
def context(self): | |
return self.context[:] | |
def pretty_print(self): | |
print("\ncontext => {}".format(self.context)) | |
pp.pprint(self.texts) | |
texts_expect = [ | |
"invalid.data.aaaaaaaaaaaaaaaaaaaaaaaaaaa", | |
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | |
"cccccccccccccccccccccccccccccccccccccccc", | |
"invalid.data.ddddddddddddddddddddddddddd", | |
] | |
texts_actual = [ | |
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | |
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | |
"cccccccccccccccccccccccccccccccccccccccERROR", | |
"dddddddddddddddddddddddddddddddddddddddd", | |
] | |
pp = pprint.PrettyPrinter(indent=4) | |
__tracebackhide__ = True | |
def test_list(): | |
actual = TextsToBeInspect("actual", texts_actual) | |
expect = TextsToBeInspect("expect", texts_expect) | |
assert actual == expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment