Skip to content

Commit

Permalink
tests: migrate to more verbose and colorized reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
vsergeev committed May 29, 2020
1 parent d856f41 commit acb9ff5
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 435 deletions.
12 changes: 0 additions & 12 deletions tests/asserts.py

This file was deleted.

42 changes: 42 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import inspect


STR_OKAY = " [\x1b[1;32m OK \x1b[0m]"
STR_FAIL = " [\x1b[1;31mFAIL\x1b[0m]"


def ptest():
frame = inspect.stack()[1]
function, lineno = frame[3], frame[2]
print("\n\nStarting test {:s}():{:d}".format(function, lineno))


def pokay(msg):
print("{:s} {:s}".format(STR_OKAY, msg))


def passert(name, condition):
frame = inspect.stack()[1]
filename, function, lineno = frame[1].split('/')[-1], frame[3], frame[2]
print("{:s} {:s} {:s}():{:d} {:s}".format(STR_OKAY if condition else STR_FAIL, filename, function, lineno, name))
assert condition


class AssertRaises(object):
def __init__(self, name, exception_type):
self.name = name
self.exception_type = exception_type

def __enter__(self):
return self

def __exit__(self, t, value, traceback):
frame = inspect.stack()[1]
filename, function, lineno = frame[1].split('/')[-1], frame[3], frame[2]

if not isinstance(value, self.exception_type):
print("{:s} {:s} {:s}():{:d} {:s}".format(STR_FAIL, filename, function, lineno, self.name))
return False

print("{:s} {:s} {:s}():{:d} {:s}".format(STR_OKAY, filename, function, lineno, self.name))
return True
Loading

0 comments on commit acb9ff5

Please sign in to comment.