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

Implement Client as context manager #238

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

wlhjason
Copy link

Simplify usage of the Client class by adding __enter__ and __exit__ methods, with the latter closing any established connection to the server.

Simplify usage of the Client class by adding `__enter__` and `__exit__` methods, with the latter closing any established connection to the server.
def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
Copy link
Author

Choose a reason for hiding this comment

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

No return value so that exceptions are propagated.



class ClientFromUrlTestCase(TestCase):
class ClientFromUrlTestCase(BaseTestCase):
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if this is the best way to get a Client instance to test with?

@@ -90,6 +90,12 @@ def __init__(self, *args, **kwargs):
self.reset_last_query()
super(Client, self).__init__()

def __enter__(self):
return self
Copy link
Author

Choose a reason for hiding this comment

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

Could run a dummy query like SELECT 1 here to test the server/client settings (check for unknown settings if settings_is_important)?

@xzkostyan xzkostyan merged commit 4ee6f36 into mymarilyn:master Jul 22, 2021
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.

3 participants