예제 #1
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_add_to_large(self):
     tbl = HeaderTable()
     # Max size to small to hold the value we specify
     tbl.maxsize = 1
     tbl.add(b'TestName', b'TestValue')
     # Table length should be 0
     assert len(tbl.dynamic_entries) == 0
예제 #2
0
 def test_search_in_dynamic_full(self):
     tbl = HeaderTable()
     idx = len(HeaderTable.STATIC_TABLE) + 1
     tbl.add(b'TestName', b'TestValue')
     exp = (idx, b'TestName', b'TestValue')
     res = tbl.search(b'TestName', b'TestValue')
     assert res == exp
예제 #3
0
 def test_get_by_index_dynamic_table(self):
     tbl = HeaderTable()
     off = len(HeaderTable.STATIC_TABLE)
     val = (b'TestName', b'TestValue')
     tbl.add(*val)
     res = tbl.get_by_index(off + 1)
     assert res == val
예제 #4
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_get_by_index_dynamic_table(self):
     tbl = HeaderTable()
     off = len(HeaderTable.STATIC_TABLE)
     val = (b'TestName', b'TestValue')
     tbl.add(*val)
     res = tbl.get_by_index(off + 1)
     assert res == val
예제 #5
0
 def test_repr(self):
     tbl = HeaderTable()
     tbl.add(b'TestName1', b'TestValue1')
     tbl.add(b'TestName2', b'TestValue2')
     tbl.add(b'TestName2', b'TestValue2')
     # Meh, I hate that I have to do this to test
     # repr
     if is_py3:
         exp = (
             "HeaderTable(4096, False, deque(["
             "(b'TestName2', b'TestValue2'), "
             "(b'TestName2', b'TestValue2'), "
             "(b'TestName1', b'TestValue1')"
             "]))"
         )
     else:
         exp = (
             "HeaderTable(4096, False, deque(["
             "('TestName2', 'TestValue2'), "
             "('TestName2', 'TestValue2'), "
             "('TestName1', 'TestValue1')"
             "]))"
         )
     res = repr(tbl)
     assert res == exp
예제 #6
0
 def test_add_to_large(self):
     tbl = HeaderTable()
     # Max size to small to hold the value we specify
     tbl.maxsize = 1
     tbl.add(b'TestName', b'TestValue')
     # Table length should be 0
     assert len(tbl.dynamic_entries) == 0
예제 #7
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_search_in_dynamic_partial(self):
     tbl = HeaderTable()
     idx = len(HeaderTable.STATIC_TABLE) + 1
     tbl.add(b'TestName', b'TestValue')
     exp = (idx , b'TestName', None)
     res = tbl.search(b'TestName', b'NotInTable')
     assert res == exp
예제 #8
0
파일: test_table.py 프로젝트: jayvdb/hpack
    def test_get_by_index_out_of_range(self):
        tbl = HeaderTable()
        off = len(HeaderTable.STATIC_TABLE)
        tbl.add(b'TestName', b'TestValue')
        with pytest.raises(InvalidTableIndex) as e:
            tbl.get_by_index(off + 2)

        assert ("Invalid table index %d" % (off + 2) in str(e.value))
예제 #9
0
    def test_shrink_maxsize(self):
        tbl = HeaderTable()
        for i in range(3):
            tbl.add(b'TestName', b'TestValue')

        assert tbl._current_size == 147
        tbl.maxsize = 146
        assert len(tbl.dynamic_entries) == 2
        assert tbl._current_size == 98
예제 #10
0
    def test_shrink_maxsize(self):
        tbl = HeaderTable()
        for i in range(3):
            tbl.add(b'TestName', b'TestValue')

        assert tbl._current_size == 147
        tbl.maxsize = 146
        assert len(tbl.dynamic_entries) == 2
        assert tbl._current_size == 98
예제 #11
0
    def test_get_by_index_out_of_range(self):
        tbl = HeaderTable()
        off = len(HeaderTable.STATIC_TABLE)
        tbl.add(b'TestName', b'TestValue')
        with pytest.raises(InvalidTableIndex) as e:
            tbl.get_by_index(off + 2)

        assert (
            "InvalidTableIndex: Invalid table index %d" % (off + 2) in str(e)
        )
예제 #12
0
 def test_repr(self):
     tbl = HeaderTable()
     tbl.add(b'TestName1', b'TestValue1')
     tbl.add(b'TestName2', b'TestValue2')
     tbl.add(b'TestName2', b'TestValue2')
     exp = ("HeaderTable(4096, False, deque(["
            "(b'TestName2', b'TestValue2'), "
            "(b'TestName2', b'TestValue2'), "
            "(b'TestName1', b'TestValue1')"
            "]))")
     res = repr(tbl)
     assert res == exp
예제 #13
0
 def test_repr(self):
     tbl = HeaderTable()
     tbl.add(b'TestName1', b'TestValue1')
     tbl.add(b'TestName2', b'TestValue2')
     tbl.add(b'TestName2', b'TestValue2')
     # Meh, I hate that I have to do this to test
     # repr
     if is_py3:
         exp = ("HeaderTable(4096, False, deque(["
                "(b'TestName2', b'TestValue2'), "
                "(b'TestName2', b'TestValue2'), "
                "(b'TestName1', b'TestValue1')"
                "]))")
     else:
         exp = ("HeaderTable(4096, False, deque(["
                "('TestName2', 'TestValue2'), "
                "('TestName2', 'TestValue2'), "
                "('TestName1', 'TestValue1')"
                "]))")
     res = repr(tbl)
     assert res == exp
예제 #14
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_search_no_match(self):
     tbl = HeaderTable()
     idx = len(HeaderTable.STATIC_TABLE)
     tbl.add(b'TestName', b'TestValue')
     res = tbl.search(b'NotInTable', b'NotInTable')
     assert res is None
예제 #15
0
 def test_shrink_maxsize_is_zero(self):
     tbl = HeaderTable()
     tbl.add(b'TestName', b'TestValue')
     assert len(tbl.dynamic_entries) == 1
     tbl.maxsize = 0
     assert len(tbl.dynamic_entries) == 0
예제 #16
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_size(self):
     tbl = HeaderTable()
     for i in range(3):
         tbl.add(b'TestValue', b'TestName')
     res = tbl._size()
     assert res == 147
예제 #17
0
 def test_size(self):
     tbl = HeaderTable()
     for i in range(3):
         tbl.add(b'TestName', b'TestValue')
     res = tbl._current_size
     assert res == 147
예제 #18
0
 def test_search_no_match(self):
     tbl = HeaderTable()
     tbl.add(b'TestName', b'TestValue')
     res = tbl.search(b'NotInTable', b'NotInTable')
     assert res is None
예제 #19
0
 def test_get_by_index_out_of_range(self):
     tbl = HeaderTable()
     off = len(HeaderTable.STATIC_TABLE)
     tbl.add(b'TestName', b'TestValue')
     with pytest.raises(InvalidTableIndex):
         tbl.get_by_index(off + 2)
예제 #20
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_shrink_maxsize_is_zero(self):
     tbl = HeaderTable()
     tbl.add(b'TestName',b'TestValue')
     assert len(tbl.dynamic_entries) == 1
     tbl.maxsize = 0
     assert len(tbl.dynamic_entries) == 0
예제 #21
0
파일: test_table.py 프로젝트: irvind/hpack
 def test_get_by_index_out_of_range(self):
     tbl = HeaderTable()
     off = len(HeaderTable.STATIC_TABLE)
     tbl.add(b'TestName', b'TestValue')
     res = tbl.get_by_index(off+2)
     assert res is None # TODO HPACKException will be raised instead
예제 #22
0
 def test_get_by_index_out_of_range(self):
     tbl = HeaderTable()
     off = len(HeaderTable.STATIC_TABLE)
     tbl.add(b'TestName', b'TestValue')
     with pytest.raises(InvalidTableIndex):
         res = tbl.get_by_index(off+2)
예제 #23
0
 def test_search_no_match(self):
     tbl = HeaderTable()
     tbl.add(b'TestName', b'TestValue')
     res = tbl.search(b'NotInTable', b'NotInTable')
     assert res is None