How to use _setup_run method in autotest

Best Python code snippet using autotest_python

test_strategy2.py

Source:test_strategy2.py Github

copy

Full Screen

1# Sean R. Lang <sean.lang@cs.helsinki.fi>2from strategy2 import *3from strategy2 import _possible_keep_toss_tuple_list,\4 _retrieve_hand_statistics,\5 _retrieve_property_list,\6 _get_all_indices,\7 _get_by_multiple_indices,\8 _to_keep_toss_tuple9_setup_run = False10_setup_suc = False11def db_setup():12 global _setup_run13 global _setup_suc14 if (not _setup_run) and (not _setup_suc):15 # populate with basic stuff for the first few cards16 PD('need to run')17 l_succ = True 18 from records import _populate_keep_throw_statistics, session, KeepThrowStatistics19 cards_l = [20 [0, 1, 2, 3, 4, 5]21 ]22 for cards in cards_l:23 for keep in combinations(cards, 4):24 k = list(keep)25 t = [card for card in cards if card not in k]26 PD('populating keep=%s, toss=%s' % (k,t))27 try:28 #l_succ = l_succ and29 _populate_keep_throw_statistics(k,t, session)30 session.commit()31 except Exception as e:32 PD('error: %s' % str(e))33 l_succ = False34 # populate with non-existant cards so that it can be consistent when35 # dealing with pegging choices36 pcards_l = [37 [60, 61, 62, 63, 64, 65]38 ]39 _setup_run = True40 l_succ = l_succ and session.query(KeepThrowStatistics).filter_by(\41 kcard0=cards_l[0][0],42 kcard1=cards_l[0][1],43 kcard2=cards_l[0][2],44 kcard3=cards_l[0][3],45 tcard0=cards_l[0][4],46 tcard1=cards_l[0][5]).first() is not None47 _setup_suc = l_succ48#def test_db_setup():49# global _setup_run50# global _setup_suc51# assert not _setup_run52# assert not _setup_suc53# db_setup()54# assert _setup_run55# assert _setup_suc56def test__possible_keep_toss_tuple_list():57 cards = [0, 1, 2, 3, 4, 5]58 combos = [59 ((0, 1, 2, 3), (4, 5)),60 ((0, 1, 2, 4), (3, 5)),61 ((0, 1, 2, 5), (3, 4)),62 ((0, 1, 3, 4), (2, 5)),63 ((0, 1, 3, 5), (2, 4)),64 ((0, 1, 4, 5), (2, 3)),65 ((0, 2, 3, 4), (1, 5)),66 ((0, 2, 3, 5), (1, 4)),67 ((0, 2, 4, 5), (1, 3)),68 ((0, 3, 4, 5), (1, 2)),69 ((1, 2, 3, 4), (0, 5)),70 ((1, 2, 3, 5), (0, 4)),71 ((1, 2, 4, 5), (0, 3)),72 ((1, 3, 4, 5), (0, 2)),73 ((2, 3, 4, 5), (0, 1))74 ]75 poss_kt_tl = _possible_keep_toss_tuple_list(cards)76 for kt in poss_kt_tl:77 assert kt in combos78 for combo in combos:79 assert combo in poss_kt_tl80def test__retrieve_hand_statistics():81 db_setup()82 keep = (0, 1, 2, 3)83 toss = (4, 5)84 kts = _retrieve_hand_statistics((keep,toss)) #, session=session)85 assert kts is not None86 assert kts.kcard0 == 087 assert kts.kcard1 == 188 assert kts.kcard2 == 289 assert kts.kcard3 == 390 assert kts.tcard0 == 491 assert kts.tcard1 == 592def test_possible_KeepThrowStatistics():93 cards = [0, 1, 2, 3, 4, 5]94 combos = [95 ((0, 1, 2, 3), (4, 5)),96 ((0, 1, 2, 4), (3, 5)),97 ((0, 1, 2, 5), (3, 4)),98 ((0, 1, 3, 4), (2, 5)),99 ((0, 1, 3, 5), (2, 4)),100 ((0, 1, 4, 5), (2, 3)),101 ((0, 2, 3, 4), (1, 5)),102 ((0, 2, 3, 5), (1, 4)),103 ((0, 2, 4, 5), (1, 3)),104 ((0, 3, 4, 5), (1, 2)),105 ((1, 2, 3, 4), (0, 5)),106 ((1, 2, 3, 5), (0, 4)),107 ((1, 2, 4, 5), (0, 3)),108 ((1, 3, 4, 5), (0, 2)),109 ((2, 3, 4, 5), (0, 1))110 ]111 pass112def test__retrieve_property_list():113 kts = [114 KeepThrowStatistics(kcard0=12, kcard1=23, kcard2=33, kcard3=40), #, tcard0=2, tcard1=3)115 KeepThrowStatistics(kcard0=11, kcard1=22, kcard2=33, kcard3=44),116 KeepThrowStatistics(kcard0=12, kcard1=23, kcard2=34, kcard3=45),117 ]118 props = _retrieve_property_list(kts, 'kcard1')119 assert props == [23, 22, 23]120def test__get_all_indices():121 lst = [1, 1, 2, 3, 5, 8]122 assert _get_all_indices(lst, 1) == [0, 1]123 assert _get_all_indices(lst, 2) == [2]124 lst = [1, 1, 1, 1, 1, 2]125 assert _get_all_indices(lst, 1) == [0, 1, 2, 3, 4]126 lst = [1, 1, 1, 2, 1, 2]127 assert _get_all_indices(lst, 1) == [0, 1, 2, 4]128def test__get_by_multiple_indices():129 tlist = range(10)130 assert _get_by_multiple_indices(tlist, [0, 1, 3]) == [0, 1, 3]131 assert _get_by_multiple_indices(tlist, [0, 3, 5]) == [0, 3, 5]132 assert _get_by_multiple_indices(tlist, [0, 2, 8]) == [0, 2, 8]133 assert _get_by_multiple_indices(tlist, [0, 8, 3]) == [0, 8, 3]134def test__to_keep_toss_tuple():135 kts = KeepThrowStatistics(kcard0=1,136 kcard1=2,137 kcard2=3,138 kcard3=4,139 tcard0=0,140 tcard1=5,141 kmin=0,142 kmax=29,143 kmed=22,144 kavg=21,145 kmod=12,146 tmin=0,147 tmax=29,148 tmed=22,149 tavg=21,150 tmod=12)151 assert _to_keep_toss_tuple(kts) == ((1,2,3,4),(0,5))152###def test_hand_picker():153### db_setup()154### cards = [0, 1, 2, 3, 4, 5]155### exp_max_min = [((0, 1, 2, 3), (4, 5))]156### exp_min_min = [((0, 1, 4, 5), (2, 3)),157### ((0, 2, 4, 5), (1, 3)),158### ((0, 3, 4, 5), (1, 2)),159### ((1, 2, 4, 5), (0, 3)),160### ((1, 3, 4, 5), (0, 2)),161### ((2, 3, 4, 5), (0, 1))]162### assert exp_max_min == hand_picker(cards, 'kmin', max)163### # impractical, but good proof of functionality164### assert exp_min_min == hand_picker(cards, 'kmin', min)165###166###def test_hand_max_min():167### db_setup()168### cards = [0, 1, 2, 3, 4, 5]169### exp_max_min = [((0, 1, 2, 3), (4, 5))]170### assert exp_max_min == hand_max_min(cards)171###172###def test_hand_max_avg():173### db_setup()174### cards = [0, 1, 2, 3, 4, 5]175### exp = [((0, 1, 2, 3), (4, 5))]176### assert exp == hand_max_avg(cards)177###178###def test_hand_max_med():179### db_setup()180### cards = [0, 1, 2, 3, 4, 5]181### exp = [((0, 1, 2, 3), (4, 5))]182### assert exp == hand_max_med(cards)183###184###def test_hand_max_poss():185### db_setup()186### cards = [0, 1, 2, 3, 4, 5]187### exp = [((0, 1, 2, 3), (4, 5))]188### assert exp == hand_max_poss(cards)189###190###def test_hand_min_avg_crib():191### db_setup()192### cards = [0, 1, 2, 3, 4, 5]193### #exp = [((0, 1, 2, 3), (4, 5))]194### #assert exp == hand_min_avg_crib(cards)195#### exp = [196#### ((1, 2, 3, 4), (0, 5)),197#### ((0, 1, 2, 4), (1, 5)),198#### ((0, 1, 3, 4), (2, 5)),199#### ((0, 1, 3, 5), (2, 4))200#### ]201### exp = [202### ((0, 1, 2, 4), (3, 5)),203### ((0, 1, 2, 5), (3, 4)),204### ((0, 1, 3, 4), (2, 5)),205### ((0, 1, 3, 5), (2, 4)),206### ((0, 2, 3, 5), (1, 4)),207### ((1, 2, 3, 4), (0, 5))208### ]209### act = hand_min_avg_crib(cards)210### for e in exp:211### assert e in act212### for a in act:213### assert a in exp214###215####def test_hand_max_avg_both():216#### db_setup()217#### cards = [0, 1, 2, 3, 4, 5]218#### assert False219#### pass220###221####222#### How should I handle the pegging methods?223#### debug database?224#### prepopulate with non-existant cards?225####226###def test_pegging_max_avg_gained():227### db_setup()228### cards = [0, 1, 2, 3, 4, 5]229### assert False230### pass231###232###def test_pegging_max_med_gained():233### db_setup()234### cards = [0, 1, 2, 3, 4, 5]235### assert False236### pass237###238###def test_pegging_min_avg_given():239### db_setup()240### cards = [0, 1, 2, 3, 4, 5]241### assert False242### pass...

Full Screen

Full Screen

local_host_unittest.py

Source:local_host_unittest.py Github

copy

Full Screen

...30 # just test that wait_up always works31 host = local_host.LocalHost()32 host.wait_up(1)33 self.god.check_playback()34 def _setup_run(self, result):35 host = local_host.LocalHost()36 (local_host.utils.run.expect_call(result.command, timeout=123,37 ignore_status=True, stdout_tee=local_host.utils.TEE_TO_LOGS,38 stderr_tee=local_host.utils.TEE_TO_LOGS, stdin=None, args=())39 .and_return(result))40 return host41 def test_run_success(self):42 result = local_host.utils.CmdResult(command='yes', stdout='y',43 stderr='', exit_status=0, duration=1)44 host = self._setup_run(result)45 self.assertEqual(host.run('yes', timeout=123, ignore_status=True,46 stdout_tee=local_host.utils.TEE_TO_LOGS,47 stderr_tee=local_host.utils.TEE_TO_LOGS, stdin=None), result)48 self.god.check_playback()49 def test_run_failure_raised(self):50 result = local_host.utils.CmdResult(command='yes', stdout='',51 stderr='err', exit_status=1, duration=1)52 host = self._setup_run(result)53 self.assertRaises(local_host.error.AutotestHostRunError, host.run,54 'yes', timeout=123)55 self.god.check_playback()56 def test_run_failure_ignored(self):57 result = local_host.utils.CmdResult(command='yes', stdout='',58 stderr='err', exit_status=1, duration=1)59 host = self._setup_run(result)60 self.assertEqual(host.run('yes', timeout=123, ignore_status=True),61 result)62 self.god.check_playback()63 def test_list_files_glob(self):64 host = local_host.LocalHost()65 files = (os.path.join(self.tmpdir.name, 'file1'),66 os.path.join(self.tmpdir.name, 'file2'))67 # create some files in tmpdir68 open(files[0], 'w').close()69 open(files[1], 'w').close()70 self.assertTrue(71 sorted(files) ==72 sorted(host.list_files_glob(os.path.join(self.tmpdir.name, '*'))))73 def test_symlink_closure_does_not_add_existent_file(self):...

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