コード例 #1
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_remove():
    """ Test LDAPValueList's remove method. """
    lvl = LDAPValueList(("test1", "test2"))
    lvl.remove("Test1")
    assert lvl == ["test2"]
    with pytest.raises(ValueError):
        lvl.remove("test1")
コード例 #2
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_append():
    """ Test LDAPValueList's append method. """
    lvl = LDAPValueList()
    lvl.append("test")
    assert "test" in lvl
    with pytest.raises(ValueError):
        lvl.append("Test")
コード例 #3
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_insert():
    """ Test LDAPValueList's insert method. """
    lvl = LDAPValueList(("test1",))
    lvl.insert(0, "test2")
    assert lvl == ["test2", "test1"]
    with pytest.raises(ValueError):
        lvl.insert(2, "test2")
コード例 #4
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_extend():
    """ Test LDAPValueList's extend method. """
    lvl = LDAPValueList(("test1",))
    lvl.extend(("test2", "test3"))
    assert lvl == ["test1", "test2", "test3"]
    with pytest.raises(ValueError):
        lvl.extend(("test4", "test1"))
コード例 #5
0
def test_readonly_attrs():
    """ Test modifying read-only attributes. """
    lvl = LDAPValueList((1, 2, 3))
    with pytest.raises(ValueError):
        lvl.added = [1, 2, 3]
    with pytest.raises(ValueError):
        lvl.deleted = [1, 2, 3]
    with pytest.raises(TypeError):
        lvl._status_dict = {"status": 2}
コード例 #6
0
def test_set_status():
    """ Test setting LDAPValueList's status. """
    lvl = LDAPValueList()
    with pytest.raises(TypeError):
        lvl.status = "a"
    with pytest.raises(ValueError):
        lvl.status = -1
    lvl.status = 2
    assert lvl.status == 2
コード例 #7
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_readonly_attrs():
    """ Test modifying read-only attributes. """
    lvl = LDAPValueList((1, 2, 3))
    with pytest.raises(ValueError):
        lvl.added = [1, 2, 3]
    with pytest.raises(ValueError):
        lvl.deleted = [1, 2, 3]
    with pytest.raises(TypeError):
        lvl._status_dict = {"status": 2}
コード例 #8
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_set_status():
    """ Test setting LDAPValueList's status. """
    lvl = LDAPValueList()
    with pytest.raises(TypeError):
        lvl.status = "a"
    with pytest.raises(ValueError):
        lvl.status = -1
    lvl.status = 2
    assert lvl.status == 2
コード例 #9
0
 def test_set_status(self):
     """ Test setting LDAPValueList's status. """
     lvl = LDAPValueList()
     def wrong1():
         lvl.status = 'a'
     self.assertRaises(TypeError, wrong1)
     def wrong2():
         lvl.status = -1
     self.assertRaises(ValueError, wrong2)
     lvl.status = 2
     self.assertEqual(lvl.status, 2)
コード例 #10
0
    def test_set_status(self):
        """ Test setting LDAPValueList's status. """
        lvl = LDAPValueList()

        def wrong1():
            lvl.status = 'a'

        self.assertRaises(TypeError, wrong1)

        def wrong2():
            lvl.status = -1

        self.assertRaises(ValueError, wrong2)
        lvl.status = 2
        self.assertEqual(lvl.status, 2)
コード例 #11
0
def test_add():
    """ Test adding list to an LDAPValueList. """
    lvl = LDAPValueList((1, 2, 3))
    assert lvl + [4, 5] == [1, 2, 3, 4, 5]
    with pytest.raises(TypeError):
        _ = lvl + 3
    with pytest.raises(TypeError):
        lvl += "x"
    lvl += [4, 5]
    assert lvl == [1, 2, 3, 4, 5]
コード例 #12
0
def test_set():
    """ Test LDAPValueList's __setitem__ method. """
    lvl = LDAPValueList()
    lvl[0:2] = ("test1", "test2", "test3")
    lvl[1] = "test4"
    assert lvl == ["test1", "test4", "test3"]
    with pytest.raises(ValueError):
        lvl[1] = "test3"
    with pytest.raises(ValueError):
        lvl[1:3] = ["test5", "test1"]
    del lvl[0:2]
    assert lvl == ["test3"]
    del lvl[0]
    assert lvl == []
    lvl = LDAPValueList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
    del lvl[slice(1, 10, 2)]
    assert lvl == [1, 3, 5, 7, 9, 11, 12]
    lvl[slice(2, 6, 2)] = (13, 14)
    assert lvl == [1, 3, 13, 7, 14, 11, 12]
コード例 #13
0
def test_pop():
    """ Test LDAPValueList's pop method. """
    lvl = LDAPValueList(("test1", "test2"))
    assert lvl.pop(0) == "test1"
    assert lvl == ["test2"]
    lvl.pop()
    assert lvl == []
    with pytest.raises(IndexError):
        lvl.pop()
コード例 #14
0
def test_remove():
    """ Test LDAPValueList's remove method. """
    lvl = LDAPValueList(("test1", "test2"))
    lvl.remove("Test1")
    assert lvl == ["test2"]
    with pytest.raises(ValueError):
        lvl.remove("test1")
コード例 #15
0
def test_extend():
    """ Test LDAPValueList's extend method. """
    lvl = LDAPValueList(("test1", ))
    lvl.extend(("test2", "test3"))
    assert lvl == ["test1", "test2", "test3"]
    with pytest.raises(ValueError):
        lvl.extend(("test4", "test1"))
コード例 #16
0
def test_insert():
    """ Test LDAPValueList's insert method. """
    lvl = LDAPValueList(("test1", ))
    lvl.insert(0, "test2")
    assert lvl == ["test2", "test1"]
    with pytest.raises(ValueError):
        lvl.insert(2, "test2")
コード例 #17
0
def test_append():
    """ Test LDAPValueList's append method. """
    lvl = LDAPValueList()
    lvl.append("test")
    assert "test" in lvl
    with pytest.raises(ValueError):
        lvl.append("Test")
コード例 #18
0
    def test_add(self):
        """ Test adding list to an LDAPValueList. """
        lvl = LDAPValueList((1, 2, 3))
        self.assertEqual(lvl + [4, 5], [1, 2, 3, 4, 5])
        self.assertRaises(TypeError, lambda: lvl + 3)

        def wrong():
            nonlocal lvl
            lvl += 'x'

        self.assertRaises(TypeError, wrong)
        lvl += [4, 5]
        self.assertEqual(lvl, [1, 2, 3, 4, 5])
コード例 #19
0
 def test_pop(self):
     """ Test LDAPValueList's pop method. """
     lvl = LDAPValueList(("test1", "test2"))
     lvl.pop(0)
     self.assertEqual(lvl, ["test2"])
     lvl.pop()
     self.assertEqual(lvl, [])
     self.assertRaises(IndexError, lvl.pop)
コード例 #20
0
 def test_pop(self):
     """ Test LDAPValueList's pop method. """
     lvl = LDAPValueList(("test1", "test2"))
     lvl.pop(0)
     self.assertEqual(lvl, ["test2"])
     lvl.pop()
     self.assertEqual(lvl, [])
     self.assertRaises(IndexError, lambda: lvl.pop())
コード例 #21
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_pop():
    """ Test LDAPValueList's pop method. """
    lvl = LDAPValueList(("test1", "test2"))
    assert lvl.pop(0) == "test1"
    assert lvl == ["test2"]
    lvl.pop()
    assert lvl == []
    with pytest.raises(IndexError):
        lvl.pop()
コード例 #22
0
    def test_set(self):
        """ Test LDAPValueList's __setitem__ method. """
        lvl = LDAPValueList()
        lvl[0:2] = ("test1", "test2", "test3")
        lvl[1] = "test4"
        self.assertEqual(lvl, ["test1", "test4", "test3"])

        def set_item1():
            lvl[1] = "test3"

        def set_item2():
            lvl[1:3] = ["test5", "test1"]

        self.assertRaises(ValueError, set_item1)
        self.assertRaises(ValueError, set_item2)
        del lvl[0:2]
        self.assertEqual(lvl, ["test3"])
        del lvl[0]
        self.assertEqual(lvl, [])
        lvl = LDAPValueList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        del lvl[slice(1, 10, 2)]
        self.assertEqual(lvl, [1, 3, 5, 7, 9, 11, 12])
        lvl[slice(2, 6, 2)] = (13, 14)
        self.assertEqual(lvl, [1, 3, 13, 7, 14, 11, 12])
コード例 #23
0
 def test_extend(self):
     """ Test LDAPValueList's extend method. """
     lvl = LDAPValueList(("test1",))
     lvl.extend(("test2", "test3"))
     self.assertEqual(lvl, ["test1", "test2", "test3"])
     self.assertRaises(ValueError, lambda: lvl.extend(("test4", "test1")))
コード例 #24
0
 def test_remove(self):
     """ Test LDAPValueList's remove method. """
     lvl = LDAPValueList(("test1", "test2"))
     lvl.remove("Test1")
     self.assertEqual(lvl, ["test2"])
     self.assertRaises(ValueError, lambda: lvl.remove("test1"))
コード例 #25
0
 def test_insert(self):
     """ Test LDAPValueList's insert method. """
     lvl = LDAPValueList(("test1",))
     lvl.insert(0, "test2")
     self.assertEqual(lvl, ["test2", "test1"])
     self.assertRaises(ValueError, lambda: lvl.insert(2, "test2"))
コード例 #26
0
def test_mul():
    """ Test multiplying an LDAPValueList. """
    lvl = LDAPValueList((1, 2, 3))
    with pytest.raises(TypeError):
        _ = lvl * 3
コード例 #27
0
 def test_remove(self):
     """ Test LDAPValueList's remove method. """
     lvl = LDAPValueList(("test1", "test2"))
     lvl.remove("Test1")
     self.assertEqual(lvl, ["test2"])
     self.assertRaises(ValueError, lambda: lvl.remove("test1"))
コード例 #28
0
def test_copy():
    """ Test LDAPValueList's copy method. """
    lvl1 = LDAPValueList(("test1", "test2"))
    lvl2 = lvl1.copy()
    assert lvl1 == lvl2
    assert lvl1.status == lvl2.status
コード例 #29
0
 def test_extend(self):
     """ Test LDAPValueList's extend method. """
     lvl = LDAPValueList(("test1", ))
     lvl.extend(("test2", "test3"))
     self.assertEqual(lvl, ["test1", "test2", "test3"])
     self.assertRaises(ValueError, lambda: lvl.extend(("test4", "test1")))
コード例 #30
0
 def test_append(self):
     """ Test LDAPValueList's append method. """
     lvl = LDAPValueList()
     lvl.append("test")
     self.assertRaises(ValueError, lambda: lvl.append("Test"))
コード例 #31
0
 def test_copy(self):
     """ Test LDAPValueList's copy method. """
     lvl1 = LDAPValueList(("test1", "test2"))
     lvl2 = lvl1.copy()
     self.assertEqual(lvl1, lvl2)
     self.assertEqual(lvl1.status, lvl2.status)
コード例 #32
0
 def test_mul(self):
     """ Test multiplying an LDAPValueList. """
     lvl = LDAPValueList((1, 2, 3))
     self.assertRaises(TypeError, lambda: lvl * 3)
コード例 #33
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_clear():
    """ Test setting LDAPValueList's clear method. """
    lvl = LDAPValueList((1, 2, 3))
    lvl.append(4)
    lvl.clear()
    assert lvl == []
コード例 #34
0
 def test_append(self):
     """ Test LDAPValueList's append method. """
     lvl = LDAPValueList()
     lvl.append("test")
     self.assertRaises(ValueError, lambda: lvl.append("Test"))
コード例 #35
0
def test_clear():
    """ Test setting LDAPValueList's clear method. """
    lvl = LDAPValueList((1, 2, 3))
    lvl.append(4)
    lvl.clear()
    assert lvl == []
コード例 #36
0
 def test_insert(self):
     """ Test LDAPValueList's insert method. """
     lvl = LDAPValueList(("test1", ))
     lvl.insert(0, "test2")
     self.assertEqual(lvl, ["test2", "test1"])
     self.assertRaises(ValueError, lambda: lvl.insert(2, "test2"))
コード例 #37
0
 def test_copy(self):
     """ Test LDAPValueList's copy method. """
     lvl1 = LDAPValueList(("test1", "test2"))
     lvl2 = lvl1.copy()
     self.assertEqual(lvl1, lvl2)
     self.assertEqual(lvl1.status, lvl2.status)
コード例 #38
0
ファイル: test_ldapvaluelist.py プロジェクト: Noirello/bonsai
def test_copy():
    """ Test LDAPValueList's copy method. """
    lvl1 = LDAPValueList(("test1", "test2"))
    lvl2 = lvl1.copy()
    assert lvl1 == lvl2
    assert lvl1.status == lvl2.status
コード例 #39
0
 def test_clear(self):
     """ Test setting LDAPValueList's clear method. """
     lvl = LDAPValueList((1,2,3))
     lvl.append(4)
     lvl.clear()
     self.assertEqual(lvl, [])
コード例 #40
0
 def test_clear(self):
     """ Test setting LDAPValueList's clear method. """
     lvl = LDAPValueList((1, 2, 3))
     lvl.append(4)
     lvl.clear()
     self.assertEqual(lvl, [])