How to use _enumerate method in hypothesis

Best Python code snippet using hypothesis

texas.py

Source: texas.py Github

copy

Full Screen

1#/​usr/​bin/​env python2#3# Copyright (C) 2008 Christian Hergert <chris@dronelabs.com>4#5# This program is free software: you can redistribute it and/​or modify6# it under the terms of the GNU General Public License or the7# GNU Lesser General Public License as published by the 8# Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http:/​/​www.gnu.org/​licenses/​>.18import gio19import gobject20import glib21import os22import time23_NAME_ATTRIBUTE="standard::display-name"24_TYPE_ATTRIBUTE="standard::type"25class WalkerTexasRanger(object):26 def __init__(self, onResult, onClear=None, onFinish=None):27 self._onResult = onResult28 self._onClear = onClear29 self._onFinish = onFinish30 self._enumerate = gio.Cancellable()31 self._userData = None32 33 def _result(self, *args, **kwargs):34 if callable(self._onResult):35 userData = self._userData and [self._userData] or [None]36 apply(self._onResult, [self] + list(args) + userData, kwargs)37 38 def _clear(self, *args, **kwargs):39 if callable(self._onClear):40 userData = self._userData and [self._userData] or [None]41 apply(self._onClear, [self] + list(args) + userData, kwargs)42 43 def _finish(self, *args, **kwargs):44 if callable(self._onFinish):45 userData = self._userData and [self._userData] or [None]46 apply(self._onFinish, [self] + list(args) + userData, kwargs)47 48 def cancel(self):49 """50 Cancels a running query.51 """52 self._stamp = None53 self._enumerate.cancel()54 55 def walk(self, query, ignoredot = False, maxdepth = -1, user_data = None):56 # cancel any existing request57 self._enumerate.cancel()58 self._enumerate.reset()59 self._userData = user_data60 61 # call the clear callback62 self._clear()63 64 # consider doing query_info_async to determine if this is65 # a directory without potential blocking for slow disks.66 if not query or not os.path.isdir(query):67 False68 69 # build a unique stamp for this query70 stamp = self._stamp = str(time.time()) + query71 72 # build our state and file objects73 # state => (74 # unique query stamp,75 # dirs to traverse,76 # ignore dot files/​dirs77 # max depth to traverse78 # current traversal depth79 # )80 state = [stamp, [], ignoredot, maxdepth, 0]81 vfs = gio.vfs_get_default()82 gfile = vfs.get_file_for_path(query)83 84 # asynchronously get the list of children85 attrs = ','.join([_NAME_ATTRIBUTE, _TYPE_ATTRIBUTE])86 gfile.enumerate_children_async(attrs, self._walk, 0, 0,87 self._enumerate, state)88 89 return True90 91 def _walk(self, gfile, result, state):92 stamp, todo, ignoredot, maxdepth, curdepth = state93 94 # return immediately if we have been End-Of-Lifed95 if stamp != self._stamp:96 return97 98 try:99 children = gfile.enumerate_children_finish(result)100 dirname = gfile.get_path()101 dirs = []102 files = []103 104 # iterate the children found105 for child in children:106 childname = child.get_attribute_string(_NAME_ATTRIBUTE)107 childtype = child.get_attribute_uint32(_TYPE_ATTRIBUTE)108 109 # keep track of dirs and files for callback.110 # add directories to traverse if needed.111 if childtype == gio.FILE_TYPE_DIRECTORY:112 if childname.startswith('.') and ignoredot:113 continue114 115 # only add this to the todo list if its within116 # our depth limit.117 if maxdepth < 0 or curdepth + 1 <= maxdepth:118 fullpath = os.path.join(gfile.get_path(), childname)119 todo.insert(0, (fullpath, curdepth + 1))120 121 dirs.insert(0, childname)122 elif childtype == gio.FILE_TYPE_REGULAR:123 if childname.startswith('.') and ignoredot:124 continue125 files.insert(0, childname)126 127 self._result(dirname, dirs, files)128 children.close()129 del children130 except gio.Error, ex:131 pass132 133 del gfile134 135 # we are done if no more dirs are left to traverse.136 # call finish and return.137 if not len(todo):138 self._finish()139 return140 141 # perform our next enumerate which calls this same method142 nextpath, nextdepth = todo.pop()143 state[-1] = nextdepth144 next = gio.file_parse_name(nextpath)145 attrs = ','.join([_NAME_ATTRIBUTE, _TYPE_ATTRIBUTE])146 next.enumerate_children_async(attrs, self._walk, 0, 0,147 self._enumerate, state)148 149if __name__ == '__main__':150 import gtk151 import pprint152 153 def p(walker, dirname, dirs, files, user):154 assert(user != None)155 print '=' * 76156 print dirname157 if dirs:158 print ' dirs:'159 print ' ' + '\n '.join(dirs)160 print161 if files:162 print ' files:'163 print ' ' + '\n '.join(files)164 print165 166 walker = WalkerTexasRanger(p, None, lambda *a: gtk.main_quit())167 #walker.walk('/​home/​chergert')168 169 def newwalk():170 walker.walk('/​home/​chergert', True, 2, "user data")171 return False172 173 # start a new search 50 mili later174 glib.timeout_add(50, newwalk)175 ...

Full Screen

Full Screen

ui.py

Source: ui.py Github

copy

Full Screen

...3class UI:4 def __init__(self):5 self.disabled = True6 def initial(self, opponent, counts, values):7 items = self._enumerate(counts)8 self._display('Opponent name is: {}'.format(9 'unspecified ' if opponent is None else opponent.name))10 self._display('There are: ' + ', '.join(items))11 prices = self._prices(values)12 self._display(', '.join(prices))13 def offer(self, offer, counts, player):14 items = self._enumerate(offer)15 counter = self._enumerate(counts - offer)16 if len(items) == 0:17 me = 'I want nothing'18 else:19 me = 'I want ' + ', '.join(items)20 if len(counter) == 0:21 you = 'You get nothing'22 else:23 you = 'You get ' + ', '.join(counter)24 self._display('{}: {}; {}'.format(player, me, you))25 def accept(self, player, reward):26 self._display('{}: I accept and get ${}'.format(player, reward))27 def no_consensus(self):28 self._display('No consensus!')29 def _enumerate(self, counts):30 items = []31 for i, count in enumerate(counts):32 if count == 0:33 continue34 if count == 1:35 items.append('1 {}'.format(ITEM_NAMES[i]))36 else:37 items.append('{} {}s'.format(count, ITEM_NAMES[i]))38 return items39 def _prices(self, values):40 return [ '1 {} is worth ${}'.format(name, price) \41 for name, price in zip(ITEM_NAMES, values) if price > 0 ]42 def _display(self, message):43 if not self.disabled:...

Full Screen

Full Screen

__init__.py

Source: __init__.py Github

copy

Full Screen

1from ._structural import IsomerEnumerator2from ._enumerate import enumerate_stereoisomers3from ._enumerate import enumerate_tautomers4from ._enumerate import enumerate_structisomers5from ._enumerate import remove_stereochemistry...

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