-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_translation.py
43 lines (31 loc) · 1.23 KB
/
test_translation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
from cache import Db
from tempfile import mkdtemp
from translation import CachingClient
class TestCachingClient(unittest.TestCase):
class MockTranslator:
def translate(self, values):
return values
def setUp(self):
dirname = mkdtemp(suffix='cachingclient', prefix='teststorage')
self.db = Db(dirname, 'en')
self.translation_caching_client = CachingClient(self.MockTranslator(), self.db)
def teadDown(self):
self.translation_caching_client.close()
def test_hits_and_misses(self):
members = 10
times = 5
for i in range(0, members * times):
_ = self.translation_caching_client.translate(str(i % members))
stats = self.translation_caching_client.stats()
self.assertEqual(stats['misses'], members)
self.assertEqual(stats['hits'], (members * times) - members)
def test_misses(self):
members = 43
for i in range(0, members):
_ = self.translation_caching_client.translate(str(i))
stats = self.translation_caching_client.stats()
self.assertEqual(stats['misses'], members)
self.assertEqual(stats['hits'], 0)
if __name__ == '__main__':
unittest.main()