File: test_named_bits.py

package info (click to toggle)
python-pysnmp4 7.1.21-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,564 kB
  • sloc: python: 33,654; makefile: 166; javascript: 4
file content (54 lines) | stat: -rw-r--r-- 1,323 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest

from pysnmp.proto.rfc1902 import Bits


def test_prettyIn_list_valid():
    Fruit = Bits.with_named_bits(apple=0, orange=1, peach=2)

    assert Fruit().prettyIn(["apple"]) == b"\x80"
    assert Fruit().prettyIn(["orange"]) == b"\x40"
    assert Fruit().prettyIn(["peach"]) == b"\x20"


def test_prettyIn_list_multiple_valid():
    Fruit = Bits.with_named_bits(apple=0, orange=1, peach=2)

    assert Fruit().prettyIn(["peach", "apple"]) == b"\xA0"


def test_prettyIn_list_invalid():
    Fruit = Bits.with_named_bits(apple=0, orange=1, peach=2)

    with pytest.raises(Exception):
        Fruit().prettyIn(["banana"])


def test_prettyIn_multiple_octets():
    Fruit = Bits.with_named_bits(
        apple=0,
        orange=1,
        peach=2,
        banana=3,
        watermelon=4,
        strawberry=5,
        mango=6,
        lemon=7,
        cherry=8,
    )

    assert len(Fruit().prettyIn(["cherry"])) > 1


def test_prettyOut_valid():
    Fruit = Bits.with_named_bits(apple=0, orange=1, peach=2)

    assert Fruit().prettyOut(b"\x20") == "peach"
    assert Fruit().prettyOut(b"\x40") == "orange"
    assert Fruit().prettyOut(b"\x80") == "apple"


def test_prettyOut_invalid():
    Fruit = Bits.with_named_bits(apple=0, orange=1, peach=2)

    assert Fruit().prettyOut(b"\x01").startswith("Unknown")