File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,41 @@ def test_long_tag_id(self):
279279 res = enc .output ()
280280 assert res == b'\x3f \x83 \xff \x7f \x03 \x02 \x01 \x01 '
281281
282+ def test_contextmanager_construct (self ):
283+ enc = asn1 .Encoder ()
284+ enc .start ()
285+
286+ with enc .construct (asn1 .Numbers .Sequence ):
287+ enc .write (1 )
288+ enc .write (b'foo' )
289+
290+ res = enc .output ()
291+ assert res == b'\x30 \x08 \x02 \x01 \x01 \x04 \x03 foo'
292+
293+ def test_contextmanager_calls_enter (self ):
294+ class TestEncoder (asn1 .Encoder ):
295+ def enter (self , nr , cls = None ):
296+ raise RuntimeError ()
297+
298+ enc = TestEncoder ()
299+ enc .start ()
300+
301+ with pytest .raises (RuntimeError ):
302+ with enc .construct (asn1 .Numbers .Sequence ):
303+ enc .write (1 )
304+
305+ def test_contextmanager_calls_leave (self ):
306+ class TestEncoder (asn1 .Encoder ):
307+ def leave (self ):
308+ raise RuntimeError ()
309+
310+ enc = TestEncoder ()
311+ enc .start ()
312+
313+ with pytest .raises (RuntimeError ):
314+ with enc .construct (asn1 .Numbers .Sequence ):
315+ enc .write (1 )
316+
282317 def test_long_tag_length (self ):
283318 enc = asn1 .Encoder ()
284319 enc .start ()
You can’t perform that action at this time.
0 commit comments