How to use _patch_time method in tempest

Best Python code snippet using tempest_python

test_cache_client.py

Source:test_cache_client.py Github

copy

Full Screen

...13 self.cache = MemoryTTLCache()14 def test_get_nonexistent(self):15 self.assertIsNone(self.cache.get('key'))16 def test_set_get_within_ttl(self):17 with self._patch_time(1):18 self.cache.set('key', 'value', 1000)19 self.assertEqual(self.cache.get('key'), 'value')20 def test_set_get_past_ttl(self):21 with self._patch_time(1):22 self.cache.set('key', 'value', 1000)23 with self._patch_time(3):24 self.assertIsNone(self.cache.get('key'))25 def test_delete_within_ttl(self):26 with self._patch_time(1):27 self.cache.set('key', 'value', 1000)28 self.assertEqual(self.cache.get('key'), 'value')29 self.cache.delete('key')30 self.assertIsNone(self.cache.get('key'))31 def test_delete_past_ttl(self):32 with self._patch_time(1):33 self.cache.set('key', 'value', 1000)34 with self._patch_time(3):35 self.cache.delete('key')36 self.assertIsNone(self.cache.get('key'))37 @staticmethod38 def _patch_time(timestamp):39 return mock.patch.object(time, 'time', return_value=timestamp)40class TestRedisProxyClient(TestCase):41 @mock.patch.object(redis, 'Redis')42 def setUp(self, *args):43 self.cache = RedisProxyClient('localhost:6379')44 def test_get_redis(self):45 self.cache.redis.get.return_value = 'redis'46 self.assertEqual(self.cache.get('key'), 'redis')47 self.cache.redis.get.assert_called_with('key')48 def test_get_failover(self):49 self.cache.redis.get.return_value = 'redis'50 self.cache.redis.get.side_effect = ConnectionError51 self.assertNotEqual(self.cache.get('key'), 'redis')52 self.cache.redis.get.assert_called_with('key')...

Full Screen

Full Screen

_example_data.py

Source:_example_data.py Github

copy

Full Screen

...18 def __call__(self, name, doc):19 # Emit the modified document to self._callback.20 name, doc = super().__call__(name, doc)21 self._callback(name, doc)22 def _patch_time(self, doc):23 doc = doc.copy()24 doc["time"] -= self._delta25 return doc26 def _patch_time_stamps(self, ts_dict):27 return {k: v - self._delta for k, v in ts_dict.items()}28 def start(self, doc):29 self._delta = doc["time"] - self._t030 return self._patch_time(doc)31 def descriptor(self, doc):32 return self._patch_time(doc)33 def stop(self, doc):34 return self._patch_time(doc)35 def event(self, doc):36 doc = self._patch_time(doc)37 doc["timestamps"] = self._patch_time_stamps(doc["timestamps"])38 return doc39 def event_page(self, doc):40 return self._patch_time(doc)41def generate_example_data(callback):42 from ophyd.sim import det, motor1, motor2, motor343 motor1.set(3.1).wait()44 motor2.set(-1000.02).wait()45 motor3.set(5.01).wait()46 RE = RunEngine()47 sd = SupplementalData(baseline=[motor1, motor2, motor3])48 RE.preprocessors.append(sd)49 RE.md["operator"] = "Dmitri"50 RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:00", callback))51 RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:05", callback))52 RE(count([det], 5, delay=0.05), RewriteTimes("2020-01-01 9:07", callback))53 RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 9:00", callback))54 RE(count([det], 5, delay=0.05), RewriteTimes("2020-02-01 9:05", callback))...

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 tempest 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