def test_filter(self):
        for k in range(-10, 11):
            cutoff = k * 11

            def _filter(item):
                if item <= cutoff:
                    return True

            items = list(range(-1000, 1000))
            random.shuffle(items)
            q = _NoThreadingLIFOQueue()
            for i in items:
                q.put(i)
            correct = []
            removed = []
            for _, item in q._items:
                if item <= cutoff:
                    correct.append(item)
                else:
                    removed.append(item)
            removed_ = q.filter(_filter)
            assert removed_ == removed
            check = []
            for _, item in q._items:
                check.append(item)
            assert sorted(correct) == sorted(check)
        for k in range(-10, 11):
            cutoff = k * 11

            def _filter(item):
                if item <= cutoff:
                    return True

            items = list(range(-1000, 1000))
            random.shuffle(items)
            q = _NoThreadingLIFOQueue()
            for i in items:
                q.put(i)
            correct = []
            removed = []
            for cnt, item in q._items:
                if item <= cutoff:
                    correct.append(item)
                else:
                    removed.append((cnt, item))
            removed_ = q.filter(_filter, include_counters=True)
            assert removed_ == removed
            check = []
            for _, item in q._items:
                check.append(item)
            assert sorted(correct) == sorted(check)
 def test_put_get(self):
     q = _NoThreadingLIFOQueue()
     with pytest.raises(ValueError):
         q.put(None)
     with pytest.raises(ValueError):
         q.put_get(None)
     assert list(q.items()) == []
     assert q.put_get(1) == (0, 1)
     assert q.put_get(1) == (1, 1)
     cntr = {}
     cntr[1] = q.put(1)
     assert list(q.items()) == [1]
     cntr[2] = q.put(2)
     assert list(q.items()) == [1, 2]
     cntr[3] = q.put(3)
     assert list(q.items()) == [1, 2, 3]
     cntr[4], item_ = q.put_get(4)
     assert item_ == 4
     assert list(q.items()) == [1, 2, 3]
     assert q.next() == (cntr[q.next()[1]], 3)
     assert q.get() == 3
     assert list(q.items()) == [1, 2]
     assert q.next() == (cntr[q.next()[1]], 2)
     assert q.get() == 2
     assert list(q.items()) == [1]
     assert q.next() == (cntr[q.next()[1]], 1)
     assert q.get() == 1
     assert list(q.items()) == []
     with pytest.raises(IndexError):
         q.next()
 def test_size(self):
     q = _NoThreadingLIFOQueue()
     assert q.size() == 0
     with pytest.raises(IndexError):
         q.next()
     cntr = {}
     for i in range(10):
         cntr[i] = q.put(i)
         assert q.size() == i + 1
     for i in reversed(range(10)):
         c_, x_ = q.next()
         assert c_ == cntr[x_]
         x = q.get()
         assert x_ == x
         assert x == i
         assert q.size() == i
     assert q.size() == 0
     assert q.get() is None
     with pytest.raises(IndexError):
         q.next()