How to use is_exception method in localstack

Best Python code snippet using localstack_python

main.py

Source:main.py Github

copy

Full Screen

1import unittest2import os3import sys4from dotenv import load_dotenv, find_dotenv5sys.path.append(os.path.join(os.path.dirname(__file__), '..'))6from src.nice_crud import PostgresCrud7load_dotenv(dotenv_path=find_dotenv(raise_error_if_not_found=True))8psql_crud = PostgresCrud(9 host=os.getenv('DB_HOST'),10 port=int(os.getenv('DB_PORT')),11 dbname=os.getenv('DB_NAME'),12 user=os.getenv('DB_USER'),13 password=os.getenv('DB_PASSWORD'),14)15table_name = 'test_table'16def reset(create_table: bool = False, insert_data: bool = False) -> None:17 psql_crud.drop_table(table_name)18 if create_table is True:19 psql_crud.create_table(20 table_name=table_name,21 columns={22 'id': 'serial',23 'name': 'text NOT NULL',24 'family': 'text NOT NULL',25 'age': 'integer NOT NULL',26 },27 unique_keys=['family'],28 primary_key='id',29 )30 if insert_data is True:31 psql_crud.insert_from_dict(32 table_name=table_name,33 data={34 'name': 'john',35 'family': 'doe',36 'age': 20,37 },38 )39class CreateTestTable(unittest.TestCase):40 crud = psql_crud41 table_name = table_name42 primary_key = 'id'43 unique_keys = ['name', 'family']44 def test_via_string(self) -> None:45 try:46 reset()47 except Exception as e:48 print(e)49 try:50 self.crud.create_table(51 table_name=self.table_name,52 columns="id serial, name text NOT NULL, family text NOT NULL, age integer NOT NULL",53 unique_keys=self.unique_keys,54 primary_key=self.primary_key55 )56 is_exception = False57 except Exception as e:58 print(e)59 is_exception = True60 self.assertFalse(is_exception)61 def test_via_dict(self) -> None:62 try:63 reset()64 except Exception as e:65 print(e)66 try:67 self.crud.create_table(68 table_name=self.table_name,69 columns={70 'id': 'serial',71 'name': 'text NOT NULL',72 'family': 'text NOT NULL',73 'age': 'integer NOT NULL'74 },75 unique_keys=self.unique_keys,76 primary_key=self.primary_key77 )78 is_exception = False79 except Exception as e:80 print(e)81 is_exception = True82 self.assertFalse(is_exception)83 def test_via_list_of_lists(self) -> None:84 try:85 reset()86 except Exception as e:87 print(e)88 try:89 self.crud.create_table(90 table_name=self.table_name,91 columns=[92 ['id', 'serial'],93 ['name', 'text NOT NULL'],94 ['family', 'text NOT NULL'],95 ['age', 'integer NOT NULL']96 ],97 unique_keys=self.unique_keys,98 primary_key=self.primary_key99 )100 is_exception = False101 except Exception as e:102 print(e)103 is_exception = True104 self.assertFalse(is_exception)105 def test_via_list_of_dicts(self) -> None:106 try:107 reset()108 except Exception as e:109 print(e)110 try:111 self.crud.create_table(112 table_name=self.table_name,113 columns=[114 {'id': 'serial'},115 {'name': 'text NOT NULL'},116 {'family': 'text NOT NULL'},117 {'age': 'integer NOT NULL'}118 ],119 unique_keys=self.unique_keys,120 primary_key=self.primary_key121 )122 is_exception = False123 except Exception as e:124 print(e)125 is_exception = True126 self.assertFalse(is_exception)127 def test_via_list_of_tuples(self) -> None:128 try:129 reset()130 except Exception as e:131 print(e)132 try:133 self.crud.create_table(134 table_name=self.table_name,135 columns=[136 ('id', 'serial'),137 ('name', 'text NOT NULL'),138 ('family', 'text NOT NULL'),139 ('age', 'integer NOT NULL')140 ],141 unique_keys=self.unique_keys,142 primary_key=self.primary_key143 )144 is_exception = False145 except Exception as e:146 print(e)147 is_exception = True148 self.assertFalse(is_exception)149 def test_via_tuples_of_tuples(self) -> None:150 try:151 reset()152 except Exception as e:153 print(e)154 try:155 self.crud.create_table(156 table_name=self.table_name,157 columns=(158 ('id', 'serial'),159 ('name', 'text NOT NULL'),160 ('family', 'text NOT NULL'),161 ('age', 'integer NOT NULL')162 ),163 unique_keys=self.unique_keys,164 primary_key=self.primary_key165 )166 is_exception = False167 except Exception as e:168 print(e)169 is_exception = True170 self.assertFalse(is_exception)171 def test_via_tuples_of_dict(self) -> None:172 try:173 reset()174 except Exception as e:175 print(e)176 try:177 self.crud.create_table(178 table_name=self.table_name,179 columns=(180 {'id': 'serial'},181 {'name': 'text NOT NULL'},182 {'family': 'text NOT NULL'},183 {'age': 'integer NOT NULL'}184 ),185 unique_keys=self.unique_keys,186 primary_key=self.primary_key187 )188 is_exception = False189 except Exception as e:190 print(e)191 is_exception = True192 self.assertFalse(is_exception)193 def test_via_tuples_of_lists(self) -> None:194 try:195 reset()196 except Exception as e:197 print(e)198 try:199 self.crud.create_table(200 table_name=self.table_name,201 columns=(202 ['id', 'serial'],203 ['name', 'text NOT NULL'],204 ['family', 'text NOT NULL'],205 ['age', 'integer NOT NULL']206 ),207 unique_keys=self.unique_keys,208 primary_key=self.primary_key209 )210 is_exception = False211 except Exception as e:212 print(e)213 is_exception = True214 self.assertFalse(is_exception)215class InsertTestData(unittest.TestCase):216 crud = psql_crud217 table_name = table_name218 columns = ['name', 'family', 'age']219 values1 = ['john', 'doe', '42']220 values2 = ['Jane', 'doe', '43']221 def test_via_string(self) -> None:222 try:223 reset(create_table=True)224 except Exception as e:225 print(e)226 try:227 self.crud.insert(228 table_name=self.table_name,229 columns='name, family, age',230 values="'john', 'doe', 43",231 on_conflict='do nothing'232 )233 is_exception = False234 except Exception as e:235 print(e)236 is_exception = True237 self.assertFalse(is_exception)238 def test_via_dict(self) -> None:239 try:240 reset(create_table=True)241 except Exception as e:242 print(e)243 try:244 self.crud.insert_from_dict(245 table_name=self.table_name,246 data={247 'name': 'john',248 'family': 'doe',249 'age': 43250 },251 on_conflict='do nothing'252 )253 is_exception = False254 except Exception as e:255 print(e)256 is_exception = True257 self.assertFalse(is_exception)258 def test_via_list_of_data(self) -> None:259 try:260 reset(create_table=True)261 except Exception as e:262 print(e)263 try:264 self.crud.insert(265 table_name=self.table_name,266 columns=['name', 'family', 'age'],267 values=["'john'", "'doe'", '43'],268 on_conflict='do nothing'269 )270 is_exception = False271 except Exception as e:272 print(e)273 is_exception = True274 self.assertFalse(is_exception)275 def test_via_tuples_of_data(self) -> None:276 try:277 reset(create_table=True)278 except Exception as e:279 print(e)280 try:281 self.crud.insert(282 table_name=self.table_name,283 columns=('name', 'family', 'age'),284 values=("'john'", "'doe'", '42'),285 on_conflict='do nothing'286 )287 is_exception = False288 except Exception as e:289 print(e)290 is_exception = True291 self.assertFalse(is_exception)292class SelectTestData(unittest.TestCase):293 crud = psql_crud294 table_name = table_name295 def test_via_string_one(self):296 try:297 reset(create_table=True, insert_data=True)298 except Exception as e:299 print(e)300 try:301 result = self.crud.select(302 table_name=self.table_name,303 columns='*',304 condition='name = \'john\'',305 order_by='name',306 limit=1307 )308 is_exception = False309 except Exception as e:310 print(e)311 is_exception = True312 result = None313 self.assertFalse(is_exception)314 self.assertEqual(result, [(1, 'john', 'doe', 20)])315 def test_via_string_two(self):316 try:317 reset(create_table=True, insert_data=True)318 except Exception as e:319 print(e)320 try:321 result = self.crud.select(322 table_name=self.table_name,323 columns='name, family, age',324 condition='name = \'john\''325 )326 is_exception = False327 except Exception as e:328 print(e)329 is_exception = True330 result = None331 self.assertFalse(is_exception)332 self.assertEqual(result, [('john', 'doe', 20)])333 def test_via_string_three(self):334 try:335 reset(create_table=True, insert_data=True)336 except Exception as e:337 print(e)338 try:339 result = self.crud.select(340 table_name=self.table_name,341 columns='name, family',342 condition='name = \'john\'',343 order_by='name'344 )345 is_exception = False346 except Exception as e:347 print(e)348 is_exception = True349 result = None350 self.assertEqual(result, [('john', 'doe')])351 self.assertFalse(is_exception)352 def test_via_list(self):353 try:354 reset(create_table=True, insert_data=True)355 except Exception as e:356 print(e)357 try:358 result = self.crud.select(359 table_name=self.table_name,360 columns=[361 'name',362 'family',363 'age'364 ],365 condition='name = \'john\'',366 order_by='name'367 )368 is_exception = False369 except Exception as e:370 print(e)371 is_exception = True372 result = None373 self.assertFalse(is_exception)374 self.assertEqual(result, [('john', 'doe', 20)])375 def via_tuple(self):376 try:377 reset(create_table=True, insert_data=True)378 except Exception as e:379 print(e)380 try:381 result = self.crud.select(382 table_name=self.table_name,383 columns=(384 'name',385 'family',386 'age',387 ),388 condition='name = \'john\'',389 order_by='name'390 )391 is_exception = False392 except Exception as e:393 print(e)394 is_exception = True395 result = None396 self.assertFalse(is_exception)397 self.assertEqual(result, [('john', 'doe', 20)])398class UpdateTestData(unittest.TestCase):399 crud = psql_crud400 table_name = table_name401 def test_via_list_and_list(self) -> None:402 try:403 reset(create_table=True, insert_data=True)404 except Exception as e:405 print(e)406 try:407 self.crud.update(408 table_name=self.table_name,409 columns=[410 'family',411 'age'412 ],413 values=[414 'nice',415 '100'416 ],417 condition='name = \'john\'',418 )419 is_exception = False420 except Exception as e:421 print(e)422 is_exception = True423 self.assertFalse(is_exception)424 def test_via_list_and_tuple(self) -> None:425 try:426 reset(create_table=True, insert_data=True)427 except Exception as e:428 print(e)429 try:430 self.crud.update(431 table_name=self.table_name,432 columns=[433 'family',434 'age'435 ],436 values=(437 'nice',438 '100'439 ),440 condition='name = \'john\'',441 )442 is_exception = False443 except Exception as e:444 print(e)445 is_exception = True446 self.assertFalse(is_exception)447 def test_via_tuple_and_list(self) -> None:448 try:449 reset(create_table=True, insert_data=True)450 except Exception as e:451 print(e)452 try:453 self.crud.update(454 table_name=self.table_name,455 columns=(456 'family',457 'age'458 ),459 values=[460 'nice',461 '100'462 ],463 condition='name = \'john\'',464 )465 is_exception = False466 except Exception as e:467 print(e)468 is_exception = True469 self.assertFalse(is_exception)470 def via_tuple_and_tuple(self) -> None:471 try:472 reset(create_table=True, insert_data=True)473 except Exception as e:474 print(e)475 try:476 self.crud.update(477 table_name=self.table_name,478 columns=(479 'family',480 'age'481 ),482 values=(483 'nice',484 '100'485 ),486 condition='name = \'john\'',487 )488 is_exception = False489 except Exception as e:490 print(e)491 is_exception = True492 self.assertFalse(is_exception)493 def test_via_dict(self) -> None:494 try:495 reset(create_table=True, insert_data=True)496 except Exception as e:497 print(e)498 try:499 self.crud.update_via_dict(500 table_name=self.table_name,501 data={502 'family': 'nice',503 'age': 100504 },505 condition=[506 'name = \'aaaaaaa\'',507 'family = \'doe\''508 ],509 )510 is_exception = False511 except Exception as e:512 print(e)513 is_exception = True514 self.assertFalse(is_exception)515class DeleteTestData(unittest.TestCase):516 crud = psql_crud517 table_name = table_name518 def test_via_string(self) -> None:519 try:520 reset(create_table=True, insert_data=True)521 except Exception as e:522 print(e)523 try:524 self.crud.delete(525 table_name=self.table_name,526 condition='name = \'john\'',527 )528 is_exception = False529 except Exception as e:530 print(e)531 is_exception = True532 self.assertFalse(is_exception)533 def test_via_list(self) -> None:534 try:535 reset(create_table=True, insert_data=True)536 except Exception as e:537 print(e)538 try:539 self.crud.delete(540 table_name=self.table_name,541 condition=[542 "name = 'john'",543 "age = 50"544 ],545 )546 is_exception = False547 except Exception as e:548 print(e)549 is_exception = True550 self.assertFalse(is_exception)551 def test_via_tuple(self) -> None:552 try:553 reset(create_table=True, insert_data=True)554 except Exception as e:555 print(e)556 try:557 self.crud.delete(558 table_name=self.table_name,559 condition=(560 "name = 'john'",561 "age = 50"562 ),563 )564 is_exception = False565 except Exception as e:566 print(e)567 is_exception = True568 self.assertFalse(is_exception)569class DropTestTable(unittest.TestCase):570 crud = psql_crud571 table_name = table_name572 def test_drop(self):573 try:574 reset(create_table=True, insert_data=True)575 except Exception as e:576 print(e)577 try:578 self.crud.drop_table(table_name=self.table_name)579 is_exception = False580 except Exception as e:581 print(e)582 is_exception = True583 self.assertFalse(is_exception)584class CreateIndex(unittest.TestCase):585 crud = psql_crud586 table_name = table_name587 def test_via_string(self):588 try:589 reset(create_table=True, insert_data=True)590 except Exception as e:591 print(e)592 try:593 self.crud.create_index(594 table_name=self.table_name,595 columns='name ASC, family ASC',596 unique=True,597 index_name='name_family_index'598 )599 is_exception = False600 except Exception as e:601 print(e)602 is_exception = True603 self.assertFalse(is_exception)604 def test_via_list(self):605 try:606 reset(create_table=True, insert_data=True)607 except Exception as e:608 print(e)609 try:610 self.crud.create_index(611 table_name=self.table_name,612 columns=['name ASC', 'family ASC'],613 unique=True,614 index_name='name_family_index'615 )616 is_exception = False617 except Exception as e:618 print(e)619 is_exception = True620 self.assertFalse(is_exception)621 def test_via_tuple(self):622 try:623 reset(create_table=True, insert_data=True)624 except Exception as e:625 print(e)626 try:627 self.crud.create_index(628 table_name=self.table_name,629 columns=('name ASC', 'family ASC'),630 unique=True,631 index_name='name_family_index'632 )633 is_exception = False634 except Exception as e:635 print(e)636 is_exception = True637 self.assertFalse(is_exception)638 def test_via_dict(self):639 try:640 reset(create_table=True, insert_data=True)641 except Exception as e:642 print(e)643 try:644 self.crud.create_index(645 table_name=self.table_name,646 columns={647 'name': 'ASC',648 'family': 'ASC'649 },650 unique=True,651 index_name='name_family_index'652 )653 is_exception = False654 except Exception as e:655 print(e)656 is_exception = True657 self.assertFalse(is_exception)658 def test_via_list_of_list(self):659 try:660 reset(create_table=True, insert_data=True)661 except Exception as e:662 print(e)663 try:664 self.crud.create_index(665 table_name=self.table_name,666 columns=[667 ['name', 'ASC'],668 ['family', 'DESC']669 ],670 unique=True,671 index_name='name_family_index'672 )673 is_exception = False674 except Exception as e:675 print(e)676 is_exception = True677 self.assertFalse(is_exception)678 def test_via_list_of_tuple(self):679 try:680 reset(create_table=True, insert_data=True)681 except Exception as e:682 print(e)683 try:684 self.crud.create_index(685 table_name=self.table_name,686 columns=[687 ('name', 'ASC NULLS FIRST'),688 ('family', 'DESC NULLS LAST')689 ],690 unique=True,691 index_name='name_family_index'692 )693 is_exception = False694 except Exception as e:695 print(e)696 is_exception = True697 self.assertFalse(is_exception)698 def test_via_tuple_of_list(self):699 try:700 reset(create_table=True, insert_data=True)701 except Exception as e:702 print(e)703 try:704 self.crud.create_index(705 table_name=self.table_name,706 columns=(707 ['name', 'ASC'],708 ['family', 'DESC']709 ),710 unique=True,711 index_name='name_family_index'712 )713 is_exception = False714 except Exception as e:715 print(e)716 is_exception = True717 self.assertFalse(is_exception)718if __name__ == '__main__':...

Full Screen

Full Screen

AlipayAccountExrateSourcerateQueryModel.py

Source:AlipayAccountExrateSourcerateQueryModel.py Github

copy

Full Screen

...22 @generate_date.setter23 def generate_date(self, value):24 self._generate_date = value25 @property26 def is_exception(self):27 return self._is_exception28 @is_exception.setter29 def is_exception(self, value):30 self._is_exception = value31 @property32 def rate_source_code(self):33 return self._rate_source_code34 @rate_source_code.setter35 def rate_source_code(self, value):36 self._rate_source_code = value37 @property38 def size(self):39 return self._size40 @size.setter41 def size(self, value):42 self._size = value43 @property...

Full Screen

Full Screen

pk_nca_test.py

Source:pk_nca_test.py Github

copy

Full Screen

1""" test pk_nca """2from quantpkpd.analysis.pk_nca import exec_pk_nca3def test_exec_pk_nca():4 """ test pk_nca executor """5 is_exception = False6 try:7 exec_pk_nca(1, {})8 except TypeError:9 is_exception = True10 assert is_exception11 is_exception = False12 try:13 exec_pk_nca('aaa', {})14 except RuntimeError:15 is_exception = True16 assert is_exception17 is_exception = False18 try:19 exec_pk_nca('test/unit_tests/files/predpp_sample1.csv',20 {'dose_admin_method': 1})21 except ValueError:22 is_exception = True23 assert is_exception24 exec_pk_nca('test/unit_tests/files/theoph.csv',25 {'dose_admin_method': 1, 'datafile_type': 'nonmen', 'r_sqrt_adj': 0.9})...

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