Best Python code snippet using pandera_python
forms.py
Source:forms.py
...19 class Meta:20 model = Pate21 exclude = ['number']22class OfferForm(forms.ModelForm):23 def test_required(self, field:str):24 data = self.cleaned_data[field]25 if data is None or data == "" or data == []:26 self.add_error(field=field, error=PFLICHT)27 return data28 template_name = 'serd/form_snippet.html'29 available_from = forms.DateField(30 label=_('Verfügbar ab'),31 widget=forms.SelectDateWidget(years=range(2022, 2024))) 32 available_until = forms.DateField(33 label=_('Verfügbar bis'), required=False,34 widget=forms.SelectDateWidget(years=range(2022, 2024))) 35 cost = forms.IntegerField(label=_("falls verlangt, Monatsmiete warm"), required=False)36 comment = forms.CharField(required=False, label=_("Weiterer Kommentar (max. 500 Zeichen)"), widget=forms.Textarea)37 def clean_last_name(self):38 return self.test_required('last_name')39 def clean_given_name(self):40 return self.test_required('given_name')41 42 def clean_plz(self):43 return self.test_required('plz')44 def clean_total_number(self):45 return self.test_required('total_number')46 47 def clean_children_number(self):48 return self.test_required('children_number')49 def clean_city(self):50 return self.test_required('city')51 def clean_mail(self):52 return self.test_required('mail')53 54 def clean_rooms(self):55 return self.test_required('rooms')56 57 def clean_comment(self):58 comment = self.cleaned_data['comment']59 if len(comment) > 500:60 self.add_error(field='comment', error=ValidationError(_("Maximal 500 Zeichen (aktuell: {})").format(len(comment))))61 return comment62 63 def clean_language(self):64 65 return self.test_required('language')66 def clean(self):67 if self.errors:68 return self.cleaned_data69 if not self.cleaned_data.get('total_number') > self.cleaned_data.get('children_number'):70 self.add_error(field='total_number', error=71 ValueError(72 _("Mindestens eine erwachsene Person")73 ))74 if self.cleaned_data.get('limited_availability'):75 available_from = self.cleaned_data.get('available_from')76 available_until = self.cleaned_data.get('available_until')77 if (available_until <= available_from):78 self.add_error(field='available_until', error=79 ValueError(80 _("Ende der Verfügbarkeit muss später als der Beginn sein")81 ))82 if not self.cleaned_data.get('seperate_appartment') and not self.cleaned_data.get('living_with'):83 self.add_error(field='living_with', error=84 ValueError(85 _("Eigene Wohnsituation muss angegeben werden, wenn die Unterbringung nicht in einer getrennten Wohnung erfolgt")86 ))87 if not self.cleaned_data.get('for_free') and not self.cleaned_data.get('cost'):88 self.add_error(field='for_free', error=89 ValueError(90 _("Bitte bestätigen Sie, dass die Unterkunft kostenfrei überlassen wird, oder geben Sie die Miethöhe an")91 ))92 if self.cleaned_data.get('for_free') and self.cleaned_data.get('cost'):93 self.add_error(field='cost', error=94 ValueError(95 _("Bei kostenfreier Unterkunft ist keine Mietangabe möglich")96 ))97 return self.cleaned_data98 def save(self, commit=True, **kwargs):99 offer = super(OfferForm, self).save(commit=False, **kwargs)100 if commit:101 offer.save()102 if not isinstance(self, OfferEditForm):103 mailer = Mailer()104 mailer.send_offer_confirmation_mail(offer)105 return offer106 107 class Meta :108 model = Offer109 fields =('given_name', 'last_name', 'plz','city', 'street', 'phone', 'mail',110 'language', 'additional_languages', 'total_number' , 'children_number' , 'for_free' , 'cost', 'spontan', 111 'available_from', 'limited_availability', 'available_until','accessability', 'public_transport', 112 'rooms', 'seperate_appartment', 'living_with', 'pets', 'covid', 'comment')113 114class OfferEditForm(OfferForm):115 private_comment = forms.CharField(required=False, label=_("Interner Kommentar"), widget=forms.Textarea)116 number = forms.IntegerField(label="Laufende Nr.", disabled=True, required=False)117 def clean_language(self):118 return self.cleaned_data['language']119 def clean_comment(self):120 return self.cleaned_data['comment']121 class Meta:122 model = Offer123 fields = OfferForm.Meta.fields + ('number', 'by_municipality', 'private_comment', 'state')124class RequestForm(forms.ModelForm):125 template_name = 'form_snippet.html'126 def test_required(self, field:str):127 data = self.cleaned_data[field]128 if not settings.DEBUG and (data is None or data == ""):129 self.add_error(field=field, error=PFLICHT)130 return data131 arrival_date = forms.DateField(label=_('Ankunftstag'), required=False, widget=forms.SelectDateWidget(years=range(2022, 2024)))132 who = forms.CharField(label=_("Bitte beschreiben Sie Ihre Gruppe kurz (Alter, Geschlecht, ...)"), required=False, widget=forms.Textarea)133 class Meta:134 model = HousingRequest135 fields =('given_name', 'last_name', 'phone', 'mail', 'adults', 'children', 'who',136 'split', 'current_housing', 'can_pay', 'representative', 'repr_mail', 'repr_phone', 'arrival_date', 137 'pets', 'pet_number', 'car', 'languages', 'additional_languages', 'vaccination', 'smoker', 'accessability_needs', 'profession')138 def clean_given_name(self):139 return self.test_required('given_name')140 def clean_last_name(self):141 return self.test_required('last_name')142 def clean_phone(self):143 return self.test_required('phone')144 def clean_mail(self):145 return self.test_required('mail')146 def clean_adults(self):147 return self.test_required('adults')148 def clean_children(self):149 return self.test_required('children')150 def clean_who(self):151 return self.test_required('who')152 def clean_arrival_date(self):153 return self.test_required('arrival_date')154 def clean_current_housing(self):155 return self.test_required('current_housing')156 def clean(self):157 pets = self.cleaned_data.get('pets')158 if pets and len(pets) > 1 and 'none' in pets:159 self.add_error(field='pets', error=ValueError(160 _("Ungültige Auswahl: 'Keine' schlieÃt die anderen Wahlmöglichkeiten aus.")161 ))162 if pets == ['none']:163 if self.cleaned_data.get('pet_number'):164 self.add_error(field='pet_number', error=ValueError(165 _("Auswahl 'Keine' bei Haustier widerspricht Anzahl ungleich 0")166 ))167 else:168 self.cleaned_data['pet_number'] = 0169 elif not self.cleaned_data.get('pet_number'):170 self.add_error(field='pets', error=ValueError(171 _("Wenn keine Haustiere vorhanden sind, muss 'Keine' ausgewählt werden.")172 ))173 174 elif pets and 'none' not in pets and len(pets) > self.cleaned_data.get('pet_number'):175 self.add_error(field='pet_number', error=ValueError(176 _("Mehr Tierarten ausgewählt als Tiere vorhanden")177 ))178 return self.cleaned_data179 def save(self, commit=True, **kwargs):180 """Slugify the name if it is not in ASCII to make live easier for case handlers who181 can't read cyrillic 182 """183 housingrequest = super(RequestForm, self).save(commit=False, **kwargs)184 if not isascii(housingrequest.given_name) or not isascii(housingrequest.last_name):185 housingrequest.name_slug = slugify(housingrequest.given_name)+" "+ slugify(housingrequest.last_name)186 187 if commit:188 housingrequest.save()189 if not isinstance(self, RequestEditForm):190 mailer = Mailer()191 mailer.send_request_confirmation_mail(housingrequest)192 return housingrequest193class RequestEditForm(RequestForm):194 private_comment = forms.CharField(label=_("Interner Kommentar"), required=False, widget=forms.Textarea)195 number = forms.IntegerField(label="Laufende Nr.", disabled=True, required=False)196 197 def __init__(self, *args, **kwargs):198 super(RequestForm, self).__init__(*args, **kwargs)199 self.fields['case_handler'].queryset = User.objects.order_by('username')200 def save(self, commit=True):201 request = super(RequestEditForm, self).save(commit=False)202 hosts = self.cleaned_data['possible_hosts']203 if request.number:204 request.possible_hosts.remove(*request.possible_hosts.difference(hosts))205 request.possible_hosts.add(*hosts)206 if commit:207 request.save()208 return request209 class Meta:210 model = HousingRequest211 fields = RequestForm.Meta.fields + ('number', 'state','case_handler', 'placed_at', 'possible_hosts', 'private_comment')212 widgets= {'possible_hosts': autocomplete.ModelSelect2Multiple(url='offer-autocomplete')}213class RequestFormForHotels(RequestForm):214 private_comment = forms.CharField(label=_("Interner Kommentar"), required=False, widget=forms.Textarea)215 class Meta:216 fields = RequestForm.Meta.fields + ('number', 'state', 'private_comment')217 model = HousingRequest218class HotelStayForm(forms.ModelForm):219 arrival_date = forms.DateField(required= False, label="Anreisetag", widget=forms.SelectDateWidget(years=range(2022, 2024)))220 departure_date = forms.DateField(required= False, label="Abreisetag", widget=forms.SelectDateWidget(years=range(2022, 2024)))221 hotel= forms.ModelChoiceField(required = False, label="Hotel", queryset=Hotel.objects.all())222 room = forms.CharField(required=False, label="Zimmer", max_length=64)223 def clean_arrival_date(self):224 return self.test_required('arrival_date')225 226 def clean_hotel(self):227 return self.test_required('hotel')228 def clean(self):229 arrival = self.cleaned_data.get('arrival_date')230 departure = self.cleaned_data.get('departure_date')231 if departure:232 if departure <= arrival:233 self.add_error(field='departure_date', error=ValidationError("Abreise muss nach der Ankunft sein"))234 return self.cleaned_data235 def test_required(self, field:str):236 data = self.cleaned_data[field]237 if data is None or data == "":238 self.add_error(field=field, error=PFLICHT)239 return data240 class Meta:241 model = HotelStay242 fields = ('arrival_date', 'departure_date', 'room', 'hotel')243class BaseStaySet(BaseModelFormSet):244 def clean(self):245 if any(self.errors):246 return247 intervals = []248 form: HotelStayForm249 for form in self.forms:...
searchPrimitives.py
Source:searchPrimitives.py
1__author__ = 'johnthompson'2import itertools3from tileGroupings import PartialGroup, PartialRun4def create_new_set(existing_sets, target_set, new_tile):5 out = []6 for s in existing_sets:7 if s == target_set:8 new_s = s.clone()9 new_s.addTile(new_tile)10 out.append(new_s)11 else:12 out.append(s)13 return out14def try_set(remaining_tiles, putative_set):15 out = []16 for pair in itertools.combinations(remaining_tiles, 2):17 if pair[0] in putative_set.validAdds():18 expanded_set = putative_set.clone()19 expanded_set.addTile(pair[0])20 if pair[1] in expanded_set.validAdds():21 out.append(pair)22 elif pair[1] in putative_set.validAdds():23 expanded_set = putative_set.clone()24 expanded_set.addTile(pair[1])25 if pair[0] in expanded_set.validAdds():26 out.append((pair[1],pair[0]))27 return out28def findPlays(rack, existing_sets = None, required_tiles = None):29 if existing_sets == None:30 existing_sets = []31 current_best_sets = existing_sets32 current_best_remaining = rack[:]33 if required_tiles == None or required_tiles == []:34 tiles_satisfied = True35 else:36 tiles_satisfied = False37 for tile in rack:38 remaining_tiles = rack[:]39 remaining_tiles.remove(tile)40 if required_tiles != None:41 remaining_required = required_tiles[:]42 if tile in remaining_required:43 remaining_required.remove(tile)44 else:45 remaining_required = None46 ## try adding to existing sets47 for tileSet in existing_sets:48 if tile in tileSet.validAdds():49 produced_sets, produced_remaining_tiles = findPlays(remaining_tiles, create_new_set(existing_sets, tileSet, tile), remaining_required)50 if produced_sets != None: #used all required tiles51 if len(produced_remaining_tiles) == 0:52 return produced_sets, produced_remaining_tiles53 elif len(produced_remaining_tiles) < len(current_best_remaining):54 current_best_sets = produced_sets55 current_best_remaining = produced_remaining_tiles56 tiles_satisfied = True ## we have found a solution that does satisfy57 ## try creating a new run58 putative_run = PartialRun(tile)59 for pair in try_set(remaining_tiles, putative_run):60 test_run = putative_run.clone()61 test_run.addTile(pair[0])62 test_run.addTile(pair[1])63 test_tiles = remaining_tiles[:]64 test_tiles.remove(pair[0])65 test_tiles.remove(pair[1])66 test_sets = existing_sets[:]67 test_sets.append(test_run)68 if remaining_required != None:69 test_required = remaining_required[:]70 if pair[0] in test_required:71 test_required.remove(pair[0])72 if pair[1] in test_required:73 test_required.remove(pair[1])74 else:75 test_required = None76 produced_sets, produced_remaining_tiles = findPlays(test_tiles, test_sets, test_required)77 if produced_sets != None: # we found a valid solution78 if len(produced_remaining_tiles) == 0:79 return produced_sets, produced_remaining_tiles80 elif len(produced_remaining_tiles) < len(current_best_remaining):81 current_best_sets = produced_sets82 current_best_remaining = produced_remaining_tiles83 tiles_satisfied = True ## we have found a solution that does satisfy84 ## try creating a new group85 putative_group = PartialGroup(tile)86 for pair in try_set(remaining_tiles, putative_group):87 test_group = putative_group.clone()88 test_group.addTile(pair[0])89 test_group.addTile(pair[1])90 test_tiles = remaining_tiles[:]91 test_tiles.remove(pair[0])92 test_tiles.remove(pair[1])93 test_sets = existing_sets[:]94 test_sets.append(test_group)95 if remaining_required != None:96 test_required = remaining_required[:]97 if pair[0] in test_required:98 test_required.remove(pair[0])99 if pair[1] in test_required:100 test_required.remove(pair[1])101 else:102 test_required = None103 produced_sets, produced_remaining_tiles = findPlays(test_tiles, test_sets, test_required)104 if produced_sets != None: ## we used all required tiles105 if len(produced_remaining_tiles) == 0:106 return produced_sets, produced_remaining_tiles107 elif len(produced_remaining_tiles) < len(current_best_remaining):108 current_best_sets = produced_sets109 current_best_remaining = produced_remaining_tiles110 tiles_satisfied = True ## we have found a solution that does satisfy111 if tiles_satisfied:112 return current_best_sets, current_best_remaining113 else: ## this was not a successful path...
setup.py
Source:setup.py
1from setuptools import setup2REQUIREMENTS_FILENAME = 'requirements.txt'3REQUIREMENTS_TEST_FILENAME = 'requirements_test.txt'4# Requirements5try:6 with open(REQUIREMENTS_FILENAME, encoding="utf-8") as fh:7 REQUIRED = fh.read().split("\n")8except FileNotFoundError:9 REQUIRED = []10try:11 with open(REQUIREMENTS_TEST_FILENAME, encoding="utf-8") as fh:12 TEST_REQUIRED = fh.read().split("\n")13except FileNotFoundError:14 TEST_REQUIRED = []15# What packages are optional?16EXTRAS = {"test": TEST_REQUIRED}17setup(18 install_requires=REQUIRED,19 extras_require=EXTRAS,...
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!!