How to use str_to_bool method in localstack

Best Python code snippet using localstack_python

import_data.py

Source:import_data.py Github

copy

Full Screen

1import csv2import datetime3from django.core.management.base import BaseCommand, CommandError4from squirrel.models import Chipmunk5def str_to_bool(x):6 if x.lower() == 'true':7 return True8 elif x.lower() == 'false':9 return False10 else:11 # evil ValueError that doesn't tell you what the wrong value was12 raise ValueError("Has to be True or False!")13class Command(BaseCommand):14 def add_arguments(self, parser):15 parser.add_argument('path')16 def handle(self, *args, **kwargs):17 path = kwargs['path']18 try:19 with open(path, encoding='utf-8') as fp:20 reader = csv.DictReader(fp)21 for item in reader:22 squirrel = Chipmunk.objects.filter(23 unique_squirrel_id=item['Unique Squirrel ID'])24 if squirrel.exists():25 continue26 squirrel=Chipmunk(27 longitude=item['X'],28 latitude=item['Y'],29 unique_squirrel_id=item['Unique Squirrel ID'],30 shift=item['Shift'],31 date=datetime.date(int(item['Date'][-4:]),int(item['Date'][:2]),int(item['Date'][2:4])), 32 age=item['Age'],33 primary_fur_color=item['Primary Fur Color'],34 location=item['Location'],35 specific_location=item['Specific Location'],36 running=str_to_bool(item['Running']),37 chasing=str_to_bool(item['Chasing']),38 climbing=str_to_bool(item['Climbing']),39 eating=str_to_bool(item['Eating']),40 foraging=str_to_bool(item['Foraging']),41 other_activities=item['Other Activities'],42 kuks=str_to_bool(item['Kuks']),43 quaas=str_to_bool(item['Quaas']),44 moans=str_to_bool(item['Moans']),45 tail_flags=str_to_bool(item['Tail flags']),46 tail_twitches=str_to_bool(item['Tail twitches']),47 approaches=str_to_bool(item['Approaches']),48 indifferent=str_to_bool(item['Indifferent']),49 runs_from=str_to_bool(item['Runs from']),50 )51 squirrel.save()52 #print(f"Squirrel {item['Unique Squirrel ID']} imported successfully!")53 except csv.Error as e:...

Full Screen

Full Screen

test_string_utils.py

Source:test_string_utils.py Github

copy

Full Screen

...7 """8 Tests for str_to_bool.9 """10 def test_str_to_bool_true(self):11 self.assertTrue(str_to_bool('True'))12 self.assertTrue(str_to_bool('true'))13 self.assertTrue(str_to_bool('trUe'))14 def test_str_to_bool_false(self):15 self.assertFalse(str_to_bool('Tru'))16 self.assertFalse(str_to_bool('False'))17 self.assertFalse(str_to_bool('false'))18 self.assertFalse(str_to_bool(''))19 self.assertFalse(str_to_bool(None))20 self.assertFalse(str_to_bool('anything'))21 def test_str_to_bool_errors(self):22 def test_raises_error(val):23 with self.assertRaises(AttributeError):24 self.assertFalse(str_to_bool(val))25 test_raises_error({})26 test_raises_error([])27 test_raises_error(1)...

Full Screen

Full Screen

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 localstack 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