]> git.scottworley.com Git - paperdoorknob/blobdiff - fetch_test.py
Learning TeX: Render icon images with TeX command
[paperdoorknob] / fetch_test.py
index 6bdf69ecc2a39e93f1903d15ce8a5fd8eea1ddf3..59a1514853d3f370fe233b2a883c5f8ad196ad88 100644 (file)
@@ -5,8 +5,11 @@
 # Free Software Foundation, version 3.
 
 
 # Free Software Foundation, version 3.
 
 
+from io import StringIO
 import unittest
 import unittest
+
 from requests import HTTPError
 from requests import HTTPError
+
 from testing.fakeserver import FakeGlowficServer
 from fetch import CachingFetcher, DirectFetcher
 
 from testing.fakeserver import FakeGlowficServer
 from fetch import CachingFetcher, DirectFetcher
 
@@ -40,6 +43,16 @@ class TestFetch(unittest.TestCase):
             f.fetch(f"http://localhost:{self._port}")
             self.assertEqual(self._server.request_count(), 1)
 
             f.fetch(f"http://localhost:{self._port}")
             self.assertEqual(self._server.request_count(), 1)
 
+    def testCacheHitRateReport(self) -> None:
+        buf = StringIO()
+
+        def log(msg: str) -> None:
+            print(msg, file=buf)
+        with CachingFetcher("testcachehitratereportwithcl", TIMEOUT, log) as f:
+            for _ in range(7):
+                f.fetch(f"http://localhost:{self._port}")
+        self.assertEqual("Fetch cache hits: 6 (85.7%)\n", buf.getvalue())
+
     def testFetchErrors(self) -> None:
         with DirectFetcher(TIMEOUT) as f:
             with self.assertRaises(HTTPError):
     def testFetchErrors(self) -> None:
         with DirectFetcher(TIMEOUT) as f:
             with self.assertRaises(HTTPError):