How to use do_stuff method in hypothesis

Best Python code snippet using hypothesis

test_caching.py

Source:test_caching.py Github

copy

Full Screen

...40 global executions41 executions += 142 return "do_stuff_overriden"43 @cache()44 def do_stuff(self, number):45 global executions46 executions += 147 return number + 148 @cache()49 def do_stuff_cancel(self, number):50 global executions51 cache.cancel()52 executions += 153 return number - 154 @cache()55 def do_stuff_raises(self, number):56 global executions57 executions += 158 raise NotImplementedError()59 return number60class WithCacheIdOverride(object):61 def __init__(self, value):62 self.value = value63 def cache_id(self):64 return self.value65 @cache()66 def do_stuff(self, number):67 global executions68 executions += 169 return number70@cache()71def do_stuff(x=None):72 global executions73 executions += 174 return 175@cache()76def do_stuff_no_return(x=None):77 global executions78 executions += 179 return None80@cache()81def do_stuff_parallel(x=None):82 global executions83 executions += 184 while executions < 2:85 time.sleep(0.1)86 return 187@pytest.mark.basic88class Test:89 def setup_method(self, method):90 logging.getLogger().setLevel("DEBUG")91 config = ConfigParser().read()92 cache.init(config.get("caching", {}))93 global executions94 executions = 095 cache.wipe()96 def test_cache(self):97 global executions98 c = child()99 c.do_stuff(1)100 c.do_stuff(1)101 assert executions == 1102 c.do_stuff(2)103 assert executions == 2104 c.do_stuff(1)105 assert executions == 2106 def test_cache_two_objects(self):107 global executions108 c1 = child()109 c2 = child()110 c1.do_stuff(1)111 c2.do_stuff(1)112 assert executions == 1113 c2.diff = True # changes the pickle of c2114 c2.do_stuff(1)115 assert executions == 2116 c1.diff = True # now they are the same117 c1.do_stuff(1)118 assert executions == 2119 def test_cache_no_cache_inherited(self):120 global executions121 b = base()122 b.do_stuff_base(1)123 b.do_stuff_base(1)124 assert executions == 1125 c = child()126 child()127 c.do_stuff_base(1)128 assert executions == 2129 c.do_stuff_base(1) # not cached, decorator doesn't apply130 assert executions == 3131 def test_cache_cancelled(self):132 global executions133 c = child()134 c.do_stuff_cancel(1)135 assert executions == 1136 c.do_stuff_cancel(1) # not cached, function cancelled it137 assert executions == 2138 def test_cache_raised(self):139 global executions140 c = child()141 with pytest.raises(NotImplementedError):142 c.do_stuff_raises(1)143 assert executions == 1144 with pytest.raises(NotImplementedError):145 c.do_stuff_raises(1) # not cached, first call raised exception146 assert executions == 2147 def test_cache_function(self):148 global executions149 do_stuff()150 assert executions == 1151 do_stuff()152 assert executions == 1153 do_stuff("hello")154 assert executions == 2155 do_stuff({"a": {"b": "c"}})156 assert executions == 3157 do_stuff({"a": {"b": "d"}})158 assert executions == 4159 do_stuff({"a": {"b": "c"}})160 assert executions == 4161 do_stuff({"a": {"b": "d"}})162 assert executions == 4163 def test_cache_function_none(self):164 global executions165 do_stuff_no_return()166 assert executions == 1167 do_stuff_no_return()168 assert executions == 1169 def test_cache_two_objects_with_cache_id(self):170 a = WithCacheIdOverride("a")171 a2 = WithCacheIdOverride("a")172 a2.i_am_different_now = "xyz"173 b = WithCacheIdOverride("b")174 a.do_stuff(1)175 assert executions == 1176 a2.do_stuff(1)177 assert executions == 1178 a2.do_stuff(2)179 assert executions == 2180 a.do_stuff(2)181 assert executions == 2182 b.do_stuff(1)183 assert executions == 3184 b.do_stuff(3)185 assert executions == 4186 a.do_stuff(3)187 assert executions == 5188 def test_cache_parallel(self):189 # POLY-231: where a cacheable functions runs in parallel it may try to cache twice190 thread_pool = concurrent.futures.ThreadPoolExecutor(2)191 t1 = thread_pool.submit(do_stuff_parallel, (1,))192 t2 = thread_pool.submit(do_stuff_parallel, (1,))193 t1.result()...

Full Screen

Full Screen

test_command_descriptor.py

Source:test_command_descriptor.py Github

copy

Full Screen

...9class CommandDescriptorTester(unittest.TestCase):10 def test_call_name(self):11 class Foo:12 @icpw_command13 def do_stuff(self):14 pass15 foo = Foo()16 self.assertEqual(get_command_object(foo, 'do_stuff').name, 'do_stuff')17 def test_call_local(self):18 """Test creating a command on a method and calling it like a normal19 method."""20 class Foo:21 @icpw_command22 def do_stuff(self, x: Int64):23 self.x = x24 foo = Foo()25 exp_value = 726 foo.do_stuff(exp_value)27 act_value = foo.x28 self.assertEqual(exp_value, act_value)29 def test_call_local_default_args(self):30 """Test calling a command locally with default arguments."""31 def_y = "abc"32 class Foo:33 @icpw_command34 def do_stuff(self, x: Int64, y: String = def_y):35 self.x = x36 self.y = y37 foo = Foo()38 exp_x = 739 exp_y = "hello"40 foo.do_stuff(exp_x, y=exp_y)41 act_x = foo.x42 act_y = foo.y43 self.assertEqual(exp_x, act_x)44 self.assertEqual(exp_y, act_y)45 foo.do_stuff(exp_x)46 act_x = foo.x47 act_y = foo.y48 self.assertEqual(exp_x, act_x)49 self.assertEqual(def_y, act_y)50 def test_call_network(self):51 """Test calling a command via the network interface."""52 class Foo:53 @icpw_command54 def do_stuff(self, x: Int64):55 self.x = x56 class do_stuff(Struct):57 network_name = 'do_stuff'58 x = Field(Int64)59 foo = Foo()60 exp_value = -4261 icypaw_arg = do_stuff({'x': exp_value})62 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)63 self.assertEqual(foo.x, exp_value)64 def test_call_network_default(self):65 """Test calling a command via the network interface with a default66 value."""67 def_y = "abc"68 class Foo:69 @icpw_command70 def do_stuff(self, x: Int64, y: String = def_y):71 self.x = x72 self.y = y73 exp_x = 4274 exp_y = "def"75 class do_stuff(Struct):76 network_name = 'do_stuff'77 x = Field(Int64)78 y = Field(String, default=def_y)79 foo = Foo()80 icypaw_arg = do_stuff({'x': exp_x, 'y': exp_y})81 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)82 self.assertEqual(foo.x, exp_x)83 self.assertEqual(foo.y, exp_y)84 icypaw_arg = do_stuff({'x': exp_x})85 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)86 self.assertEqual(foo.x, exp_x)87 self.assertEqual(foo.y, def_y)88 def test_call_bad_args(self):89 """Test calling a command via the network interface with bad90 arguments."""91 class Foo:92 @icpw_command93 def do_stuff(self, x: Int64):94 pass95 class do_stuff(Struct):96 network_name = 'do_stuff'97 x = Field(Int32)98 foo = Foo()99 icypaw_arg = do_stuff({'x': 5})100 with self.assertRaises(IcypawException):101 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)102 def test_scalar_one_arg_local(self):103 """Test calling a command defined using a scalar single argument."""104 class Foo:105 @icpw_command(use_template=False)106 def do_stuff(self, x: Int64):107 self.x = x108 foo = Foo()109 exp_value = 7110 foo.do_stuff(exp_value)111 act_value = foo.x112 self.assertEqual(exp_value, act_value)113 def test_scalar_one_arg_network(self):114 """Test calling a command defined using a scalar single argument."""115 class Foo:116 @icpw_command(use_template=False)117 def do_stuff(self, x: Int64):118 self.x = x119 foo = Foo()120 exp_value = -42121 icypaw_arg = Int64(exp_value)122 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)123 self.assertEqual(foo.x, exp_value)124 def test_scalar_no_args_network(self):125 """Test calling a command defined with no arguments."""126 exp_value = 55127 class Foo:128 @icpw_command(use_template=False)129 def do_stuff(self):130 self.x = exp_value131 foo = Foo()132 icypaw_arg = Boolean(True)133 get_command_object(foo, 'do_stuff').run_network(foo, icypaw_arg)...

Full Screen

Full Screen

bdl_utils_test.py

Source:bdl_utils_test.py Github

copy

Full Screen

...5def test_indents():6 eq_(bdl_utils.add_indents('#!benchDL\nmake_install(git = "git@github.com:foo/bar", branch = "b")'),7 '#!benchDL\nmake_install(git = "git@github.com:foo/bar", branch = "b")')8def test_indents_2():9 eq_(bdl_utils.add_indents('#!benchDL\npool(size = 1):\n do_stuff(1,2)'),10 '#!benchDL\npool(size = 1):\n_INDENT_ do_stuff(1,2)\n_DEDENT_ ')11def test_indents_3():12 eq_(bdl_utils.add_indents('#!benchDL\npool(size = 1):\n do_stuff(2,3)\n #comment\n do_stuff(1,2)'),13 '#!benchDL\npool(size = 1):\n_INDENT_ do_stuff(2,3)\n #comment\n do_stuff(1,2)\n_DEDENT_ ')14def test_indents_4():15 eq_(bdl_utils.add_indents("""#!benchDL16pool(size = 1,17 worker_type = dummy_worker):18 do_stuff(1,2)"""),19"""#!benchDL20pool(size = 1,21 worker_type = dummy_worker):22_INDENT_ do_stuff(1,2)23_DEDENT_ """)24def test_indents_5():25 eq_(bdl_utils.add_indents("""#!benchDL26 # (27pool(size = 1,28 worker_type = dummy_worker):29 do_stuff(1,2)"""),30"""#!benchDL31 # (32pool(size = 1,33 worker_type = dummy_worker):34_INDENT_ do_stuff(1,2)35_DEDENT_ """)36def test_indents_6():37 eq_(bdl_utils.add_indents('#!benchDL\n'38 'pool(size = 1, attrib = "\\\"#("):\n'39 ' do_stuff(3)\n'40 ' #comment\n do_stuff(1,2)'),41 '#!benchDL\n'42 'pool(size = 1, attrib = "\\\"#("):\n'43 '_INDENT_ do_stuff(3)\n'44 ' #comment\n'45 ' do_stuff(1,2)\n'46 '_DEDENT_ ')47def test_includes():48 eq_(bdl_utils.get_includes(bdl_utils.convert("""#!benchDL49include_resource(test_json, "file.json", json)50pool(size = 17,51 worker_type = dummy_worker):52 do_stuff(1,2)""", {})), [["test_json", "file.json"]])53def test_includes_2():54 eq_(bdl_utils.get_includes(bdl_utils.convert("""#!benchDL55include_resourse()56pool(size = 17,57 worker_type = dummy_worker):58 do_stuff(1,2)""", {})), [])59def test_includes_3():60 eq_(bdl_utils.get_includes(bdl_utils.convert("""#!benchDL61# second comment62include_resource(test_json, "file.json", json)63pool(size = 17,64 worker_type = dummy_worker):65 do_stuff(1,2)""", {})), [["test_json", "file.json"]])66def test_num_of_workers():67 eq_(bdl_utils.get_num_of_workers(bdl_utils.convert("""#!benchDL68pool(size = 17,69 worker_type = dummy_worker):70 do_stuff(1,2)71pool(size = 13,72 worker_type = dummy_worker):73 do_stuff(1,2)""", {})), 30)74def test_num_of_workers_2():75 eq_(bdl_utils.get_num_of_workers(bdl_utils.convert("""#!benchDL76pool(size = var("num2", 3),77 worker_type = dummy_worker):78 do_stuff(1,2)79pool(size = var("num", 3),80 worker_type = dummy_worker):81 do_stuff(1,2)""", {"num": 7})), 10)82def test_num_of_workers_3():83 eq_(bdl_utils.get_num_of_workers(bdl_utils.convert("""#!benchDL84pool(size = 17K,85 worker_type = dummy_worker):86 do_stuff(1,2)87pool(size = 13M,88 worker_type = dummy_worker):...

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