Best Python code snippet using hypothesis
test_data_tree.py
Source:test_data_tree.py
...144 assert root.transition.children[1].forced == {0}145 assert root.transition.children[0].forced == {0}146def test_can_go_from_interesting_to_valid():147 tree = DataTree()148 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())149 with pytest.raises(StopTest):150 data.conclude_test(Status.INTERESTING)151 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())152 with pytest.raises(StopTest):153 data.conclude_test(Status.VALID)154def test_going_from_interesting_to_invalid_is_flaky():155 tree = DataTree()156 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())157 with pytest.raises(StopTest):158 data.conclude_test(Status.INTERESTING)159 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())160 with pytest.raises(Flaky):161 data.conclude_test(Status.INVALID)162def test_concluding_at_prefix_is_flaky():163 tree = DataTree()164 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())165 data.draw_bits(1)166 with pytest.raises(StopTest):167 data.conclude_test(Status.INTERESTING)168 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())169 with pytest.raises(Flaky):170 data.conclude_test(Status.INVALID)171def test_concluding_with_overrun_at_prefix_is_not_flaky():172 tree = DataTree()173 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())174 data.draw_bits(1)175 with pytest.raises(StopTest):176 data.conclude_test(Status.INTERESTING)177 data = ConjectureData.for_buffer(b"", observer=tree.new_observer())178 with pytest.raises(StopTest):179 data.conclude_test(Status.OVERRUN)180def test_changing_n_bits_is_flaky_in_prefix():181 tree = DataTree()182 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())183 data.draw_bits(1)184 with pytest.raises(StopTest):185 data.conclude_test(Status.INTERESTING)186 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())187 with pytest.raises(Flaky):188 data.draw_bits(2)189def test_changing_n_bits_is_flaky_in_branch():190 tree = DataTree()191 for i in [0, 1]:192 data = ConjectureData.for_buffer([i], observer=tree.new_observer())193 data.draw_bits(1)194 with pytest.raises(StopTest):195 data.conclude_test(Status.INTERESTING)196 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())197 with pytest.raises(Flaky):198 data.draw_bits(2)199def test_extending_past_conclusion_is_flaky():200 tree = DataTree()201 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())202 data.draw_bits(1)203 with pytest.raises(StopTest):204 data.conclude_test(Status.INTERESTING)205 data = ConjectureData.for_buffer(b"\1\0", observer=tree.new_observer())206 data.draw_bits(1)207 with pytest.raises(Flaky):208 data.draw_bits(1)209def test_changing_to_forced_is_flaky():210 tree = DataTree()211 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())212 data.draw_bits(1)213 with pytest.raises(StopTest):214 data.conclude_test(Status.INTERESTING)215 data = ConjectureData.for_buffer(b"\1\0", observer=tree.new_observer())216 with pytest.raises(Flaky):217 data.draw_bits(1, forced=0)218def test_changing_value_of_forced_is_flaky():219 tree = DataTree()220 data = ConjectureData.for_buffer(b"\1", observer=tree.new_observer())221 data.draw_bits(1, forced=1)222 with pytest.raises(StopTest):223 data.conclude_test(Status.INTERESTING)224 data = ConjectureData.for_buffer(b"\1\0", observer=tree.new_observer())225 with pytest.raises(Flaky):226 data.draw_bits(1, forced=0)227def test_does_not_truncate_if_unseen():228 tree = DataTree()229 b = bytes([1, 2, 3, 4])230 assert tree.rewrite(b) == (b, None)231def test_truncates_if_seen():232 tree = DataTree()233 b = bytes([1, 2, 3, 4])234 data = ConjectureData.for_buffer(b, observer=tree.new_observer())235 data.draw_bits(8)236 data.draw_bits(8)237 data.freeze()238 assert tree.rewrite(b) == (b[:2], Status.VALID)239def test_child_becomes_exhausted_after_split():240 tree = DataTree()241 data = ConjectureData.for_buffer([0, 0], observer=tree.new_observer())242 data.draw_bits(8)243 data.draw_bits(8, forced=0)244 data.freeze()245 data = ConjectureData.for_buffer([1, 0], observer=tree.new_observer())246 data.draw_bits(8)247 data.draw_bits(8)248 data.freeze()249 assert not tree.is_exhausted250 assert tree.root.transition.children[0].is_exhausted251def test_will_generate_novel_prefix_to_avoid_exhausted_branches():252 tree = DataTree()253 data = ConjectureData.for_buffer([1], observer=tree.new_observer())254 data.draw_bits(1)255 data.freeze()256 data = ConjectureData.for_buffer([0, 1], observer=tree.new_observer())257 data.draw_bits(1)258 data.draw_bits(8)259 data.freeze()260 prefix = list(tree.generate_novel_prefix(Random(0)))261 assert len(prefix) == 2262 assert prefix[0] == 0263def test_will_mark_changes_in_discard_as_flaky():264 tree = DataTree()265 data = ConjectureData.for_buffer([1, 1], observer=tree.new_observer())266 data.start_example(10)267 data.draw_bits(1)268 data.stop_example()269 data.draw_bits(1)270 data.freeze()271 data = ConjectureData.for_buffer([1, 1], observer=tree.new_observer())272 data.start_example(10)273 data.draw_bits(1)274 with pytest.raises(Flaky):...
models.py
Source:models.py
...53 profile.user.is_active = True 54 profile.save() 55 return profile 56 57 def create_new_observer(self, email, name, surname, affiliation, password):58 """59 Create a new, inactive ``Observer``, generates a60 ``profile`` and emails its activation key,61 returning the new ``Observer``.62 63 """64 new_observer = RegisteredObserver()65 user = User()66 user.email = email67 user.username = email68 user.is_active = False69 new_observer.name = name70 new_observer.surname = surname71 user.name = name + surname...
test_observer1.py
Source:test_observer1.py
1#coding=utf82"""3è§å¯è
模å¼4å®ä¹ï¼å®ä¹å¯¹è±¡é´ä¸ç§ä¸å¯¹å¤çä¾èµå
³ç³»ï¼ä½¿å¾å½æ¯ä¸ä¸ªå¯¹è±¡æ¹åç¶æï¼åææä¾èµäºå®ç对象é½ä¼å¾å°éç¥å¹¶èªå¨æ´æ°5ç±»åï¼è¡ä¸ºç±»æ¨¡å¼6"""7class Observer:8 def __init__(self,strname,strsub):9 self.name = strname10 self.sub = strsub11 def Update(self):12 pass13class StockObserver(Observer):14 #no need to rewrite __init__()15 def Update(self):16 print "%s:%s,stop watching Stock and go on work!" %(self.name,self.sub.action)17class NBAObserver(Observer):18 def Update(self):19 print "%s:%s,stop watching NBA and go on work!" %(self.name,self.sub.action)20class SecretaryBase:21 def __init__(self):22 self.observers = []23 def Attach(self,new_observer):24 pass25 def Notify(self):26 pass27class Secretary(SecretaryBase):28 def Attach(self,new_observer):29 self.observers.append(new_observer)30 def Notify(self):31 for p in self.observers:32 p.Update()33if __name__ == "__main__":34 p = Secretary()35 s1 = StockObserver("xh",p)36 s2 = NBAObserver("wyt",p)37 p.Attach(s1);38 p.Attach(s2);39 p.action = "WARNING:BOSS ";...
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!!