Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace type checking method #73

Merged
merged 1 commit into from
Oct 18, 2016
Merged

Replace type checking method #73

merged 1 commit into from
Oct 18, 2016

Conversation

leviable
Copy link
Contributor

@leviable leviable commented Oct 15, 2016

Suppose I was to subclass the Test class and add attributes specific to my environment:

from testrail.test import Test as TestBase

class Test(TestBase):
    def __init__(self, testrail_test):
        if not isinstance(testrail_test, TestBase):
            raise ValueError("testrail_test must be of TestRail Test type")
        super().__init__(content=testrail_test.raw_data())

    @property
    def long_running(self):
        return self._content.get("long_running", False)

    @long_running.setter
    def long_running(self, val):
        self._content['long_running'] = val

If I then instantiate one of these new tests and attempt to assign it to a result:

tests = tr_client.tests(run)
test = Test(tests[0])

result = tr_client.result()
result.test = test

An exception will be thrown because of the Results type checking:

    @test.setter
    def test(self, test_obj):
        if type(test_obj) != Test:
            raise TestRailError('input must be a Test')

The type(foo) == Foo idiom isn't capable of handling subclassing, wheres isinstance can:

    @test.setter
    def test(self, test_obj):
        if isintance(test_obj, Test):
            raise TestRailError('input must be a Test')

This PR reeplaces the method used for type checking (type(foo) == Foo) with one that allows for subclassing (isinstance(foo, Foo))

 - Replace the method used for type checking (`type(foo) == Foo`) with
   one that allows for subclassing (`isinstance(foo, Foo)`)
@coveralls
Copy link

coveralls commented Oct 15, 2016

Coverage Status

Coverage remained the same at 82.575% when pulling 202d982 on levi-rs:add-better-type-detection into 55250c9 on travispavek:master.

@travispavek travispavek merged commit 4a101f4 into travispavek:master Oct 18, 2016
@leviable leviable deleted the add-better-type-detection branch October 22, 2017 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants