Best Python code snippet using localstack_python
usage.py
Source:usage.py
...87 for index, bit in enumerate(bits):88 bit and lst.append(args[index])89 header_usage = UHeaderData(lst)90 return header_usage91def get_usage(name, flags=0):92 count = get_number_of_example(name)93 name = str(name).lower()94 header_usage = get_usage_header(name, flags=flags)95 lst = ['{} {} operands [options]'.format(tool, name)]96 if count > 0:97 lst1 = list(map(str, range(1, count + 1)))98 s = lst1[0] if len(lst1) == 1 else '{%s}' % (','.join(lst1))99 lst.append('%s %s example %s' % (tool, name, s))100 body_usage = UBodyData(*lst)101 usage = UsageData(header_usage, body_usage)102 return usage103def get_example_usage(name):104 count = get_number_of_example(name)105 name = str(name).lower()106 fmt = '{} {} example {}'107 example_usage = UsageData(108 UHeaderData('{} {} example syntax:'.format(tool, name)),109 UBodyData(*[fmt.format(tool, name, i + 1) for i in range(count)])110 )111 return example_usage112class ConfigureUsage:113 usage = get_usage('configure', flags=FLAG.HOST | FLAG.HELP)114 other_usage = get_usage('configure', flags=FLAG.HOST)115 example_usage = get_example_usage('configure')116class ConnectUsage:117 usage = get_usage('connect', flags=FLAG.HOST | FLAG.HELP)118 other_usage = get_usage('connect', flags=FLAG.HOST | FLAG.HELP)119 example_usage = get_example_usage('connect')120class DisconnectUsage:121 usage = get_usage('disconnect', flags=FLAG.HOST | FLAG.HELP)122 other_usage = get_usage('disconnect', flags=FLAG.HOST | FLAG.HELP)123 example_usage = get_example_usage('disconnect')124class DestroyUsage:125 usage = get_usage('destroy', flags=FLAG.HOST | FLAG.HELP)126 other_usage = get_usage('destroy', flags=FLAG.HOST | FLAG.HELP)127 example_usage = get_example_usage('destroy')128class ExecuteUsage:129 usage = get_usage('execute', flags=FLAG.HOST | FLAG.HELP)130 other_usage = get_usage('execute', flags=FLAG.HOST | FLAG.HELP)131 example_usage = get_example_usage('execute')132class InfoUsage:133 usage = get_usage('info', flags=FLAG.INFO_USAGE)134 other_usage = get_usage('info', flags=FLAG.INFO_USAGE)135 example_usage = get_example_usage('info')136class ListUsage:137 usage = get_usage('list', flags=FLAG.HOST | FLAG.HELP)138 other_usage = get_usage('list', flags=FLAG.HOST | FLAG.HELP)139 example_usage = get_example_usage('list')140class LoadUsage:141 usage = get_usage('load', flags=FLAG.FILENAME | FLAG.SAVE | FLAG.HELP)142 other_usage = get_usage('load', flags=FLAG.FILENAME | FLAG.SAVE | FLAG.HELP)143 example_usage = get_example_usage('load')144class ReleaseUsage:145 usage = get_usage('release', flags=FLAG.HOST | FLAG.HELP)146 other_usage = get_usage('release', flags=FLAG.HOST | FLAG.HELP)147 example_usage = get_example_usage('release')148class ReloadUsage:149 usage = get_usage('reload', flags=FLAG.HOST | FLAG.HELP)150 other_usage = get_usage('reload', flags=FLAG.HOST | FLAG.HELP)151 example_usage = get_example_usage('reload')152class ViewUsage:153 usage = get_usage('view', flags=FLAG.VIEW_USAGE)154 other_usage = get_usage('view', flags=FLAG.VIEW_USAGE)155 example_usage = get_example_usage('view')156class Usage:157 configure = ConfigureUsage158 connect = ConnectUsage159 disconnect = DisconnectUsage160 destroy = DestroyUsage161 execute = ExecuteUsage162 info = InfoUsage163 list = ListUsage164 load = LoadUsage165 reload = ReloadUsage166 release = ReleaseUsage167 view = ViewUsage168def validate_usage(name, operands):...
rate_limit_test.py
Source:rate_limit_test.py
...22 """23 Should raise TooManyRequests Exception when trying to increment for the24 eleventh time.25 """26 self.assertEqual(self.rate_limit.get_usage(), 0)27 self.assertEqual(self.rate_limit.has_been_reached(), False)28 self._make_10_requests()29 self.assertEqual(self.rate_limit.get_usage(), 10)30 self.assertEqual(self.rate_limit.has_been_reached(), True)31 with self.assertRaises(TooManyRequests):32 with self.rate_limit:33 pass34 self.assertEqual(self.rate_limit.get_usage(), 11)35 self.assertEqual(self.rate_limit.has_been_reached(), True)36 def test_expire(self):37 """38 Should not raise TooManyRequests Exception when trying to increment for39 the eleventh time after the expire time.40 """41 self._make_10_requests()42 time.sleep(1)43 with self.rate_limit:44 pass45 def test_not_expired(self):46 """47 Should raise TooManyRequests Exception when the expire time has not48 been reached yet.49 """50 self.rate_limit = RateLimit(resource='test', client='localhost',51 max_requests=10, expire=2)52 self._make_10_requests()53 time.sleep(1)54 with self.assertRaises(TooManyRequests):55 with self.rate_limit:56 pass57 def test_limit_10_using_rate_limiter(self):58 """59 Should raise TooManyRequests Exception when trying to increment for the60 eleventh time.61 """62 self.rate_limit = RateLimiter(resource='test', max_requests=10,63 expire=2).limit(client='localhost')64 self.assertEqual(self.rate_limit.get_usage(), 0)65 self.assertEqual(self.rate_limit.has_been_reached(), False)66 self._make_10_requests()67 self.assertEqual(self.rate_limit.get_usage(), 10)68 self.assertEqual(self.rate_limit.has_been_reached(), True)69 with self.assertRaises(TooManyRequests):70 with self.rate_limit:71 pass72 self.assertEqual(self.rate_limit.get_usage(), 11)73 self.assertEqual(self.rate_limit.has_been_reached(), True)74 def test_wait_time_limit_reached(self):75 """76 Should report wait time approximately equal to expire after reaching77 the limit without delay between requests.78 """79 self.rate_limit = RateLimit(resource='test', client='localhost',80 max_requests=10, expire=1)81 self._make_10_requests()82 with self.assertRaises(TooManyRequests):83 with self.rate_limit:84 pass85 self.assertAlmostEqual(self.rate_limit.get_wait_time(), 1, places=2)86 def test_wait_time_limit_expired(self):87 """88 Should report wait time equal to expire / max_requests before any89 requests were made and after the limit has expired.90 """91 self.rate_limit = RateLimit(resource='test', client='localhost',92 max_requests=10, expire=1)93 self.assertEqual(self.rate_limit.get_wait_time(), 1./10)94 self._make_10_requests()95 time.sleep(1)96 self.assertEqual(self.rate_limit.get_wait_time(), 1./10)97 98 def test_context_manager_returns_usage(self):99 """100 Should return the usage when used as a context manager.101 """102 self.rate_limit = RateLimit(resource='test', client='localhost',103 max_requests=1, expire=1)104 with self.rate_limit as usage:105 self.assertEqual(usage, 1)106 def test_limit_10_using_as_decorator(self):107 """108 Should raise TooManyRequests Exception when trying to increment for the109 eleventh time.110 """111 self.assertEqual(self.rate_limit.get_usage(), 0)112 self.assertEqual(self.rate_limit.has_been_reached(), False)113 self._make_10_requests()114 self.assertEqual(self.rate_limit.get_usage(), 10)115 self.assertEqual(self.rate_limit.has_been_reached(), True)116 @self.rate_limit117 def limit_with_decorator():118 pass119 with self.assertRaises(TooManyRequests):120 limit_with_decorator()121 self.assertEqual(self.rate_limit.get_usage(), 11)122 self.assertEqual(self.rate_limit.has_been_reached(), True)123 def test_increment_multiple(self):124 """125 Test incrementing usage by a value > 1126 """127 self.rate_limit.increment_usage(7)128 self.rate_limit.increment_usage(3)129 self.assertEqual(self.rate_limit.get_usage(), 10)130 self.assertEqual(self.rate_limit.has_been_reached(), True)131 with self.assertRaises(TooManyRequests):132 self.rate_limit.increment_usage(1)133 self.assertEqual(self.rate_limit.get_usage(), 11)134 self.assertEqual(self.rate_limit.has_been_reached(), True)135 with self.assertRaises(TooManyRequests):136 self.rate_limit.increment_usage(5)137 self.assertEqual(self.rate_limit.get_usage(), 16)138 self.assertEqual(self.rate_limit.has_been_reached(), True)139 def test_increment_multiple_too_much(self):140 """141 Test that we cannot bulk-increment a value higher than142 the bucket limit.143 """144 with self.assertRaises(ValueError):145 self.rate_limit.increment_usage(11)146 self.assertEqual(self.rate_limit.get_usage(), 0)147 self.assertEqual(self.rate_limit.has_been_reached(), False)148 def test_increment_by_zero(self):149 """150 Should not allow increment by zero.151 """152 self.assertEqual(self.rate_limit.get_usage(), 0)153 self.assertEqual(self.rate_limit.has_been_reached(), False)154 self.rate_limit.increment_usage(5)155 self.assertEqual(self.rate_limit.get_usage(), 5)156 self.assertEqual(self.rate_limit.has_been_reached(), False)157 with self.assertRaises(ValueError):158 self.rate_limit.increment_usage(0)159 self.assertEqual(self.rate_limit.get_usage(), 5)160 self.assertEqual(self.rate_limit.has_been_reached(), False)161 def test_increment_by_negative(self):162 """163 Should not allow decrement the counter.164 """165 self.assertEqual(self.rate_limit.get_usage(), 0)166 self.assertEqual(self.rate_limit.has_been_reached(), False)167 with self.assertRaises(ValueError):168 self.rate_limit.increment_usage(-5)169 self.assertEqual(self.rate_limit.get_usage(), 0)170 self.assertEqual(self.rate_limit.has_been_reached(), False)171if __name__ == '__main__':...
main_controller.py
Source:main_controller.py
1from .main.get_home import get_home2from .main.get_about import get_about3from .main.get_usage import get_usage4from .main.get_math import get_math5# Create dictionary to store references relevant functions6main_controller = {7 'get_home': get_home,8 'get_about': get_about,9 'get_usage': get_usage,10 'get_math': get_math...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!