Changeset 83fa028 in trunk
- Timestamp:
- 2023-11-16T18:53:51Z (17 months ago)
- Branches:
- master
- Children:
- 7b680b3
- Parents:
- 3ddfb92
- Location:
- src/allmydata
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/__init__.py ¶
r3ddfb92 r83fa028 126 126 127 127 from eliot import to_file 128 from allmydata.util. eliotutil import BytesEliotJSONEncoder129 to_file(open("eliot.log", "wb"), encoder= BytesEliotJSONEncoder)128 from allmydata.util.jsonbytes import AnyBytesJSONEncoder 129 to_file(open("eliot.log", "wb"), encoder=AnyBytesJSONEncoder) -
TabularUnified src/allmydata/test/eliotutil.py ¶
r3ddfb92 r83fa028 39 39 ) 40 40 41 from ..util. eliotutilimport (42 BytesEliotJSONEncoder41 from ..util.jsonbytes import ( 42 AnyBytesJSONEncoder 43 43 ) 44 44 … … 148 148 @wraps(test_method) 149 149 def run_with_logging(*args, **kwargs): 150 validating_logger = MemoryLogger(encoder= BytesEliotJSONEncoder)150 validating_logger = MemoryLogger(encoder=AnyBytesJSONEncoder) 151 151 original = swap_logger(None) 152 152 try: -
TabularUnified src/allmydata/test/test_client.py ¶
r3ddfb92 r83fa028 68 68 jsonbytes as json, 69 69 ) 70 from allmydata.util.eliotutil import capture_logging , BytesEliotJSONEncoder70 from allmydata.util.eliotutil import capture_logging 71 71 from allmydata.util.fileutil import abspath_expanduser_unicode 72 72 from allmydata.interfaces import IFilesystemNode, IFileNode, \ … … 851 851 succeeded=True, 852 852 ), 853 encoder_= BytesEliotJSONEncoder853 encoder_=json.AnyBytesJSONEncoder 854 854 ) 855 855 def test_static_servers(self, logger): … … 886 886 succeeded=False, 887 887 ), 888 encoder_= BytesEliotJSONEncoder888 encoder_=json.AnyBytesJSONEncoder 889 889 ) 890 890 def test_invalid_static_server(self, logger): -
TabularUnified src/allmydata/test/test_eliotutil.py ¶
r3ddfb92 r83fa028 64 64 65 65 from ..util.eliotutil import ( 66 BytesEliotJSONEncoder,67 66 log_call_deferred, 68 67 _parse_destination_description, … … 86 85 return result.wasSuccessful() 87 86 return AfterPreprocessing(run, Equals(True)) 88 89 90 class BytesEliotJSONEncoderTests(TestCase):91 """Tests for ``BytesEliotJSONEncoder``."""92 93 def test_encoding_bytes(self):94 """``BytesEliotJSONEncoder`` can encode bytes."""95 encoder = BytesEliotJSONEncoder()96 self.assertEqual(encoder.default(b"xxx"), "xxx")97 self.assertEqual(encoder.default(bytes([12])), "\x0c")98 99 def test_encoding_sets(self):100 """``BytesEliotJSONEncoder`` can encode sets."""101 encoder = BytesEliotJSONEncoder()102 self.assertIn(encoder.default({1, 2}), ([1, 2], [2, 1]))103 87 104 88 -
TabularUnified src/allmydata/test/web/test_logs.py ¶
r3ddfb92 r83fa028 118 118 yield proto.is_closed 119 119 120 self.assertThat(len(messages), Equals(3) )120 self.assertThat(len(messages), Equals(3), messages) 121 121 self.assertThat(messages[0]["action_type"], Equals("test:cli:some-exciting-action")) 122 122 self.assertThat(messages[0]["arguments"], -
TabularUnified src/allmydata/util/eliotutil.py ¶
r3ddfb92 r83fa028 51 51 capture_logging, 52 52 ) 53 from eliot.json import EliotJSONEncoder54 53 55 54 from eliot._validation import ( … … 79 78 from twisted.application.service import Service 80 79 81 82 class BytesEliotJSONEncoder(EliotJSONEncoder): 83 """Support encoding bytes.""" 84 85 def default(self, o): 86 if isinstance(o, bytes): 87 return o.decode("utf-8", "backslashreplace") 88 if isinstance(o, set): 89 return list(o) 90 return EliotJSONEncoder.default(self, o) 80 from .jsonbytes import AnyBytesJSONEncoder 91 81 92 82 … … 307 297 maxRotatedFiles=max_rotated_files, 308 298 ) 309 return lambda reactor: FileDestination(get_file(), encoder= BytesEliotJSONEncoder)299 return lambda reactor: FileDestination(get_file(), encoder=AnyBytesJSONEncoder) 310 300 311 301 -
TabularUnified src/allmydata/util/jsonbytes.py ¶
r3ddfb92 r83fa028 62 62 A JSON encoder than can also encode UTF-8 encoded strings. 63 63 """ 64 def default(self, o): 65 return bytes_to_unicode(False, o) 66 64 67 def encode(self, o, **kwargs): 65 68 return json.JSONEncoder.encode( … … 78 81 bytes are quoted. 79 82 """ 83 def default(self, o): 84 return bytes_to_unicode(True, o) 85 80 86 def encode(self, o, **kwargs): 81 87 return json.JSONEncoder.encode(
Note: See TracChangeset
for help on using the changeset viewer.