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