File: test_encode.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (34 lines) | stat: -rw-r--r-- 1,302 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest
from azure.eventhub._pyamqp._encode import encode_filter_set, encode_unknown
from decimal import Decimal

@pytest.mark.parametrize(
    "value,expected",
    [
        ({b"com.microsoft:session-filter": "ababa"}, "ababa"),
        ({b"com.microsoft:session-filter": "abab"}, "abab"),
        ({b"com.microsoft:session-filter": "aba"}, "aba"),
        ({b"com.microsoft:session-filter": "ab"}, "ab"),
        ({b"com.microsoft:session-filter": "a"}, "a"),
        ({b"com.microsoft:session-filter": 1}, 1),
    ],
)
def test_valid_filter_encode(value, expected):
    fields = encode_filter_set(value)
    assert len(fields) == 2
    assert fields["VALUE"][0][1] == expected


@pytest.mark.parametrize(
        "value, expected",
        [
            (Decimal("3.14"), b'\x940<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01:'),
            (Decimal((1, (3, 1, 4), -2)), b'\x94\xb0<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01:'),
            (Decimal("0.1"), b'\x940>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'),
            (Decimal("33802.4489"), b'\x9408\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14%\xd8)'),
        ]
)
def test_decimal_encode(value, expected):
    output = bytearray()
    encode_unknown(output, value)
    assert bytes(output) == expected