Exemplo n.º 1
0
    def test_item_properties(self):
        item1 = Item(100)
        assert item1._item == b"100"
        assert item1._type == int
        assert item1.raw == b"100"
        assert item1.string == "100"
        assert item1.integer == 100
        assert item1.boolean == True
        assert item1.original == 100

        item2 = Item("hello world")
        assert item2._item == b"hello world"
        assert item2._type == str
        assert item2.raw == b"hello world"
        assert item2.string == "hello world"
        assert item2.integer == None
        assert item2.boolean == True
        assert item2.original == "hello world"

        item3 = Item(None)
        assert item3._item == b""
        assert item3._type == type(None)
        assert item3.raw == b""
        assert item3.string == ""
        assert item3.integer == None
        assert item3.boolean == False
        assert item3.original == None
Exemplo n.º 2
0
 def test_item_repr(self):
     assert (
         repr(Item(100)) ==
         "Item(bytes=b'100', str='100', int=100, bool=True, original_type=int)"
     )
     assert (
         repr(Item(None)) ==
         "Item(bytes=b'', str='', int=None, bool=False, original_type=NoneType)"
     )
     assert (repr(
         Item(True)
     ) == "Item(bytes=b'1', str='1', int=1, bool=True, original_type=bool)")
     assert (
         repr(Item("hello")) ==
         "Item(bytes=b'hello', str='hello', int=None, bool=True, original_type=str)"
     )
Exemplo n.º 3
0
 def test_item_update(self):
     d = ItemDict()
     d.update({"100": "one hundred"})
     assert "100" in d
     assert b"100" in d
     assert 100 in d
     assert Item(100) in d
Exemplo n.º 4
0
    def test_item_pos_and_neg(self):
        assert +Item("100") == "100"
        assert +Item(100) == "100"
        assert +Item(None) == ""
        assert +Item(True) == "1"

        assert -Item("100") == 100
        assert -Item(100) == 100
        assert -Item(None) == None
        assert -Item(False) == 0
Exemplo n.º 5
0
 def test_item_add(self):
     assert Item("hello") + Item("world") == Item("helloworld")
Exemplo n.º 6
0
 def test_item_eq(self):
     assert Item(100) == Item("100") == Item(b"100")
     assert Item("hello") == Item(b"hello")
Exemplo n.º 7
0
 def test_item_contains(self):
     assert b"hello" in Item("hello world")
     assert 100 in Item("one hundred is 100")
     assert "ola" in Item(b"ola mundo")
Exemplo n.º 8
0
 def test_item_str(self):
     item = Item(100)
     assert str(item) == item.string
Exemplo n.º 9
0
 def test_item_hash(self):
     assert hash(b"hello") == hash(Item("hello")) == hash(Item(b"hello"))
Exemplo n.º 10
0
 def test_item_isub(self):
     item = Item("helloworld")
     item -= Item("world")
     assert item == Item("hello")
Exemplo n.º 11
0
 def test_item_setitem(self):
     d = ItemDict()
     d[100] = "one hundred"
     assert d["100"] == d[b"100"] == d[100] == d[Item(100)]
Exemplo n.º 12
0
 def test_item_init(self):
     d = ItemDict({"100": "one hundred"})
     assert d["100"] == d[b"100"] == d[100] == d[Item(100)]
Exemplo n.º 13
0
 def test_item_init(self):
     item = Item(100)
     assert item._item == b"100"
     assert item._type == int
Exemplo n.º 14
0
 def test_item_byte_item_err(self):
     with pytest.raises(TypeError):
         Item.byte_item(1.5)
Exemplo n.º 15
0
 def test_item_iadd(self):
     item = Item("hello")
     item += Item("world")
     assert item == Item("helloworld")
Exemplo n.º 16
0
 def test_item_sub(self):
     assert Item("helloworld") - Item("world") == Item("hello")
Exemplo n.º 17
0
 def test_item_contains(self):
     d = ItemDict({"100": "one hundred"})
     assert "100" in d
     assert b"100" in d
     assert 100 in d
     assert Item(100) in d
Exemplo n.º 18
0
 def test_item_iter(self):
     for i1, i2 in zip(Item("hello"), "hello"):
         assert i1 == i2
Exemplo n.º 19
0
 def test_replace(self):
     item = Item("hello world")
     item = item.replace("hello", "ola")
     assert item == Item("ola world")
Exemplo n.º 20
0
 def test_item_len(self):
     assert len(Item(None)) == 0
     assert len(Item(123)) == 3
     assert len(Item("hello world")) == 11
Exemplo n.º 21
0
 def test_item_bool(self):
     item = Item(100)
     assert bool(item) == item.boolean