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

fix(testing.base.TestBase): parameterize api and srmock #577

Merged
merged 1 commit into from
Nov 17, 2015

Conversation

swizzard
Copy link
Contributor

Make api and srmock arguments to TestBase.setUp

As currently implemented, API and testing.srmock.StartResponseMock
objects are instantiated during setUp. This means subclasses either
need to throw away those instances, or eschew the super call.

@sriram-mv
Copy link
Contributor

Looks good to me.

"""Initializer, unittest-style"""

super(TestBase, self).setUp()
self._id = itertools.count(0)
self.api = falcon.API()
self.srmock = StartResponseMock()
self.api = api or falcon.API()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: It's a good habit to explicitly test for None (e.g., falcon.API() if api is None else api) since the object being passed in may (unexpectedly) evaluate to False, but in this case I don't think it matters since we are expecting instances of API and StartResponseMock which are known to always evaluate to True.

@kgriffs
Copy link
Member

kgriffs commented Nov 5, 2015

@swizzard Just a couple suggestions inline. Otherwise, could you please rebase onto master and squash down to a single commit? Thanks!

@philiptzou
Copy link
Contributor

I'd like to propose a new design here which I learned this trick first from Flask:

class TestBase(unittest.TestCase):
    api_class = falcon.API
    srmock_class = StartResponseMock

    def setUp(self):
        # blah blah
        self.api = self.api_class()
        self.srmock = self.srmock_class()
        # other blah blah

I perceive that super() call is also ugly since you had to override the whole setUp method actually. But override class attributes are much smooth and looks more "Pythonic" to me.

@kgriffs
Copy link
Member

kgriffs commented Nov 11, 2015

@philiptzou's We're actually already using this strategy in falcon.Request to determine the type of the context attribute. I've seen it work well in a few other projects, assuming it's well-documented.

@swizzard What do you think?

@swizzard
Copy link
Contributor Author

I implemented @philiptzou's fix. I usually just let my agonized, flailing git logs speak for themselves, so if I've messed something up on the rebase, please let me know.

super(TestBase, self).setUp()
self._id = itertools.count(0)
self.api = falcon.API()
self.srmock = StartResponseMock()
self.api = self.api()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.api = self.api_class()

attributes of `TestBase` to make subclassing easier.

As currently implemented, `API` and `testing.srmock.StartResponseMock`
objects are instantiated during `setUp`. This means subclasses either
need to throw away those instances, or eschew the `super` call.
@kgriffs
Copy link
Member

kgriffs commented Nov 17, 2015

LGTM, thanks!

kgriffs added a commit that referenced this pull request Nov 17, 2015
fix(testing.base.TestBase): parameterize api and srmock
@kgriffs kgriffs merged commit 2ad3468 into falconry:master Nov 17, 2015
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

4 participants