1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# -*- coding: utf-8 -*-
# preggy assertions
# https://github.com/heynemann/preggy
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2013 Bernardo Heynemann heynemann@gmail.com
from preggy import expect
from tests import Comparable
#-----------------------------------------------------------------------------
class FakeClass(object): pass
class Other(FakeClass): pass
class Another(FakeClass, Comparable): pass
TEST_DATA = frozenset([
FakeClass,
FakeClass(),
Other,
Other(),
Another,
Another()
])
#-----------------------------------------------------------------------------
def is_expected(item):
expect(item).to_be_instance_of(FakeClass)
try:
expect(item).not_to_be_instance_of(FakeClass)
except AssertionError:
return
assert False, 'Should not have gotten this far'
def is_not_expected(item):
expect(item).Not.to_be_instance_of(dict)
expect(item).not_to_be_instance_of(dict)
try:
expect(item).to_be_instance_of(dict)
except AssertionError:
return
assert False, 'Should not have gotten this far'
#-----------------------------------------------------------------------------
def test_to_be_instance_of():
for item in TEST_DATA:
is_expected(item)
def test_not_to_be_instance_of():
for item in TEST_DATA:
is_not_expected(item)
|