Debian Codegraph @

testing/web-platform/tests/tools/third_party/hyperframe/test/test_flags.py

raw
1 # -*- coding: utf-8 -*-
2 from hyperframe.frame import (
3 Flags, Flag,
4 )
5 import pytest
6
7
8 class TestFlags:
9 def test_add(self):
10 flags = Flags([Flag("VALID_FLAG", 0x00)])
11 assert not flags
12
13 flags.add("VALID_FLAG")
14 flags.add("VALID_FLAG")
15 assert "VALID_FLAG" in flags
16 assert list(flags) == ["VALID_FLAG"]
17 assert len(flags) == 1
18
19 def test_remove(self):
20 flags = Flags([Flag("VALID_FLAG", 0x00)])
21 flags.add("VALID_FLAG")
22
23 flags.discard("VALID_FLAG")
24 assert "VALID_FLAG" not in flags
25 assert list(flags) == []
26 assert len(flags) == 0
27
28 # discarding elements not in the set should not throw an exception
29 flags.discard("END_STREAM")
30
31 def test_validation(self):
32 flags = Flags([Flag("VALID_FLAG", 0x00)])
33 flags.add("VALID_FLAG")
34 with pytest.raises(ValueError):
35 flags.add("INVALID_FLAG")
36
37 def test_repr(self):
38 flags = Flags([Flag("VALID_FLAG", 0x00), Flag("OTHER_FLAG", 0x01)])
39 assert repr(flags) == "[]"
40 flags.add("VALID_FLAG")
41 assert repr(flags) == "['VALID_FLAG']"
42 flags.add("OTHER_FLAG")
43 assert repr(flags) == "['OTHER_FLAG', 'VALID_FLAG']"