-
Notifications
You must be signed in to change notification settings - Fork 306
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: The DB API Binary function accepts bytes data #630
Changes from 4 commits
bc8644f
40e34b5
c50686f
8d18d94
433712f
082a7d0
64a02eb
209fa5f
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# limitations under the License. | ||
|
||
import datetime | ||
import pytest | ||
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. Nit: We usually put
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 |
||
import unittest | ||
|
||
import google.cloud._helpers | ||
|
@@ -29,6 +30,19 @@ def test_binary_type(self): | |
def test_binary_constructor(self): | ||
self.assertEqual(types.Binary(u"hello"), b"hello") | ||
self.assertEqual(types.Binary(u"\u1f60"), u"\u1f60".encode("utf-8")) | ||
self.assertEqual(types.Binary(b"hello"), b"hello") | ||
self.assertEqual(types.Binary(bytearray(b"hello")), b"hello") | ||
self.assertEqual(types.Binary(memoryview(b"hello")), b"hello") | ||
|
||
class C: | ||
def __bytes__(self): | ||
return b"Google" | ||
|
||
self.assertEqual(types.Binary(C()), b"Google") | ||
|
||
for bad in 42, 42.0, None: | ||
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. I'd expect the tests for "bad inputs" to be in a separate test function. Ideally both of these (good inputs, bad inputs) would be parameterized in pytest-style tests. I think we can actually mix those in to the same file, so we can do that without refactoring everything, especially since these tests don't require any of the setup from the unit test class. 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 |
||
with pytest.raises(TypeError): | ||
types.Binary(bad) | ||
|
||
def test_timefromticks(self): | ||
somedatetime = datetime.datetime( | ||
|
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.
isinstance is checking for
int
, but the error saysdecimal.Decimal
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.
Oops. Thanks.
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