Fix tests logic

Some tests had assertTrue while it should be assertEqual and move
as much as possible out of the assertRaises contextmanager.