Example #1
0
    def test_prevent_call(self):
        m = mock.Mock()
        m.return_value = 'value'

        microCache = MicroCache()
        v = None
        for i in range(1000):
            v = microCache.get('key', m)

        self.assertEquals(v, 'value', 'different value')
        self.assertEquals(m.call_count, 1, 'call more then 1 time')
    def test_prevent_call(self):
        m = mock.Mock()
        m.return_value = 'value'

        microCache = MicroCache()
        v = None
        for i in range(1000):
            v = microCache.get('key', m)

        self.assertEquals(v, 'value', 'different value')
        self.assertEquals(m.call_count, 1, 'call more then 1 time')
Example #3
0
    def test_prevent_download(self):
        def download():
            global CALL_COUNT
            CALL_COUNT += 1
            return urllib.urlopen('https://github.com/ebertti/micro-cache').read()

        microCache = MicroCache()
        v = None

        for i in range(1000):
            v = microCache.get('key', download)

        self.assertEquals(CALL_COUNT, 1, 'call more then 1 time')
        self.assertEquals(microCache.get('key'), v, 'html download is not equal')
    def test_prevent_download(self):
        def download():
            global CALL_COUNT
            CALL_COUNT += 1
            pwd = os.path.realpath(os.path.dirname(__file__))
            html_file = os.path.join(pwd, 'html_test.html')
            return urllib.urlopen(html_file).read()

        microCache = MicroCache()
        v = None

        for i in range(1000):
            v = microCache.get('key', download)

        self.assertEquals(CALL_COUNT, 1, 'call more then 1 time')
        self.assertEquals(microCache.get('key'), v, 'html download is not equal')
Example #5
0
    def test_prevent_download(self):
        def download():
            global CALL_COUNT
            CALL_COUNT += 1
            pwd = os.path.realpath(os.path.dirname(__file__))
            html_file = os.path.join(pwd, 'html_test.html')
            return urllib.urlopen(html_file).read()

        microCache = MicroCache()
        v = None

        for i in range(1000):
            v = microCache.get('key', download)

        self.assertEquals(CALL_COUNT, 1, 'call more then 1 time')
        self.assertEquals(microCache.get('key'), v,
                          'html download is not equal')
 def test_set(self):
     microCache = MicroCache()
     v = "value"
     microCache.set("key", v)
     self.assertEqual("value", microCache.get("key"))
 def test_use_with_getitems(self):
     microCache = MicroCache()
     v = lambda  : 'value'
     microCache.update('key', v)
     self.assertEqual('value', microCache['key'])
Example #8
0
 def test_set(self):
     microCache = MicroCache()
     v = "value"
     microCache.set("key", v)
     self.assertEqual("value", microCache.get("key"))
Example #9
0
 def test_use_with_call(self):
     microCache = MicroCache()
     v = lambda: 'value'
     a = microCache('key', v)
     self.assertEqual('value', a)
Example #10
0
 def test_use_with_getitems(self):
     microCache = MicroCache()
     v = lambda: 'value'
     microCache.update('key', v)
     self.assertEqual('value', microCache['key'])