Fix assertRaises when the exception has a metaclass

Due to not taking into account that the type of the class can be a
subclass of type (which is the case when using metaclasses),
assertRaises would report a false positive in case an exception that was
expected had a custom metaclass.

This patch introduces a more robust checking if a given object is a
class or an instance of one, and adds a test case, to make sure
exceptions with custom metaclasses don't break assertRaises.