-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-1787: fix NotMasterError wrong attribute error #450
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
Changes from all commits
eea3a91
7b41218
269d554
82edc07
8a90dee
7c5b7fb
4cfb959
71c60da
bf46a51
a2274c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ pymongo.egg-info/ | |
*.egg | ||
.tox | ||
mongocryptd.pid | ||
.idea/ |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
# Copyright 2020-present MongoDB, Inc. | ||||||
# | ||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
# you may not use this file except in compliance with the License. | ||||||
# You may obtain a copy of the License at | ||||||
# | ||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||
# | ||||||
# Unless required by applicable law or agreed to in writing, software | ||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
|
||||||
import sys | ||||||
import traceback | ||||||
|
||||||
sys.path[0:0] = [""] | ||||||
|
||||||
from pymongo.errors import (NotMasterError, | ||||||
OperationFailure) | ||||||
from test import (PyMongoTestCase, | ||||||
unittest) | ||||||
|
||||||
|
||||||
class TestErrors(PyMongoTestCase): | ||||||
def test_not_master_error(self): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a similar test for OperationFailure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
exc = NotMasterError("not master test", {"errmsg": "error"}) | ||||||
self.assertIn("full error", str(exc)) | ||||||
try: | ||||||
raise exc | ||||||
except NotMasterError: | ||||||
self.assertIn("full error", traceback.format_exc()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the mongo-python-driver/test/test_bson.py Lines 1088 to 1089 in 4760d07
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
|
||||||
def test_operation_failure(self): | ||||||
exc = OperationFailure("operation failure test", 10, | ||||||
{"errmsg": "error"}) | ||||||
self.assertIn("full error", str(exc)) | ||||||
try: | ||||||
raise exc | ||||||
except OperationFailure: | ||||||
self.assertIn("full error", traceback.format_exc()) | ||||||
|
||||||
def _test_unicode_strs(self, exc): | ||||||
if sys.version_info[0] == 2: | ||||||
self.assertEqual("unicode \xf0\x9f\x90\x8d, full error: {" | ||||||
"'errmsg': u'unicode \\U0001f40d'}", str(exc)) | ||||||
elif 'PyPy' in sys.version: | ||||||
# PyPy displays unicode in repr differently. | ||||||
self.assertEqual("unicode \U0001f40d, full error: {" | ||||||
"'errmsg': 'unicode \\U0001f40d'}", str(exc)) | ||||||
else: | ||||||
self.assertEqual("unicode \U0001f40d, full error: {" | ||||||
"'errmsg': 'unicode \U0001f40d'}", str(exc)) | ||||||
try: | ||||||
raise exc | ||||||
except Exception: | ||||||
self.assertIn("full error", traceback.format_exc()) | ||||||
|
||||||
def test_unicode_strs_operation_failure(self): | ||||||
exc = OperationFailure(u'unicode \U0001f40d', 10, | ||||||
{"errmsg": u'unicode \U0001f40d'}) | ||||||
self._test_unicode_strs(exc) | ||||||
|
||||||
def test_unicode_strs_not_master_error(self): | ||||||
exc = NotMasterError(u'unicode \U0001f40d', | ||||||
{"errmsg": u'unicode \U0001f40d'}) | ||||||
self._test_unicode_strs(exc) | ||||||
|
||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest removing any unused imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.