File: test_flags.py

package info (click to toggle)
python-hyperframe 6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 224 kB
  • sloc: python: 1,460; makefile: 14
file content (43 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (14)
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
# -*- coding: utf-8 -*-
from hyperframe.frame import (
    Flags, Flag,
)
import pytest


class TestFlags:
    def test_add(self):
        flags = Flags([Flag("VALID_FLAG", 0x00)])
        assert not flags

        flags.add("VALID_FLAG")
        flags.add("VALID_FLAG")
        assert "VALID_FLAG" in flags
        assert list(flags) == ["VALID_FLAG"]
        assert len(flags) == 1

    def test_remove(self):
        flags = Flags([Flag("VALID_FLAG", 0x00)])
        flags.add("VALID_FLAG")

        flags.discard("VALID_FLAG")
        assert "VALID_FLAG" not in flags
        assert list(flags) == []
        assert len(flags) == 0

        # discarding elements not in the set should not throw an exception
        flags.discard("END_STREAM")

    def test_validation(self):
        flags = Flags([Flag("VALID_FLAG", 0x00)])
        flags.add("VALID_FLAG")
        with pytest.raises(ValueError):
            flags.add("INVALID_FLAG")

    def test_repr(self):
        flags = Flags([Flag("VALID_FLAG", 0x00), Flag("OTHER_FLAG", 0x01)])
        assert repr(flags) == "[]"
        flags.add("VALID_FLAG")
        assert repr(flags) == "['VALID_FLAG']"
        flags.add("OTHER_FLAG")
        assert repr(flags) == "['OTHER_FLAG', 'VALID_FLAG']"