Best Python code snippet using green
test_sys.py
Source:test_sys.py
1import sys2from unittest import expectedFailure3from ..utils import TranspileTestCase4class SysModuleTests(TranspileTestCase):5 ############################################################6 # __displayhook__7 @expectedFailure8 def test___displayhook__(self):9 self.assertCodeExecution("""10 import sys11 print(sys.__displayhook__())12 """)13 ############################################################14 # __doc__15 def test___doc__(self):16 if sys.hexversion < 0x03040500:17 # A minor change in the docstring for 3.4.518 substitutions = {19 'the value of the largest Unicode code point': [20 'the value of the largest Unicode codepoint'21 ]22 }23 else:24 substitutions = None25 self.assertCodeExecution(26 """27 import sys28 print(sys.__doc__)29 """,30 substitutions=substitutions31 )32 ############################################################33 # __egginsert34 @expectedFailure35 def test___egginsert(self):36 self.assertCodeExecution("""37 import sys38 print(sys.__egginsert)39 """)40 ############################################################41 # __excepthook__42 @expectedFailure43 def test___excepthook__(self):44 self.assertCodeExecution("""45 import sys46 print(sys.__excepthook__())47 """)48 ############################################################49 # __loader__50 self.assertCodeExecution("""51 import sys52 print(sys.__excepthook__())53 """)54 ############################################################55 # __name__56 def test___name__(self):57 self.assertCodeExecution("""58 import sys59 print(sys.__name__)60 """)61 ############################################################62 # __package__63 def test___package__(self):64 self.assertCodeExecution("""65 import sys66 print(sys.__package__)67 """)68 ############################################################69 # __plen70 @expectedFailure71 def test___plen(self):72 self.assertCodeExecution("""73 import sys74 print(sys.__plen)75 """)76 ############################################################77 # __spec__78 @expectedFailure79 def test___spec__(self):80 self.assertCodeExecution("""81 import sys82 print(sys.__spec__())83 """)84 ############################################################85 # __stderr__86 @expectedFailure87 def test___stderr__(self):88 self.assertCodeExecution("""89 import sys90 print(sys.__stderr__())91 """)92 ############################################################93 # __stdin__94 @expectedFailure95 def test___stdin__(self):96 self.assertCodeExecution("""97 import sys98 print(sys.__stdin__())99 """)100 ############################################################101 # __stdout__102 @expectedFailure103 def test___stdout__(self):104 self.assertCodeExecution("""105 import sys106 print(sys.__stdout__())107 """)108 ############################################################109 # _clear_type_cache110 @expectedFailure111 def test__clear_type_cache(self):112 self.assertCodeExecution("""113 import sys114 print(sys._clear_type_cache())115 """)116 ############################################################117 # _current_frames118 @expectedFailure119 def test__current_frames(self):120 self.assertCodeExecution("""121 import sys122 print(sys._current_frames())123 """)124 ############################################################125 # _debugmallocstats126 @expectedFailure127 def test__debugmallocstats(self):128 self.assertCodeExecution("""129 import sys130 print(sys._debugmallocstats())131 """)132 ############################################################133 # getframe134 @expectedFailure135 def test__getframe(self):136 self.assertCodeExecution("""137 import sys138 print(sys._getframe())139 """)140 ############################################################141 # _mercurial142 @expectedFailure143 def test__mercurial(self):144 self.assertCodeExecution("""145 import sys146 print(sys._mercurial)147 """)148 ############################################################149 # _xoptions150 @expectedFailure151 def test__xoptions(self):152 self.assertCodeExecution("""153 import sys154 print(sys._xoptions)155 """)156 ############################################################157 # abiflags158 @expectedFailure159 def test_abiflags(self):160 self.assertCodeExecution("""161 import sys162 print(sys.abiflags)163 """)164 ############################################################165 # api_version166 @expectedFailure167 def test_api_version(self):168 self.assertCodeExecution("""169 import sys170 print(sys.api_version)171 """)172 ############################################################173 # argv174 def test_argv(self):175 self.assertCodeExecution("""176 import sys177 print('ARGS =', sys.argv)178 """)179 self.assertCodeExecution("""180 import sys181 print('ARGS =', sys.argv)182 """, args=['1', 'asdf', '3'])183 ############################################################184 # base_exec_prefix185 @expectedFailure186 def test_base_exec_prefix(self):187 self.assertCodeExecution("""188 import sys189 print(sys.base_exec_prefix)190 """)191 ############################################################192 # base_prefix193 @expectedFailure194 def test_base_prefix(self):195 self.assertCodeExecution("""196 import sys197 print(sys.base_prefix)198 """)199 ############################################################200 # builtin_module_names201 @expectedFailure202 def test_builtin_module_names(self):203 self.assertCodeExecution("""204 import sys205 print(sys.builtin_module_names)206 """)207 ############################################################208 # byteorder209 @expectedFailure210 def test_byteorder(self):211 self.assertCodeExecution("""212 import sys213 print(sys.byteorder)214 """)215 ############################################################216 # call_tracing217 @expectedFailure218 def test_call_tracing(self):219 self.assertCodeExecution("""220 import sys221 print(sys.call_tracing())222 """)223 ############################################################224 # callstats225 @expectedFailure226 def test_callstats(self):227 self.assertCodeExecution("""228 import sys229 print(sys.callstats())230 """)231 ############################################################232 # copyright233 @expectedFailure234 def test_copyright(self):235 self.assertCodeExecution("""236 import sys237 print(sys.copyright)238 """)239 ############################################################240 # displayhook241 @expectedFailure242 def test_displayhook(self):243 self.assertCodeExecution("""244 import sys245 print(sys.displayhook)246 """)247 ############################################################248 # dont_write_bytecode249 @expectedFailure250 def test_dont_write_bytecode(self):251 self.assertCodeExecution("""252 import sys253 print(sys.dont_write_bytecode)254 """)255 ############################################################256 # exc_info257 @expectedFailure258 def test_exc_info(self):259 self.assertCodeExecution("""260 import sys261 prexc_info()int(sys.exc_info())262 """)263 ############################################################264 # excepthook265 @expectedFailure266 def test_excepthook(self):267 self.assertCodeExecution("""268 import sys269 print(sys.excepthook)270 """)271 ############################################################272 # exec_prefix273 @expectedFailure274 def test_exec_prefix(self):275 self.assertCodeExecution("""276 import sys277 print(sys.exec_prefix)278 """)279 ############################################################280 # executable281 @expectedFailure282 def test_executable(self):283 self.assertCodeExecution("""284 import sys285 print(sys.executable)286 """)287 ############################################################288 # exit289 def test_exit_from_static(self):290 # Exit from static block291 self.assertCodeExecution("""292 import sys293 print(sys.exit())294 """, exits_early=True)295 def test_exit(self):296 # From inside main297 self.assertCodeExecution("""298 import sys299 if __name__ == '__main__':300 print(sys.exit())301 """, run_in_function=False, exits_early=True)302 # From a method called from inside main303 self.assertCodeExecution("""304 import sys305 def foo():306 print(sys.exit())307 if __name__ == '__main__':308 foo()309 """, run_in_function=False, exits_early=True)310 ############################################################311 # flags312 @expectedFailure313 def test_flags(self):314 self.assertCodeExecution("""315 import sys316 print(sys.flags())317 """)318 ############################################################319 # float_info320 @expectedFailure321 def test_float_info(self):322 self.assertCodeExecution("""323 import sys324 print(sys.float_info())325 """)326 ############################################################327 # float_repr_style328 @expectedFailure329 def test_float_repr_style(self):330 self.assertCodeExecution("""331 import sys332 print(sys.float_repr_style)333 """)334 ############################################################335 # getallocatedblocks336 @expectedFailure337 def test_getallocatedblocks(self):338 self.assertCodeExecution("""339 import sys340 print(sys.getallocatedblocks())341 """)342 ############################################################343 # getcheckinterval344 @expectedFailure345 def test_getcheckinterval(self):346 self.assertCodeExecution("""347 import sys348 print(sys.getcheckinterval())349 """)350 ############################################################351 # getdefaultencoding352 @expectedFailure353 def test_getdefaultencoding(self):354 self.assertCodeExecution("""355 import sys356 print(sys.getdefaultencoding())357 """)358 ############################################################359 # getdlopenflags360 @expectedFailure361 def test_getdlopenflags(self):362 self.assertCodeExecution("""363 import sys364 print(sys.getdlopenflags())365 """)366 ############################################################367 # getfilesystemencoding368 @expectedFailure369 def test_getfilesystemencoding(self):370 self.assertCodeExecution("""371 import sys372 print(sys.getfilesystemencoding())373 """)374 ############################################################375 # getprofile376 @expectedFailure377 def test_getprofile(self):378 self.assertCodeExecution("""379 import sys380 print(sys.getprofile())381 """)382 ############################################################383 # getrecursionlimit384 @expectedFailure385 def test_getrecursionlimit(self):386 self.assertCodeExecution("""387 import sys388 print(sys.getrecursionlimit())389 """)390 ############################################################391 # getrefcount392 @expectedFailure393 def test_getrefcount(self):394 self.assertCodeExecution("""395 import sys396 print(sys.getrefcount())397 """)398 ############################################################399 # getsizeof400 @expectedFailure401 def test_getsizeof(self):402 self.assertCodeExecution("""403 import sys404 print(sys.getsizeof())405 """)406 ############################################################407 # Float getswitchinterval408 @expectedFailure409 def test_getswi(self):410 self.assertCodeExecution("""411 import sys412 print(sys.getswi())413 """)414 ############################################################415 # gettrace416 @expectedFailure417 def test_gettrace(self):418 self.assertCodeExecution("""419 import sys420 print(sys.gettrace())421 """)422 ############################################################423 # hash_info424 @expectedFailure425 def test_hash_info(self):426 self.assertCodeExecution("""427 import sys428 print(sys.hash_info)429 """)430 ############################################################431 # hexversion432 def test_hexversion(self):433 self.assertCodeExecution("""434 import sys435 print(sys.hexversion)436 """)437 ############################################################438 # implementation439 @expectedFailure440 def test_implementati(self):441 self.assertCodeExecution("""442 import sys443 print(sys.implementati())444 """)445 ############################################################446 # int_info447 @expectedFailure448 def test_int_info(self):449 self.assertCodeExecution("""450 import sys451 print(sys.int_info())452 """)453 ############################################################454 # intern455 @expectedFailure456 def test_intern(self):457 self.assertCodeExecution("""458 import sys459 print(sys.intern())460 """)461 ############################################################462 # last_traceback463 @expectedFailure464 def test_last_traceba(self):465 self.assertCodeExecution("""466 import sys467 print(sys.last_traceba())468 """)469 ############################################################470 # last_type471 @expectedFailure472 def test_last_type(self):473 self.assertCodeExecution("""474 import sys475 print(sys.last_type())476 """)477 ############################################################478 # last_value479 @expectedFailure480 def test_last_value(self):481 self.assertCodeExecution("""482 import sys483 print(sys.last_value())484 """)485 ############################################################486 # maxsize487 def test_maxsize(self):488 self.assertCodeExecution("""489 import sys490 print(sys.maxsize)491 """)492 ############################################################493 # maxunicode494 @expectedFailure495 def test_maxunicode(self):496 self.assertCodeExecution("""497 import sys498 print(sys.maxunicode)499 """)500 ############################################################501 # meta_path502 @expectedFailure503 def test_meta_path(self):504 self.assertCodeExecution("""505 import sys506 print(sys.meta_path)507 """)508 ############################################################509 # modules510 @expectedFailure511 def test_modules(self):512 self.assertCodeExecution("""513 import sys514 print(sys.modules)515 """)516 ############################################################517 # path518 @expectedFailure519 def test_path(self):520 self.assertCodeExecution("""521 import sys522 print(sys.path)523 """)524 ############################################################525 # path_hooks526 @expectedFailure527 def test_path_hooks(self):528 self.assertCodeExecution("""529 import sys530 print(sys.path_hooks)531 """)532 ############################################################533 # path_importer_cache534 @expectedFailure535 def test_path_importer_cache(self):536 self.assertCodeExecution("""537 import sys538 print(sys.path_importer_cache)539 """)540 ############################################################541 # platform542 def test_platform(self):543 self.assertCodeExecution("""544 import sys545 print(sys.platform)546 """)547 ############################################################548 # prefix549 @expectedFailure550 def test_prefix(self):551 self.assertCodeExecution("""552 import sys553 print(sys.prefix)554 """)555 ############################################################556 # ps1557 @expectedFailure558 def test_ps1(self):559 self.assertCodeExecution("""560 import sys561 print(sys.ps1)562 """)563 ############################################################564 # ps2565 @expectedFailure566 def test_ps2(self):567 self.assertCodeExecution("""568 import sys569 print(sys.ps2)570 """)571 ############################################################572 # ps3573 @expectedFailure574 def test_ps3(self):575 self.assertCodeExecution("""576 import sys577 print(sys.ps3)578 """)579 ############################################################580 # real_prefix581 @expectedFailure582 def test_real_prefix(self):583 self.assertCodeExecution("""584 import sys585 print(sys.real_prefix)586 """)587 ############################################################588 # setcheckinterval589 @expectedFailure590 def test_setcheckinterval(self):591 self.assertCodeExecution("""592 import sys593 print(sys.setcheckinterval())594 """)595 ############################################################596 # setdlopenflags597 @expectedFailure598 def test_setdlopenflags(self):599 self.assertCodeExecution("""600 import sys601 print(sys.setdlopenflags())602 """)603 ############################################################604 # setprofile605 @expectedFailure606 def test_setprofile(self):607 self.assertCodeExecution("""608 import sys609 print(sys.setprofile())610 """)611 ############################################################612 # setrecursionlimit613 @expectedFailure614 def test_setrecursionlimit(self):615 self.assertCodeExecution("""616 import sys617 print(sys.setrecursionlimit())618 """)619 ############################################################620 # setswitchinterval621 @expectedFailure622 def test_setswitchinterval(self):623 self.assertCodeExecution("""624 import sys625 print(sys.setswitchinterval())626 """)627 ############################################################628 # settrace629 @expectedFailure630 def test_settrace(self):631 self.assertCodeExecution("""632 import sys633 print(sys.settrace())634 """)635 ############################################################636 # stderr637 @expectedFailure638 def test_stderr(self):639 self.assertCodeExecution("""640 import sys641 print(sys.stderr())642 """)643 ############################################################644 # stdin645 @expectedFailure646 def test_stdin(self):647 self.assertCodeExecution("""648 import sys649 print(sys.stdin())650 """)651 ############################################################652 # stdout653 @expectedFailure654 def test_stdout(self):655 self.assertCodeExecution("""656 import sys657 print(sys.stdout())658 """)659 ############################################################660 # thread_info661 @expectedFailure662 def test_thread_info(self):663 self.assertCodeExecution("""664 import sys665 print(sys.thread_info())666 """)667 ############################################################668 # version669 @expectedFailure670 def test_version(self):671 self.assertCodeExecution("""672 import sys673 lines = sys.version.split('\n')674 print("There are %d lines" % len(lines))675 print(lines[0].split(' ')[0])676 """)677 ############################################################678 # version_info679 def test_version_info(self):680 self.assertCodeExecution("""681 import sys682 print(sys.version_info)683 """)684 ############################################################685 # warnoptions686 @expectedFailure687 def test_warnoptions(self):688 self.assertCodeExecution("""689 import sys690 print(sys.warnoptions)...
test_models.py
Source:test_models.py
1import datetime2import unittest3from unittest import TestCase4from django.contrib.auth.models import User5from django.core.exceptions import ValidationError6from advt.models import Advert, Like, Comment7class AdvertModelTest(TestCase):8 def setUp(self):9 self.advert = Advert(10 title="ÐÑодам IPhone XS 256gb",11 text="ÐÑлиÑное ÑоÑÑоÑние, ÑелеÑÐ¾Ð½Ñ 2 меÑÑÑа",12 price=1500.00,13 address="Ñл. ÐомÑомолÑÑÐºÐ°Ñ 7/2, д. 133"14 )15 self.advert.save()16 self.like = Like()17 super().setUp()18 def test_model_creation_with_object_manager(self):19 advt = Advert.objects.create(20 title="ÐÑодам IPhone XS 256gb",21 text="ÐÑлиÑное ÑоÑÑоÑние, ÑелеÑÐ¾Ð½Ñ 2 меÑÑÑа",22 price=1500.00,23 address="Ñл. ÐомÑомолÑÑÐºÐ°Ñ 7/2, д. 133"24 )25 self.assertTrue(isinstance(advt, Advert))26 self.assertEqual(self.advert.title, advt.title)27 @unittest.expectedFailure28 def test_update_date_at_future(self):29 with self.assertRaises(ValidationError):30 self.advert.update_at = datetime.datetime.now() + datetime.timedelta(days=1)31 @unittest.expectedFailure32 def test_update_date_at_past(self):33 with self.assertRaises(ValidationError):34 self.advert.update_at = datetime.datetime.now() - datetime.timedelta(weeks=1000)35 @unittest.expectedFailure36 def test_create_date_at_future(self):37 with self.assertRaises(ValidationError):38 self.advert.create_at = datetime.datetime.now() + datetime.timedelta(days=1)39 @unittest.expectedFailure40 def test_create_date_at_past(self):41 with self.assertRaises(ValidationError):42 self.advert.create_at = datetime.datetime.now() - datetime.timedelta(weeks=1000)43class LikeModelTest(TestCase):44 def create_advert(self):45 return Advert.objects.create(46 title="ÐÑодам IPhone XS 256gb",47 text="ÐÑлиÑное ÑоÑÑоÑние, ÑелеÑÐ¾Ð½Ñ 2 меÑÑÑа",48 price=1500.00,49 address="Ñл. ÐомÑомолÑÑÐºÐ°Ñ 7/2, д. 133"50 )51 def create_user(self):52 return User.objects.create(53 username="user_test",54 password="qwerty123@"55 )56 def test_model_creation_with_object_manager(self):57 User.objects.filter(username="user_test").delete()58 like = Like.objects.create(59 advt=self.create_advert(),60 user=self.create_user()61 )62 self.assertTrue(isinstance(like, Like))63 self.assertIsNotNone(like.user)64 self.assertIsNotNone(like.advt)65 @unittest.expectedFailure66 def test_model_creation_with_user_and_advert_that_already_exist(self):67 with self.assertRaises(ValidationError):68 like = Like.objects.create(69 advt=self.create_advert(),70 user=self.create_user()71 )72 @unittest.expectedFailure73 def test_update_date_at_future(self):74 with self.assertRaises(ValidationError):75 like = Like.objects.create(76 advt=self.create_advert(),77 user=self.create_user()78 )79 like.update_at = datetime.datetime.now() + datetime.timedelta(days=1)80 @unittest.expectedFailure81 def test_update_date_at_past(self):82 with self.assertRaises(ValidationError):83 like = Like.objects.create(84 advt=self.create_advert(),85 user=self.create_user()86 )87 like.update_at = datetime.datetime.now() - datetime.timedelta(weeks=1000)88 @unittest.expectedFailure89 def test_create_date_at_future(self):90 with self.assertRaises(ValidationError):91 like = Like.objects.create(92 advt=self.create_advert(),93 user=self.create_user()94 )95 like.create_at = datetime.datetime.now() + datetime.timedelta(days=1)96 @unittest.expectedFailure97 def test_create_date_at_past(self):98 with self.assertRaises(ValidationError):99 like = Like.objects.create(100 advt=self.create_advert(),101 user=self.create_user()102 )...
test_db_backend.py
Source:test_db_backend.py
1import unittest2from django.test import TestCase3from .test_backends import BackendTests4class TestDBBackend(BackendTests, TestCase):5 backend_path = 'wagtail.search.backends.db'6 # Doesn't support autocomplete7 @unittest.expectedFailure8 def test_autocomplete(self):9 super().test_autocomplete()10 # Doesn't support ranking11 @unittest.expectedFailure12 def test_ranking(self):13 super().test_ranking()14 # Doesn't support ranking15 @unittest.expectedFailure16 def test_annotate_score(self):17 super().test_annotate_score()18 # Doesn't support ranking19 @unittest.expectedFailure20 def test_annotate_score_with_slice(self):21 super().test_annotate_score_with_slice()22 # Doesn't support ranking23 @unittest.expectedFailure24 def test_search_boosting_on_related_fields(self):25 super().test_search_boosting_on_related_fields()26 # Doesn't support searching specific fields27 @unittest.expectedFailure28 def test_search_child_class_field_from_parent(self):29 super().test_search_child_class_field_from_parent()30 # Doesn't support searching related fields31 @unittest.expectedFailure32 def test_search_on_related_fields(self):33 super().test_search_on_related_fields()34 # Doesn't support searching callable fields35 @unittest.expectedFailure36 def test_search_callable_field(self):37 super().test_search_callable_field()38 # Database backend always uses `icontains`, so always autocomplete39 @unittest.expectedFailure40 def test_incomplete_term(self):41 super().test_incomplete_term()42 # Database backend always uses `icontains`, so always autocomplete43 @unittest.expectedFailure44 def test_incomplete_plain_text(self):45 super().test_incomplete_plain_text()46 # Database backend doesn't support Boost() query class47 @unittest.expectedFailure48 def test_boost(self):...
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!!