Skip to content

Instantly share code, notes, and snippets.

@hayd
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayd/c9246c15652e5eb3b90b to your computer and use it in GitHub Desktop.
Save hayd/c9246c15652e5eb3b90b to your computer and use it in GitHub Desktop.
Extracting counts of test failures
nosetests 2> nose_output.log
# prints counts of exceptions from output of nose
from collections import Counter, deque
import re
def last_exception_line(chunk):
d = deque(maxlen=1)
d.extend(line for line in chunk.splitlines() if startswith_exception(line))
return d[0] # what to do if empty?
def startswith_exception(line):
return re.match("[^\s]*Error", line)
def get_exceptions(nose_output_filename):
with open(nose_output_filename) as f:
nose_output = f.read()
lst = nose_output.split("======================================================================")
# first chunk is junk ...S....E...
# last chunk is summary
lst = lst[1:-1]
return Counter(last_exception_line(chunk) for chunk in lst)
def print_most_common(counter, N=10):
for message, count in counter.most_common(N):
print("%3d %s" % (count, message))
# usage
exceptions = get_exceptions("nose_output.log")
print_most_common(exceptions, 3)
# 11 pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
# 2 TypeError: 'str' does not support the buffer interface
# 1 TypeError: sequence item 0: expected str instance, bytes found
EFE...F..E.......F..E.S..SSSSSSSSSSSSSSSSSEEEEEEEEEEEES....F..E.E...
======================================================================
ERROR: test_csv (test_db.TestCSV)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 905, in test_csv
v.save("test.csv", headers=True)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 1921, in save
w.writerows([[csv_header_encode(name, type) for name, type in self.fields]])
TypeError: 'str' does not support the buffer interface
======================================================================
ERROR: test_file (test_db.TestCSV)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 918, in test_file
v.save("test.csv", headers=True)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 1921, in save
w.writerows([[csv_header_encode(name, type) for name, type in self.fields]])
TypeError: 'str' does not support the buffer interface
======================================================================
ERROR: test_copy (test_db.TestDatasheet)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 1043, in test_copy
self.assertTrue(v.copy(rows=[0], columns=[0]), [[1]])
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 2222, in copy
return Datasheet(rows=(z[i] for i in rows))
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 2007, in __init__
CSV.__init__(self, rows, fields, **kwargs)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 1895, in __init__
self.extend(rows, **kwargs)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 2139, in extend
for row in rows:
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 2222, in <genexpr>
return Datasheet(rows=(z[i] for i in rows))
TypeError: 'zip' object is not subscriptable
======================================================================
ERROR: test_format (test_db.TestDate)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 174, in test_format
self.assertRaises(ValueError, lambda: v.timestamp)
File "/Users/andy/anaconda/envs/py34/lib/python3.4/unittest/case.py", line 704, in assertRaises
return context.handle('assertRaises', callableObj, args, kwargs)
File "/Users/andy/anaconda/envs/py34/lib/python3.4/unittest/case.py", line 162, in handle
callable_obj(*args, **kwargs)
File "/Users/andy/pattern/test/test_db.py", line 174, in <lambda>
self.assertRaises(ValueError, lambda: v.timestamp)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 152, in timestamp
return int(mktime(self.timetuple())) # Seconds elapsed since 1/1/1970.
OverflowError: mktime argument out of range
======================================================================
ERROR: test_abs (test_db.TestSQLiteQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 815, in setUp
AbstractTestQuery.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 636, in setUp
self.db.persons.insert(name="john", age="30", gender=2)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 1144, in insert
v = ", ".join(self.db.escape(v) for v in kwargs.values())
TypeError: sequence item 0: expected str instance, bytes found
======================================================================
ERROR: test_cmp (test_db.TestSQLiteQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 815, in setUp
AbstractTestQuery.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 629, in setUp
db.field("gender", db.INTEGER)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_filterchain (test_db.TestSQLiteQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 815, in setUp
AbstractTestQuery.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 629, in setUp
db.field("gender", db.INTEGER)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_query (test_db.TestSQLiteQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 815, in setUp
AbstractTestQuery.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 629, in setUp
db.field("gender", db.INTEGER)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_xml (test_db.TestSQLiteQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 815, in setUp
AbstractTestQuery.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 629, in setUp
db.field("gender", db.INTEGER)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_datasheet (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_fields (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_filter (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_insert_update_delete (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_rename (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_search (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_table (test_db.TestSQLiteTable)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 613, in setUp
AbstractTestTable.setUp(self)
File "/Users/andy/pattern/test/test_db.py", line 484, in setUp
db.field("name", db.STRING)
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 762, in create
raise TableError("table '%s' already exists" % (self.name + "." + table))
pattern.db.TableError: table 'pattern_unittest_db.persons' already exists
======================================================================
ERROR: test_encryption (test_db.TestUtilityFunctions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 329, in encrypt_string
try: a.append(chr(ord(s[i]) + ord(key[i % len(key)]) % 256))
TypeError: ord() expected string of length 1, but int found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 207, in test_encryption
v2 = db.encrypt_string(v1, key="1234")
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 331, in encrypt_string
raise EncryptionError()
pattern.db.EncryptionError
======================================================================
ERROR: test_order (test_db.TestUtilityFunctions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 226, in test_order
self.assertEqual(db.order(v), [1,2,0])
File "/Users/andy/pattern/test/../pattern/db/__init__.py", line 472, in order
return sorted(range(len(list)), cmp=f, reverse=reverse)
TypeError: 'cmp' is an invalid keyword argument for this function
======================================================================
FAIL: test_csv_header (test_db.TestCSV)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 897, in test_csv_header
self.assertEqual(v1, "age (INTEGER)")
AssertionError: "b'age' (INTEGER)" != 'age (INTEGER)'
- b'age' (INTEGER)
? -- -
+ age (INTEGER)
======================================================================
FAIL: test_escape (test_db.TestCreateSQLiteDatabase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 298, in test_escape
self.assertEqual(db._escape(v), s)
AssertionError: b'a' != "'a'"
======================================================================
FAIL: test_slice (test_db.TestDatasheet)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 1034, in test_slice
self.assertTrue(isinstance(v[0:2], db.Datasheet))
AssertionError: False is not true
======================================================================
FAIL: test_encode_utf8 (test_db.TestUnicode)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andy/pattern/test/test_db.py", line 71, in test_encode_utf8
self.assertTrue(isinstance(db.encode_utf8(s), str))
AssertionError: False is not true
----------------------------------------------------------------------
Ran 68 tests in 0.149s
FAILED (SKIP=19, errors=18, failures=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment