def test_simple(self, value: Any, number: Optional[asn1.TNumber]) -> None: encoder = Encoder() encoder.write(value, number) data = encoder.output() decoder = Decoder(data) _, decoded = decoder.read() assert decoded == value assert decoder.eof()
def test_one_enter(self, number: asn1.TNumber, typ: asn1.TType, values: Tuple, expected: bytes) -> None: encoder = Encoder() encoder.enter(number, typ) for value in values: encoder.write(value) encoder.exit() res = encoder.output() assert res == expected
def test_multiple_enter( self, values: Tuple[Tuple[asn1.TNumber, Optional[asn1.TClass], Tuple]], expected: bytes ) -> None: encoder = Encoder() for number, typ, values_ in values: encoder.enter(number, typ) for value in values_: encoder.write(value) encoder.exit() res = encoder.output() assert res == expected
def test_simple_encode(self, value: Any, number: Optional[asn1.TNumber], expected: bytes) -> None: encoder = Encoder() encoder.write(value, number) result = encoder.output() assert result == expected
def test_invalid_number(self) -> None: encoder = Encoder() with pytest.raises(Error, match="Unhandled Number 155 value 1"): encoder.write(1, 155)
def test_cannot_determine_number(self) -> None: encoder = Encoder() with pytest.raises(Error, match="Cannot determine Number for value type"): encoder.write(1.21)
def test_exit_errors(self) -> None: encoder = Encoder() with pytest.raises(Error, match="Tag stack is empty."): encoder.exit()
def test_error_object_identifier(self, value: str) -> None: encoder = Encoder() with pytest.raises(Error, match="Illegal object identifier"): encoder.write(value, asn1.Number.ObjectIdentifier)
def test_error_stack(self) -> None: encoder = Encoder() encoder.enter(asn1.Number.Sequence) with pytest.raises(Error, match="Stack is not empty."): encoder.output()