|
1 | 1 | import singer |
2 | 2 | import unittest |
| 3 | +from unittest.mock import patch |
3 | 4 | import datetime |
4 | 5 | import dateutil |
5 | 6 | from decimal import Decimal |
@@ -179,6 +180,31 @@ def test_parse_bulk_decs(self): |
179 | 180 | value = self.create_record(value_str) |
180 | 181 | self.assertEqual(Decimal(value_str), value) |
181 | 182 |
|
| 183 | + @patch('sys.stdout') |
| 184 | + def test_ensure_ascii_false(self, mock_stdout): |
| 185 | + """ |
| 186 | + Setting ensure_ascii=False will preserve special characters like é |
| 187 | + in their original form. |
| 188 | + """ |
| 189 | + rec = {"name": "José"} |
| 190 | + expected_output = '{"type": "RECORD", "stream": "test_stream", "record": {"name": "José"}}\n' |
| 191 | + rec_message = singer.RecordMessage(stream="test_stream", record=rec) |
| 192 | + result = singer.write_message(rec_message, ensure_ascii=False) |
| 193 | + mock_stdout.write.assert_called_once_with(expected_output) |
| 194 | + mock_stdout.flush.assert_called_once() |
| 195 | + |
| 196 | + @patch('sys.stdout') |
| 197 | + def test_ensure_ascii_true(self, mock_stdout): |
| 198 | + """ |
| 199 | + ensure_ascii defaults to True, special characters like é are |
| 200 | + escaped into their ASCII representation (e.g., \u00e9) |
| 201 | + """ |
| 202 | + rec = {"name": "José"} |
| 203 | + expected_output = '{"type": "RECORD", "stream": "test_stream", "record": {"name": "Jos\\u00e9"}}\n' |
| 204 | + rec_message = singer.RecordMessage(stream="test_stream", record=rec) |
| 205 | + result = singer.write_message(rec_message) |
| 206 | + mock_stdout.write.assert_called_once_with(expected_output) |
| 207 | + mock_stdout.flush.assert_called_once() |
182 | 208 |
|
183 | 209 | if __name__ == '__main__': |
184 | 210 | unittest.main() |
0 commit comments