forked from python-hyper/hyperframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flags.py
43 lines (35 loc) · 1.22 KB
/
test_flags.py
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']"