8000 is_type_of and is_instance_of support for ABC/Metaclass by skippyprime · Pull Request #52 · assertpy/assertpy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@skippyprime
Copy link
Contributor

Adding support for type and instance checking for Abstract Base Classes and other class definitions that leverage metaclasses. Existing logic enforced that the passed in type or class reference was actually a type by check "if type(arg) is not type then raise". This does not allow for using asserting type/instance checks against ABCs, collections.* (lots of ABCs), etc. Added tests for abstract classes.

Checks that don't work:

import collections
from assertpy import assert_that

def test_mapping():
    data = { 'a': 'b'}
    assert_that(data).is_instance_of(collections.Mapping)

Functions affected:

  • is_type_of
  • is_instance_of

Tests added:

tests/test_class.py

Defined 3 new classes, with a base implemented as an ABC. Added assertion tests for is_type_of() and is_instance_of(). All tests pass.

…es and other classes that leverage metaclasses. Existing logic enforced that the passed in type or class reference was actually a type by check "type(arg) is type". This does not allow for using asserting type/instance checks against ABCs, collections.* (lots of ABCs), etc. Added tests for abstract classes.
@saturnboy saturnboy added this to the v1.0 milestone May 12, 2016
@saturnboy saturnboy self-assigned this May 12, 2016
@saturnboy
Copy link
Contributor

@skippyprime awesome! coming from java I use @abc.abstractmethod often...just never got around to making the assertions work

@saturnboy saturnboy merged commit 64a29d6 into assertpy:master May 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0