def test_cacheRemovesOldest(self):
        """
        Verify that when the cache is full, and a new entry is added,
        the oldest entry is removed.
        """
        trustRoot = CustomOpenSSLTrustRoot()
        wrappedPolicy = BrowserLikePolicyForHTTPS(trustRoot=trustRoot)
        policy = HostnameCachingHTTPSPolicy(wrappedPolicy)
        for i in range(0, 20):
            hostname = u"host" + unicode(i)
            policy.creatorForNetloc(hostname.encode("ascii"), 8675)

        # Force host0, which was the first, to be the most recently used
        host0 = u"host0"
        policy.creatorForNetloc(host0.encode("ascii"), 309)
        self.assertIn(host0, policy._cache)
        self.assertEquals(20, len(policy._cache))

        hostn = u"new"
        policy.creatorForNetloc(hostn.encode("ascii"), 309)

        host1 = u"host1"
        self.assertNotIn(host1, policy._cache)
        self.assertEquals(20, len(policy._cache))

        self.assertIn(hostn, policy._cache)
        self.assertIn(host0, policy._cache)

        # Accessing an item repeatedly does not corrupt the LRU.
        for _ in range(20):
            policy.creatorForNetloc(host0.encode("ascii"), 8675)

        hostNPlus1 = u"new1"

        policy.creatorForNetloc(hostNPlus1.encode("ascii"), 800)

        self.assertNotIn(u"host2", policy._cache)
        self.assertEquals(20, len(policy._cache))

        self.assertIn(hostNPlus1, policy._cache)
        self.assertIn(hostn, policy._cache)
        self.assertIn(host0, policy._cache)

        Verify that when the cache is full, and a new entry is added,
        the oldest entry is removed.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_agent.py