py27: Suppress UnicodeWarnings in ShardRange setters
Previously, we'd see warnings like UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal when setting lower/upper bounds with non-ascii byte strings. Change-Id: I328f297a5403d7e59db95bc726428a3f92df88e1
This commit is contained in:
parent
948289151b
commit
fe74ec0489
@ -48,6 +48,7 @@ import ctypes.util
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import traceback
|
import traceback
|
||||||
|
import warnings
|
||||||
|
|
||||||
from tempfile import gettempdir, mkstemp, NamedTemporaryFile
|
from tempfile import gettempdir, mkstemp, NamedTemporaryFile
|
||||||
import glob
|
import glob
|
||||||
@ -4985,8 +4986,10 @@ class ShardRange(object):
|
|||||||
|
|
||||||
@lower.setter
|
@lower.setter
|
||||||
def lower(self, value):
|
def lower(self, value):
|
||||||
if value in (None, b'', u''):
|
with warnings.catch_warnings():
|
||||||
value = ShardRange.MIN
|
warnings.simplefilter('ignore', UnicodeWarning)
|
||||||
|
if value in (None, b'', u''):
|
||||||
|
value = ShardRange.MIN
|
||||||
try:
|
try:
|
||||||
value = self._encode_bound(value)
|
value = self._encode_bound(value)
|
||||||
except TypeError as err:
|
except TypeError as err:
|
||||||
@ -5011,8 +5014,10 @@ class ShardRange(object):
|
|||||||
|
|
||||||
@upper.setter
|
@upper.setter
|
||||||
def upper(self, value):
|
def upper(self, value):
|
||||||
if value in (None, b'', u''):
|
with warnings.catch_warnings():
|
||||||
value = ShardRange.MAX
|
warnings.simplefilter('ignore', UnicodeWarning)
|
||||||
|
if value in (None, b'', u''):
|
||||||
|
value = ShardRange.MAX
|
||||||
try:
|
try:
|
||||||
value = self._encode_bound(value)
|
value = self._encode_bound(value)
|
||||||
except TypeError as err:
|
except TypeError as err:
|
||||||
|
@ -44,6 +44,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import inspect
|
import inspect
|
||||||
|
import warnings
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
@ -7585,8 +7586,10 @@ class TestShardRange(unittest.TestCase):
|
|||||||
expected = u'\N{SNOWMAN}'
|
expected = u'\N{SNOWMAN}'
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
expected = expected.encode('utf-8')
|
expected = expected.encode('utf-8')
|
||||||
do_test(u'\N{SNOWMAN}', expected)
|
with warnings.catch_warnings(record=True) as captured_warnings:
|
||||||
do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
|
do_test(u'\N{SNOWMAN}', expected)
|
||||||
|
do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
|
||||||
|
self.assertFalse(captured_warnings)
|
||||||
|
|
||||||
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
|
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
|
||||||
sr.lower = ''
|
sr.lower = ''
|
||||||
@ -7633,8 +7636,10 @@ class TestShardRange(unittest.TestCase):
|
|||||||
expected = u'\N{SNOWMAN}'
|
expected = u'\N{SNOWMAN}'
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
expected = expected.encode('utf-8')
|
expected = expected.encode('utf-8')
|
||||||
do_test(u'\N{SNOWMAN}', expected)
|
with warnings.catch_warnings(record=True) as captured_warnings:
|
||||||
do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
|
do_test(u'\N{SNOWMAN}', expected)
|
||||||
|
do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
|
||||||
|
self.assertFalse(captured_warnings)
|
||||||
|
|
||||||
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
|
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
|
||||||
sr.upper = ''
|
sr.upper = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user