How to use calc_is_empty method in hypothesis

Best Python code snippet using hypothesis

collections.py

Source: collections.py Github

copy

Full Screen

...47 def do_draw(self, data):48 return self.newtuple(49 data.draw(e) for e in self.element_strategies50 )51 def calc_is_empty(self, recur):52 return any(recur(e) for e in self.element_strategies)53TERMINATOR = hbytes(b'\0')54class ListStrategy(SearchStrategy):55 """A strategy for lists which takes an intended average length and a56 strategy for each of its element types and generates lists containing any57 of those element types.58 The conditional distribution of the length is geometric, and the59 conditional distribution of each parameter is whatever their60 strategies define.61 """62 def __init__(63 self,64 strategies, average_length=50.0, min_size=0, max_size=float('inf')65 ):66 SearchStrategy.__init__(self)67 assert average_length > 068 self.average_length = average_length69 strategies = tuple(strategies)70 self.min_size = min_size or 071 self.max_size = max_size or float('inf')72 self.element_strategy = one_of_strategies(strategies)73 def do_validate(self):74 self.element_strategy.validate()75 if self.is_empty:76 raise InvalidArgument((77 'Cannot create non-empty lists with elements drawn from '78 'strategy %r because it has no values.') % (79 self.element_strategy,))80 def calc_is_empty(self, recur):81 if self.min_size == 0:82 return False83 else:84 return recur(self.element_strategy)85 def do_draw(self, data):86 if self.element_strategy.is_empty:87 assert self.min_size == 088 return []89 elements = cu.many(90 data,91 min_size=self.min_size, max_size=self.max_size,92 average_size=self.average_length93 )94 result = []95 while elements.more():96 result.append(data.draw(self.element_strategy))97 return result98 def __repr__(self):99 return (100 'ListStrategy(%r, min_size=%r, average_size=%r, max_size=%r)'101 ) % (102 self.element_strategy, self.min_size, self.average_length,103 self.max_size104 )105class UniqueListStrategy(SearchStrategy):106 def __init__(107 self,108 elements, min_size, max_size, average_size,109 key110 ):111 super(UniqueListStrategy, self).__init__()112 assert min_size <= average_size <= max_size113 self.min_size = min_size114 self.max_size = max_size115 self.average_size = average_size116 self.element_strategy = elements117 self.key = key118 def do_validate(self):119 self.element_strategy.validate()120 if self.is_empty:121 raise InvalidArgument((122 'Cannot create non-empty lists with elements drawn from '123 'strategy %r because it has no values.') % (124 self.element_strategy,))125 def calc_is_empty(self, recur):126 if self.min_size == 0:127 return False128 else:129 return recur(self.element_strategy)130 def do_draw(self, data):131 if self.element_strategy.is_empty:132 assert self.min_size == 0133 return []134 elements = cu.many(135 data,136 min_size=self.min_size, max_size=self.max_size,137 average_size=self.average_size138 )139 seen = set()140 result = []141 while elements.more():142 value = data.draw(self.element_strategy)143 k = self.key(value)144 if k in seen:145 elements.reject()146 else:147 seen.add(k)148 result.append(value)149 assert self.max_size >= len(result) >= self.min_size150 return result151class FixedKeysDictStrategy(MappedSearchStrategy):152 """A strategy which produces dicts with a fixed set of keys, given a153 strategy for each of their equivalent values.154 e.g. {'foo' : some_int_strategy} would155 generate dicts with the single key 'foo' mapping to some integer.156 """157 def __init__(self, strategy_dict):158 self.dict_type = type(strategy_dict)159 if isinstance(strategy_dict, OrderedDict):160 self.keys = tuple(strategy_dict.keys())161 else:162 try:163 self.keys = tuple(sorted(164 strategy_dict.keys(),165 ))166 except TypeError:167 self.keys = tuple(sorted(168 strategy_dict.keys(), key=repr,169 ))170 super(FixedKeysDictStrategy, self).__init__(171 strategy=TupleStrategy(172 (strategy_dict[k] for k in self.keys), tuple173 )174 )175 def calc_is_empty(self, recur):176 return recur(self.mapped_strategy)177 def __repr__(self):178 return 'FixedKeysDictStrategy(%r, %r)' % (179 self.keys, self.mapped_strategy)180 def pack(self, value):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

Now Log Bugs Using LambdaTest and DevRev

In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

11 Best Mobile Automation Testing Tools In 2022

Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.

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