Skip to content

Commit

Permalink
Report unicode strings as is for python2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
hammady committed Dec 28, 2023
1 parent 4d46902 commit 0296a52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyworker/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def _to_camel_case(string):

@staticmethod
def _convert_value(value):
if type(value) not in [str, int, float, bool]:
# unicode is needed in python2.7 only, otherwise it raises an error
if type(value) not in [str, int, float, bool, unicode]:
return json.dumps(value)
return value

Expand Down
7 changes: 7 additions & 0 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_reporter_format_attributes_prefixes_and_camel_cases_keys_and_converts_v
self.assertEqual(
reporter._format_attributes({
'test_key1': 'test_value1',
'test_key1b': u'test_value1b', # specific to python 2.7
'test_key2': 2,
'test_key3': 3.0,
'test_key4': True,
Expand All @@ -119,6 +120,7 @@ def test_reporter_format_attributes_prefixes_and_camel_cases_keys_and_converts_v
}),
{
'prefix.testKey1': 'test_value1',
'prefix.testKey1B': u'test_value1b', # specific to python 2.7
'prefix.testKey2': 2,
'prefix.testKey3': 3.0,
'prefix.testKey4': True,
Expand Down Expand Up @@ -157,6 +159,11 @@ def test_reporter_convert_value_converts_value_to_json_if_not_supported(self):
reporter._convert_value('test_value'),
'test_value'
)
# specific to python 2.7
self.assertEqual(
reporter._convert_value(u'test_value'),
u'test_value'
)
self.assertEqual(
reporter._convert_value(1),
1
Expand Down

0 comments on commit 0296a52

Please sign in to comment.