How to use get_cache method in avocado

Best Python code snippet using avocado_python

atm_tests.py

Source:atm_tests.py Github

copy

Full Screen

...15s3_path = "cache/"16class ATMTests(unittest.TestCase):17 def test_s3_get(self):18 teller = ATM(s3_cache_dir)19 s3_content = teller.get_cache(s3_file).content20 requests_content = requests.get(s3_file).content21 assert s3_content == requests_content22 def test_is_s3_uri(self):23 assert is_s3_uri(s3_cache_dir)24 def test_parse_s3_uri(self):25 bucket, path = parse_s3_uri(s3_cache_dir)26 assert bucket == s3_bucket and path == s3_path27 def test__url_to_filepath(self):28 filepath1 = local_cache_dir + '/' + sha1(url).hexdigest() + '.txt'29 teller = ATM(local_cache_dir)30 filepath2 = teller._url_to_filepath(url, interval_string=None)31 # remove cache directory32 shutil.rmtree(local_cache_dir)33 # test34 assert filepath1 == filepath235 def test_local_liquidate(self):36 teller = ATM(local_cache_dir)37 r = teller.get_cache(url)38 r = teller.get_cache(url2)39 files = [f for f in teller.liquidate()]40 # remove cache directory41 shutil.rmtree(local_cache_dir)42 assert len(files) == 243 def test_local_statement(self):44 teller = ATM(local_cache_dir)45 r = teller.get_cache(url)46 r = teller.get_cache(url2)47 # statement48 statement = teller.statement()49 # remove cache directory50 shutil.rmtree(local_cache_dir)51 assert len(statement) == 2 52 def test_local_default(self):53 teller = ATM(local_cache_dir)54 r = teller.get_cache(url)55 r = teller.get_cache(url2)56 statement1 = teller.statement()57 # now delete58 teller.default()59 # statement again60 statement2 = teller.statement()61 # remove cache directory62 shutil.rmtree(local_cache_dir)63 assert len(statement1) == 2 and len(statement2) == 064 def test_local_interval(self):65 teller = ATM(local_cache_dir, interval=10)66 r = teller.get_cache(url)67 r = teller.get_cache(url)68 time.sleep(10)69 r = teller.get_cache(url)70 statement = teller.statement()71 72 # remove cache directory73 shutil.rmtree(local_cache_dir)74 # test75 assert len(statement)==276 def test_s3_liquidate(self):77 teller = ATM(s3_cache_dir)78 r = teller.get_cache(url)79 r = teller.get_cache(url2)80 81 assets = [f for f in teller.liquidate()]82 # remove files83 teller.default()84 assert len(assets) == 285 def test_s3_statement(self):86 teller = ATM(s3_cache_dir)87 r = teller.get_cache(url)88 r = teller.get_cache(url2)89 # get statement90 statement = teller.statement()91 # remove files92 teller.default()93 assert len(statement) == 2 94 def test_s3_default(self):95 teller = ATM(s3_cache_dir)96 r = teller.get_cache(url)97 r = teller.get_cache(url2)98 statement1 = teller.statement()99 # now delete100 teller.default()101 # statement again102 statement2 = teller.statement()103 # remove files104 teller.default()105 assert len(statement1) == 2 and len(statement2) == 0106 def test_s3_interval(self):107 teller = ATM(s3_cache_dir, interval=10)108 109 # remove cache directory110 teller.default()111 r = teller.get_cache(url)112 r = teller.get_cache(url)113 time.sleep(10)114 r = teller.get_cache(url)115 statement = teller.statement()116 # remove cache directory117 teller.default()118 # test119 assert len(statement)==2120 def test_source(self):121 teller = ATM(s3_cache_dir, interval=10)122 r = teller.get_cache(url)123 source1 = r.source124 r = teller.get_cache(url)125 source2 = r.source126 teller.default()...

Full Screen

Full Screen

fallback_cache.py

Source:fallback_cache.py Github

copy

Full Screen

...3class FallbackCache(BaseCache):4 def __init__(self, config, params): # NOQA BaseCache uses params but others use both.5 super().__init__(params)6 def add(self, *args, **kwargs):7 return get_cache().add(*args, **kwargs)8 def clear(self):9 return get_cache().clear()10 def close(self, *args, **kwargs):11 return get_cache().close(*args, **kwargs)12 def decr(self, *args, **kwargs):13 return get_cache().decr(*args, **kwargs)14 def decr_version(self, *args, **kwargs):15 return get_cache().decr_version(*args, **kwargs)16 def delete(self, *args, **kwargs):17 return get_cache().delete(*args, **kwargs)18 def delete_many(self, *args, **kwargs):19 return get_cache().delete_many(*args, **kwargs)20 def get(self, *args, **kwargs):21 return get_cache().get(*args, **kwargs)22 def get_backend_timeout(self, *args, **kwargs):23 return get_cache().get_backend_timeout(*args, **kwargs)24 def get_many(self, *args, **kwargs):25 return get_cache().get_many(*args, **kwargs)26 def get_or_set(self, *args, **kwargs):27 return get_cache().get_or_set(*args, **kwargs)28 def has_key(self, *args, **kwargs):29 return get_cache().has_key(*args, **kwargs) # NOQA has_key deprecation warning doesn't apply here.30 def incr(self, *args, **kwargs):31 return get_cache().incr(*args, **kwargs)32 def incr_version(self, *args, **kwargs):33 return get_cache().incr_version(*args, **kwargs)34 def make_key(self, *args, **kwargs):35 return get_cache().make_key(*args, **kwargs)36 def set(self, *args, **kwargs):37 return get_cache().set(*args, **kwargs)38 def set_many(self, *args, **kwargs):39 return get_cache().set_many(*args, **kwargs)40 def touch(self, *args, **kwargs):41 return get_cache().touch(*args, **kwargs)42 def validate_key(self, *args, **kwargs):43 return get_cache().validate_key(*args, **kwargs)44def get_cache():45 if caches["primary_cache"].get("primary_cache"):46 return caches["primary_cache"]47 caches["primary_cache"].set("primary_cache", True)48 if caches["primary_cache"].get("primary_cache"):49 return caches["primary_cache"]...

Full Screen

Full Screen

test_cache.py

Source:test_cache.py Github

copy

Full Screen

...4class CommonTests(object):5 def test_set_cache(self):6 set_cache = self.cache.set('test_key', ['a', 'b', 'c'])7 self.assertTrue(set_cache)8 def test_get_cache(self):9 set_cache = self.cache.set('test_key', ['a', 'b', 'c'])10 self.assertTrue(set_cache)11 get_cache = self.cache.get('test_key')12 self.assertEqual(get_cache, ['a', 'b', 'c'])13 def test_delete_cache(self):14 set_cache = self.cache.set('test_key', ['a', 'b', 'c'])15 self.assertTrue(set_cache)16 get_cache = self.cache.get('test_key')17 self.assertEqual(get_cache, ['a', 'b', 'c'])18 self.cache.delete('test_key')19 get_cache = self.cache.get('test_key')20 self.assertFalse(get_cache)21 def test_delete_wildcard(self):22 set_cache = self.cache.set('test_key:1', ['a', 'b', 'c'])23 self.assertTrue(set_cache)24 get_cache = self.cache.get('test_key:1')25 self.assertEqual(get_cache, ['a', 'b', 'c'])26 set_cache = self.cache.set('test_key:2', ['a', 'b', 'c'])27 self.assertTrue(set_cache)28 get_cache = self.cache.get('test_key:2')29 self.assertEqual(get_cache, ['a', 'b', 'c'])30 self.cache.delete_wildard('test_key')31 get_cache = self.cache.get('test_key:1')32 self.assertFalse(get_cache)33 get_cache = self.cache.get('test_key:2')34 self.assertFalse(get_cache)35class TestFileCache(BaseTest, CommonTests):36 def setUp(self):37 os.environ['CACHE_TYPE'] = 'file'38 super().setUp()39class TestNullCache(BaseTest, CommonTests):40 def setUp(self):41 os.environ['CACHE_TYPE'] = 'null'42 super().setUp()43 def test_get_cache(self):44 set_cache = self.cache.set('test_key', ['a', 'b', 'c'])45 self.assertTrue(set_cache)46 get_cache = self.cache.get('test_key')47 self.assertFalse(get_cache)48 def test_delete_cache(self):49 pass50 def test_delete_wildcard(self):51 pass52class TestRedisCache(BaseTest, CommonTests):53 def setUp(self):54 os.environ['CACHE_TYPE'] = 'redis'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful