tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_struct.py (2003B)


      1 # -*- coding: utf-8 -*-
      2 """
      3 test_struct
      4 ~~~~~~~~~~~
      5 
      6 Tests for the Header tuples.
      7 """
      8 import pytest
      9 
     10 from hpack import HeaderTuple, NeverIndexedHeaderTuple
     11 
     12 
     13 class TestHeaderTuple:
     14    def test_is_tuple(self):
     15        """
     16        HeaderTuple objects are tuples.
     17        """
     18        h = HeaderTuple('name', 'value')
     19        assert isinstance(h, tuple)
     20 
     21    def test_unpacks_properly(self):
     22        """
     23        HeaderTuple objects unpack like tuples.
     24        """
     25        h = HeaderTuple('name', 'value')
     26        k, v = h
     27 
     28        assert k == 'name'
     29        assert v == 'value'
     30 
     31    def test_header_tuples_are_indexable(self):
     32        """
     33        HeaderTuple objects can be indexed.
     34        """
     35        h = HeaderTuple('name', 'value')
     36        assert h.indexable
     37 
     38    def test_never_indexed_tuples_are_not_indexable(self):
     39        """
     40        NeverIndexedHeaderTuple objects cannot be indexed.
     41        """
     42        h = NeverIndexedHeaderTuple('name', 'value')
     43        assert not h.indexable
     44 
     45    @pytest.mark.parametrize('cls', (HeaderTuple, NeverIndexedHeaderTuple))
     46    def test_equal_to_tuples(self, cls):
     47        """
     48        HeaderTuples and NeverIndexedHeaderTuples are equal to equivalent
     49        tuples.
     50        """
     51        t1 = ('name', 'value')
     52        t2 = cls('name', 'value')
     53 
     54        assert t1 == t2
     55        assert t1 is not t2
     56 
     57    @pytest.mark.parametrize('cls', (HeaderTuple, NeverIndexedHeaderTuple))
     58    def test_equal_to_self(self, cls):
     59        """
     60        HeaderTuples and NeverIndexedHeaderTuples are always equal when
     61        compared to the same class.
     62        """
     63        t1 = cls('name', 'value')
     64        t2 = cls('name', 'value')
     65 
     66        assert t1 == t2
     67        assert t1 is not t2
     68 
     69    def test_equal_for_different_indexes(self):
     70        """
     71        HeaderTuples compare equal to equivalent NeverIndexedHeaderTuples.
     72        """
     73        t1 = HeaderTuple('name', 'value')
     74        t2 = NeverIndexedHeaderTuple('name', 'value')
     75 
     76        assert t1 == t2
     77        assert t1 is not t2