from domfilter import ApplyDOMFilters, DOMFilters
from fetch import CachingFetcher
from htmlfilter import ApplyHTMLFilters, HTMLFilters
-from images import ImageStore
+from images import DiskImageStore
from spec import Spec
from texify import PandocTexifier
yield Spec(
args.url,
fetcher,
- ImageStore(args.out + '_images', fetcher),
+ DiskImageStore(args.out + '_images', fetcher),
lambda x: ApplyHTMLFilters(args.htmlfilters, x),
lambda x: ApplyDOMFilters(args.domfilters, x),
PandocTexifier(args.pandoc or 'pandoc'),
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, version 3.
+from abc import ABC, abstractmethod
import os
import os.path
from fetch import Fetcher
+class ImageStore(ABC):
+
+ @abstractmethod
+ def get_image(self, url: str) -> str:
+ raise NotImplementedError()
+
+
class ImageStoreError(Exception):
pass
-class ImageStore:
+class DiskImageStore(ImageStore):
def __init__(self, root_path: str, fetcher: Fetcher) -> None:
self._root_path = root_path
self._filenames.add(name)
self._images[url] = path
return self._images[url]
+
+
+class FakeImageStore(ImageStore):
+
+ def get_image(self, url: str) -> str:
+ return 'stored:' + url
import unittest
from fetch import FakeFetcher
-from images import ImageStore
+from images import DiskImageStore
class TestImageStore(unittest.TestCase):
'https://example.com/other_images/carol': b'CAROLINA'})
def testFetchOnce(self) -> None:
- store = ImageStore('istest_fetch_once', self._fetcher)
+ store = DiskImageStore('istest_fetch_once', self._fetcher)
self.assertEqual(self._fetcher.request_count(), 0)
a1 = store.get_image('https://example.com/images/alice.png')
self.assertEqual(self._fetcher.request_count(), 1)
self.assertEqual(a1, a3)
def testNameCollision(self) -> None:
- store = ImageStore('istest_name_collision', self._fetcher)
+ store = DiskImageStore('istest_name_collision', self._fetcher)
self.assertEqual(self._fetcher.request_count(), 0)
b1 = store.get_image('https://example.com/images/bob.jpeg')
self.assertEqual(self._fetcher.request_count(), 1)
from testing.fakeserver import FakeGlowficServer
from domfilter import ApplyDOMFilters
from fetch import DirectFetcher, FakeFetcher, Fetcher
-from images import ImageStore
+from images import FakeImageStore
from spec import Spec
from texify import DirectTexifier, PandocTexifier, VerifyingTexifier
spec = Spec(
self.url(),
self.fetcher(),
- ImageStore('is', self.fetcher()),
+ FakeImageStore(),
lambda x: x,
lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
PandocTexifier('pandoc'),
spec = Spec(
self.url(),
self.fetcher(),
- ImageStore('is', self.fetcher()),
+ FakeImageStore(),
lambda x: x,
lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
texifier,
spec = Spec(
self.url(),
self.fetcher(),
- ImageStore('is', self.fetcher()),
+ FakeImageStore(),
lambda x: x,
lambda x: ApplyDOMFilters('NoEdit,NoFooter', x),
PandocTexifier('pandoc'),