mirror of
https://github.com/weewx/weewx.git
synced 2026-05-19 07:15:18 -04:00
Test for None_string that cannot be converted using ASCII codec.
This commit is contained in:
@@ -149,7 +149,20 @@ class ValueHelperTest(unittest.TestCase):
|
||||
self.assertEqual(six.text_type(vh), u"68.0°F")
|
||||
self.assertEqual(six.text_type(vh.degree_F), u"68.0°F")
|
||||
self.assertEqual(six.text_type(vh.degree_C), u"20.0°C")
|
||||
|
||||
|
||||
# Using .format() interface
|
||||
self.assertEqual(vh.format(), u"68.0°F")
|
||||
self.assertEqual(vh.format("T=%.3f", add_label=False), u"T=68.010")
|
||||
|
||||
# Test None_string
|
||||
value_t = (None, "degree_F", "group_temperature")
|
||||
vh = weewx.units.ValueHelper(value_t)
|
||||
self.assertEqual(vh.format(None_string='foo'), u'foo')
|
||||
self.assertTrue(isinstance(vh.format(None_string='foo'), six.text_type))
|
||||
# This one cannot be done with ASCII codec:
|
||||
self.assertEqual(vh.format(None_string=u'unknown °F'), u'unknown °F')
|
||||
self.assertTrue(isinstance(vh.format(None_string=u'unknown °F'), six.text_type))
|
||||
|
||||
def testFormattingWithConversion(self):
|
||||
value_t = (68.01, "degree_F", "group_temperature")
|
||||
c_m = weewx.units.Converter(weewx.units.MetricUnits)
|
||||
|
||||
@@ -744,7 +744,11 @@ class Formatter(object):
|
||||
val_str = self.unit_format_dict.get('NONE', u'N/A')
|
||||
else:
|
||||
# Make sure the "None_string" is, in fact, a string
|
||||
val_str = str(None_string)
|
||||
if isinstance(None_string, six.string_types):
|
||||
val_str = None_string
|
||||
else:
|
||||
# Coerce to a string.
|
||||
val_str = str(None_string)
|
||||
addLabel = False
|
||||
elif val_t[1] == "unix_epoch":
|
||||
# Different formatting routines are used if the value is a time.
|
||||
|
||||
Reference in New Issue
Block a user