Best Python code snippet using hypothesis
parse_bio.py
Source: parse_bio.py
1from typing import Dict, Set, List, Optional2from dataclasses import dataclass3import re4import pyperclip5REGIONS: Dict[str, Set[str]] = {6 'Caribbean': {7 'guadeloupe', 'martinique', 'saint-domingue', 'saint domingue',8 'cap-français', 'port-au-prince', 'îles du vent',9 'grenada', 'saint-louis', 'saint-vincent', 'caribbean'10 },11 'India': {'chandannagar', 'surat', 'india', 'pondicherry'},12 'Bourbon': {'bourbon', 'isle of france', 'isle bourbon', 'mauritius'},13 'New France': {'quebec', 'québec', 'canada', 'louisbourg', 'montreal', 'new france', 'île royale'},14 'Louisiana': {'louisiana', 'new orleans'},15 'Guyana': {'cayenne', 'Guyana'},16 'Senegal': {'senegal', 'gorée'},17}18CATEGORIES = {19 'Military': ['régiment', 'capitaine', 'soldat', 'officier', 'armurier', 'major',20 'maréchal', 'brigadier', 'bataillon', 'infanterie', 'enseigne',21 'canonnier', 'colonel',22 'troupes', 'caporal', 'déserteur', 'artillerie', 'aide-major'],23 'Official': ['lieutenant', 'lieutenant', 'contrôleur', 'inspecteur',24 'ordonnateur', 'sous-lieutenance', 'commissaire',25 'gouverneur', 'écrivain', 'conseil', 'juge',26 'garde-magasin', 'intendant', 'commandant'],27}28BY_PRECEDENCE = ['Official', 'Military']29def get_index(haystack: str, needle: str) -> int:30 match = re.search(fr"\b{needle}\b", haystack, re.IGNORECASE)31 if match is None:32 return -133 return match.start()34@dataclass35class Match:36 keyword: str37 region: str38 index: int39def get_regions_from_biography(sentence: str):40 sentence = sentence.lower()41 matches: List[Match] = []42 for region, keywords in REGIONS.items():43 for keyword in keywords:44 idx = get_index(sentence, keyword)45 if idx > -1:46 matches.append(Match(keyword, region, idx))47 matches.sort(key=lambda m: m.index)48 matching_regions = []49 # return regions in order of visit50 for match in matches:51 if match.region not in matching_regions:52 matching_regions.append(match.region)53 if len(matching_regions) == 0:54 print("No matches!")55 res = ";".join(matching_regions)56 print(res)57 pyperclip.copy(res)58def get_category_from_bio(name: str) -> Optional[str]:59 for categ in BY_PRECEDENCE:60 for kw in CATEGORIES[categ]:61 if kw in name.lower():62 print(categ)63 return64 print("Other")65while True:66 bio = input("Bio: ")67 print()68 get_regions_from_biography(bio)...
maps.py
Source: maps.py
1from os.path import abspath, dirname2from django.conf import settings3from gobotany.mapping.map import (NorthAmericanPlantDistributionMap, NAMESPACES,4 Path)5from goorchids.core.models import Taxon6GRAPHICS_ROOT = abspath(dirname(__file__) + '/../core/static/graphics')7# To differentiate8CANADIAN_PROVINCES = {9 'ab': u'Alberta',10 'bc': u'British Columbia',11 'mb': u'Manitoba',12 'nb': u'New Brunswick',13 'nl': u'Newfoundland and Labrador',14 'nt': u'Northwest Territories',15 'ns': u'Nova Scotia',16 'nu': u'Nunavut',17 'on': u'Ontario',18 'pe': u'Prince Edward Island',19 'qc': u'Quebec',20 'sk': u'Saskatchewan',21 'yt': u'Yukon'22}23PRESENT_COLOR = '#78bf47'24ABSENT_COLOR = '#fff'25STATES_MAP = dict((v, k) for k, v in settings.STATE_NAMES.iteritems())26class NorthAmericanOrchidDistributionMap(NorthAmericanPlantDistributionMap):27 PATH_NODES_XPATH = 'svg:path|svg:g|svg:g/svg:g|svg:g/svg:path|svg:g/svg:g/svg:path'28 def __init__(self):29 blank_map_path = GRAPHICS_ROOT + '/na-state-distribution.svg'30 super(NorthAmericanPlantDistributionMap, self).__init__(31 blank_map_path)32 def set_plant(self, scientific_name):33 self.scientific_name = scientific_name34 taxon = Taxon.objects.get(scientific_name=scientific_name)35 self.distribution_records = taxon.character_values.filter(36 character__short_name='state_distribution')37 if self.distribution_records:38 self._add_name_to_title(self.scientific_name)39 def shade(self):40 """Set the colors of the states and provinces based41 on distribution data.42 """43 if self.distribution_records:44 path_nodes = self.svg_map.xpath(self.PATH_NODES_XPATH,45 namespaces=NAMESPACES)46 matching_regions = {}47 for record in self.distribution_records:48 region = STATES_MAP.get(record.value_str)49 region = ((region in CANADIAN_PROVINCES and 'ca-' or 'us-') +50 region)51 matching_regions[region] = True52 for node in path_nodes:53 if node.get('style'):54 node_id = node.get('id').lower()55 box = Path(node)56 if node_id in matching_regions:57 box.color(PRESENT_COLOR)58 else:59 box.color(ABSENT_COLOR)...
find_drupal_behaviors.py
Source: find_drupal_behaviors.py
1import sublime2import sublime_plugin3# @TODO: make regex configurable.4BEHAVIOR_RE = 'Drupal\.behaviors\.([^\s]+)\s*?=\s*?\{'5class FindDrupalBehaviorsCommand(sublime_plugin.TextCommand):6 def run(self, edit):7 behaviors = []8 quicklist = []9 replacements = []10 matching_regions = self.view.find_all(BEHAVIOR_RE, sublime.IGNORECASE, '\\1', replacements)11 i = 012 for r in matching_regions:13 behavior_name = replacements[i]14 behaviors.append({'name': behavior_name, 'region': r})15 quicklist.append(behavior_name)16 i += 117 def goto_behavior(index):18 if index is not -1:19 item = behaviors[index]20 self.view.sel().clear()21 self.view.sel().add(item['region'])22 self.view.show(item['region'])...
Check out the latest blogs from LambdaTest on this topic:
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.
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.
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.
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.
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.
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!!