Best Python code snippet using uiautomator
test_DoodleFileClass.py
Source:test_DoodleFileClass.py  
...14        doodleset.projectname = "dubuxiaoyao"15        core = DoodleServer.DoodleCore.PrjAss(doodleset)16        ass_ue_prj = DoodleServer.DoodleBaseClass.assUePrj(core, doodleset)17        return core, ass_ue_prj18    def test_down(self, create_obj):19        core, ueprj = create_obj20        core.file_class = DoleOrm.fileClass(id=1, file_class="character")21        core.ass_class = DoleOrm.assClass(id=99, file_name='10GeZhongJingXiuXianZhe')22        core.file_type = DoleOrm.fileType(id=270, file_type='10GeZhongJingXiuXianZhe_UE4')23        core.query_id = 124        path = ueprj.down()25        print(path.as_posix())26    def test_upload(self, create_obj):27        core, ueprj = create_obj28        core.file_class = core.queryAssClass()[0]29        # core.file_class = DoleOrm.fileClass(id=1, file_class="character")30        core.ass_class = core.file_class.addass_class[1]31        core.file_type = core.ass_class.addfileType[0]32        core.query_id = 133        ueprj.upload(pathlib.Path(r"D:/Doodle_cache/03_Workflow/Assets/character/"34                                  r"10GeZhongJingXiuXianZhe/Scenefiles/10GeZhongJ"35                                  r"ingXiuXianZhe_UE4/CH_Projects.uproject"))36    def test_appoint(self, create_obj):37        core, ueprj = create_obj38        core.file_class = core.queryAssClass()[0]39        # core.file_class = DoleOrm.fileClass(id=1, file_class="character")40        core.ass_class = core.file_class.addass_class[1]41        core.file_type = core.ass_class.addfileType[0]42        core.query_id = 143        ueprj.appoint(pathlib.Path(r"D:/Doodle_cache/03_Workflow/Assets/character/"44                                   r"10GeZhongJingXiuXianZhe/Scenefiles/10GeZhongJ"45                                   r"ingXiuXianZhe_UE4/CH_Projects.uproject"))46class TestAssScreenshot:47    @pytest.fixture()48    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjAss, DoodleServer.DoodleBaseClass.assScreenshot]:49        doodleset = DoodleServer.DoodleSet.Doodlesetting()50        doodleset.projectname = "dubuxiaoyao"51        core = DoodleServer.DoodleCore.PrjAss(doodleset)52        ass_screenshot = DoodleServer.DoodleBaseClass.assScreenshot(core, doodleset)53        return core, ass_screenshot54    def test_upload(self, create_obj):55        core, ass_screenshot = create_obj56        core.file_class = core.queryAssClass()[0]57        # core.file_class = DoleOrm.fileClass(id=1, file_class="character")58        core.ass_class = core.file_class.addass_class[1]59        core.file_type = DoleOrm.fileType(file_type="test")60        with ass_screenshot.upload() as path:61            shutil.copy2(r"D:\test\test.jpg", path)62    def test_down(self, create_obj):63        core, ass_screenshot = create_obj64        core.file_class = core.queryAssClass()[0]65        # core.file_class = DoleOrm.fileClass(id=1, file_class="character")66        core.ass_class = core.file_class.addass_class[1]67        core.file_type = DoleOrm.fileType(file_type="test")68        print(ass_screenshot.down())69class TestAssFBFile:70    @pytest.fixture()71    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjAss, DoodleServer.DoodleBaseClass.assFBFile]:72        doodleset = DoodleServer.DoodleSet.Doodlesetting()73        doodleset.projectname = "dubuxiaoyao"74        core = DoodleServer.DoodleCore.PrjAss(doodleset)75        ass_ass_fb_file = DoodleServer.DoodleBaseClass.assFBFile(core, doodleset)76        return core, ass_ass_fb_file77    def test_upload(self, create_obj):78        core, ass_ass_fb_file = create_obj79        core.file_class = core.queryAssClass()[0]80        core.ass_class = core.file_class.addass_class[1]81        ass_ass_fb_file.upload(pathlib.Path(r"D:\sc_064\BuJu.1078.png"))82    def test_down(self, create_obj):83        core, ass_ass_fb_file = create_obj84        core.file_class = core.queryAssClass()[0]85        core.ass_class = core.file_class.addass_class[1]86        core.query_id = 487        print(ass_ass_fb_file.down())88class TestAssMayaFile:89    @pytest.fixture()90    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjAss, DoodleServer.DoodleBaseClass.assMayaFile]:91        doodleset = DoodleServer.DoodleSet.Doodlesetting()92        doodleset.projectname = "dubuxiaoyao"93        core = DoodleServer.DoodleCore.PrjAss(doodleset)94        ass_maya_file = DoodleServer.DoodleBaseClass.assMayaFile(core, doodleset)95        return core, ass_maya_file96    def test_upload(self, create_obj):97        core, ass_maya_file = create_obj98        core.file_class = core.queryAssClass()[0]99        core.ass_class = core.file_class.addass_class[1]100        core.file_type = core.ass_class.addfileType[1]101        ass_maya_file.upload(pathlib.Path(r"D:\DBXY_004_035.mb"))102        print(core.file_type.file_type)103    def test_down(self, create_obj):104        core, ass_maya_file = create_obj105        core.file_class = core.queryAssClass()[0]106        core.ass_class = core.file_class.addass_class[1]107        core.file_type = core.ass_class.addfileType[1]108        core.query_id = 254109        # ass_maya_file.down()110        print(ass_maya_file.down())111# ==================================================================================================================112# shotç±»æµè¯æ¹æ³113class TestShotMayaFile:114    @pytest.fixture()115    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotMayaFile]:116        doodleset = DoodleServer.DoodleSet.Doodlesetting()117        doodleset.projectname = "dubuxiaoyao"118        core = DoodleServer.DoodleCore.PrjShot(doodleset)119        shot_maya_file = DoodleServer.DoodleBaseClass.shotMayaFile(core, doodleset)120        return core, shot_maya_file121    def testUpload(self, create_obj):122        core, shot_maya_file = create_obj123        core.episodes = core.queryEps()[0]124        core.shot = core.episodes.addShot[0]125        core.file_class = core.shot.addfileClass[0]126        core.file_type = core.file_class.addfileType[0]127        shot_maya_file.upload(pathlib.Path(r"D:\DBXY_004_035.mb"))128    def testDown(self, create_obj):129        core, shot_maya_file = create_obj130        core.episodes = core.queryEps()[0]131        core.shot = core.episodes.addShot[0]132        core.file_class = core.shot.addfileClass[0]133        core.file_type = core.file_class.addfileType[0]134        core.query_id = 1270135        print(shot_maya_file.down())136class TestShotFBFile:137    @pytest.fixture()138    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotFBFile]:139        doodleset = DoodleServer.DoodleSet.Doodlesetting()140        doodleset.projectname = "dubuxiaoyao"141        core = DoodleServer.DoodleCore.PrjShot(doodleset)142        shot_fb_file = DoodleServer.DoodleBaseClass.shotFBFile(core, doodleset)143        return core, shot_fb_file144    def test_upload(self, create_obj):145        core, shot_fb_file = create_obj146        core.episodes = core.queryEps()[0]147        core.shot = core.episodes.addShot[0]148        core.file_class = core.shot.addfileClass[0]149        core.file_type = core.file_class.addfileType[0]150        shot_fb_file.upload(pathlib.Path(r"D:\sc_064\BuJu.1078.png"))151    def test_down(self, create_obj):152        core, shot_fb_file = create_obj153        core.episodes = core.queryEps()[0]154        core.shot = core.episodes.addShot[0]155        core.file_class = core.shot.addfileClass[0]156        core.file_type = core.file_class.addfileType[0]157        core.query_id = 666158        print(shot_fb_file.down())159class TestShotFbEpsiodesFile:160    @pytest.fixture()161    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotFbEpisodesFile]:162        doodleset = DoodleServer.DoodleSet.Doodlesetting()163        doodleset.projectname = "dubuxiaoyao"164        core = DoodleServer.DoodleCore.PrjShot(doodleset)165        shot_fb_eps_file = DoodleServer.DoodleBaseClass.shotFbEpisodesFile(core, doodleset)166        return core, shot_fb_eps_file167    def test_makeEpsFB(self, create_obj):168        core, shot_fb_eps_file = create_obj169        core.episodes = core.queryEps()[24]170        print(shot_fb_eps_file.makeEpisodesFlipBook())171    def test_down(self, create_obj):172        core, shot_fb_eps_file = create_obj173        core.episodes = core.queryEps()[24]174        print(shot_fb_eps_file.down())175class TestShotMayaExportFile:176    @pytest.fixture()177    def create_obj(self) -> typing.Tuple[DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotMayaExportFile]:178        doodleset = DoodleServer.DoodleSet.Doodlesetting()179        doodleset.projectname = "dubuxiaoyao"180        core = DoodleServer.DoodleCore.PrjShot(doodleset)181        shot_export_file = DoodleServer.DoodleBaseClass.shotMayaExportFile(core, doodleset)182        return core, shot_export_file183    def test_down(self, create_obj):184        core, shot_export_file = create_obj185        core.episodes = core.queryEps()[24]186        core.shot = core.episodes.addShot[26]187        core.file_class = core.shot.addfileClass[0]188        core.file_type = core.file_class.addfileType[2]189        core.query_file = core.file_type.addshotMayaAnmExport[0]190        print(shot_export_file.down())191        pass192    def test_export(self, create_obj):193        core, shot_export_file = create_obj194        core.episodes = core.queryEps()[24]195        core.shot = core.episodes.addShot[26]196        core.file_class = core.shot.addfileClass[0]197        core.file_type = core.file_class.addfileType[0]198        core.query_file = core.file_type.addshotMayaAnmScane[0]199        shot_export_file.export()200class TestshotMayaClothExportFile:201    @pytest.fixture()202    def create_obj(self) -> typing.Tuple[203        DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotMayaClothExportFile]:204        doodleset = DoodleServer.DoodleSet.Doodlesetting()205        doodleset.projectname = "dubuxiaoyao"206        core = DoodleServer.DoodleCore.PrjShot(doodleset)207        shot_export_file = DoodleServer.DoodleBaseClass.shotMayaClothExportFile(core, doodleset)208        return core, shot_export_file209    def test_dow(self, create_obj):210        core, shot_export_file = create_obj211        core.episodes = core.queryEps()[14]212        core.shot = DoleOrm.Shot(shot_=34, episodes=core.episodes)213        uplist = list(pathlib.Path(r"D:\Doodle_cache\03_Workflow\Shots\ep015\sc0034\export_clothToFbx\VFX\clothToFbx")214                      .iterdir())215        uplist.append(uplist.pop(0))216        shot_export_file.upload(uplist)217    def test_down(self, create_obj):218        core, shot_export_file = create_obj219        core.episodes = core.queryEps()[14]220        core.shot = core.episodes.addShot[0]221        core.file_class = core.shot.addfileClass[0]222        core.file_type = core.file_class.addfileType[0]223        core.query_file = core.file_type.addshotMayaAnmExport[0]224        shot_export_file.down()225class TestshotScreenshot:226    @pytest.fixture()227    def create_obj(self) -> typing.Tuple[228        DoodleServer.DoodleCore.PrjShot, DoodleServer.DoodleBaseClass.shotScreenshot]:229        doodleset = DoodleServer.DoodleSet.Doodlesetting()230        doodleset.projectname = "dubuxiaoyao"231        core = DoodleServer.DoodleCore.PrjShot(doodleset)232        shot_screenshot = DoodleServer.DoodleBaseClass.shotScreenshot(core, doodleset)233        return core, shot_screenshot234    def test_upload(self,create_obj):235        core, shot_screenshot = create_obj236        core.episodes = core.queryEps()[14]237        core.shot = core.episodes.addShot[0]238        with shot_screenshot.upload() as path:239            shutil.copy2(pathlib.Path(r"D:\test\test.jpg"),path)240    def test_down(self,create_obj):241        core, shot_screenshot = create_obj242        core.episodes = core.queryEps()[14]243        core.shot = core.episodes.addShot[0]244        core.file_class = core.shot.addfileClass[0]245        core.file_type = core.file_class.addfileType[1]246        core.query_file = core.file_type.addshotScreenshot[0]...tictactoe.py
Source:tictactoe.py  
1"""2Tic Tac Toe Player3"""4import math5from copy import deepcopy6X = "X"7O = "O"8EMPTY = None9def initial_state():10    """11    Returns starting state of the board.12    """13    return [[EMPTY, EMPTY, EMPTY],14            [EMPTY, EMPTY, EMPTY],15            [EMPTY, EMPTY, EMPTY]]16def player(board):17    """18    Returns player who has the next turn on a board.19    """20    if (board[0] + board[1] + board[2]).count(EMPTY) % 2 == 1:21        return X22    return O23def actions(board):24    """25    Returns set of all possible actions (i, j) available on the board.26    """27    available = set()28    # loop thru each place on the board. if EMPTY, add coordinates (i, j) to open set29    for i, row in enumerate(board):30        for j, spot in enumerate(row):31            if spot == EMPTY:32                available.add((i, j))33    return available34def result(board, action):35    """36    Returns the board that results from making move (i, j) on the board.37    """38    # if invalid action, raise exception39    row, cell = action[0], action[1]40    if board[row][cell] != EMPTY:41        raise Exception("Invalid move.")42    board_copy = deepcopy(board)43    # determine player making move44    turn = player(board_copy)45    board_copy[action[0]][action[1]] = turn46    return board_copy47def winner(board):48    """49    Returns the winner of the game, if there is one.50    """51    for i, row in enumerate(board):52        # winner via 3 across53        if row.count(X) == 3 or row.count(O) == 3:54            return row[0]55        # winner via 3 down56        test_down = []57        for j in range(0, 3):58            test_down.append(board[j][i])59        if test_down.count(X) == 3 or test_down.count(O) == 3:60            return test_down[0]61    # winner via 3 diagonal62    if [board[0][0], board[1][1], board[2][2]].count(X) == 3 or [board[0][0], board[1][1], board[2][2]].count(O) == 3:63        return board[0][0]64    if [board[0][2], board[1][1], board[2][0]].count(X) == 3 or [board[0][2], board[1][1], board[2][0]].count(O) == 3:65        return board[0][2]66    # else no winner67    return None68def terminal(board):69    """70    Returns True if game is over, False otherwise.71    """72    if winner(board) is not None or (board[0] + board[1] + board[2]).count(EMPTY) == 0:73        return True74    return False75def utility(board):76    """77    Returns 1 if X has won the game, -1 if O has won, 0 otherwise.78    """79    if winner(board) == X:80        return 181    elif winner(board) == O:82        return -183    else:84        return 085def minimax(board):86    """87    Returns the optimal action for the current player on the board.88    """89    if terminal(board):90        return None91    if player(board) == X:92        return max_value(deepcopy(board), board)93    return min_value(deepcopy(board), board)94def max_value(board, og):95    if terminal(board):96        return utility(board)97    v, goal, potential = -math.inf, 1, {}98    for i, action in enumerate(actions(board)):99        val = min_value(result(board, action), og)100        v = max(v, val)101        # perform check on moves available from current state102        if len(actions(board)) - len(actions(og)) == 0:103            if val == goal:104                return action105            potential[val] = action106            # all current actions evaluated, return best option107            if i + 1 == len(actions(board)):108                return potential[max(potential.keys())]109    return v110def min_value(board, og):111    if terminal(board):112        return utility(board)113    v, goal, potential = math.inf, -1, {}114    for i, action in enumerate(actions(board)):115        val = max_value(result(board, action), og)116        v = min(v, val)117        # perform check on moves available from current state118        if len(actions(board)) - len(actions(og)) == 0:119            if val == goal:120                return action121            potential[val] = action122            # all current actions evaluated, return best option123            if i + 1 == len(actions(board)):124                return potential[min(potential.keys())]...split_to_folds.py
Source:split_to_folds.py  
1import numpy as np2import scipy as scp3import scipy.io4from v2 import utils5data = scp.io.loadmat("dataset/features.mat")6labels = data['labels'].reshape((2000, 1)).astype(int)7features = data['features'].reshape((2000, 1024, 5, 1))8def split_to_folds(np_arr, prefix):9    """10    Splits the full array of ESC-50 by extracting test fold and combining other folds into one array.11    Full array of ESC-50 contains 2000 examples organized into 5 folds. This function gets consecutively12    each fold and produces:13        test_[LABEL OR TRAINING DATA]_fold_[NUMBER OF TEST FOLD].npy14        train_[LABEL OR TRAINING DATA]_fold_[NUMBER OF TEST FOLD].npy (except test fold all others are combined here)15    :param np_arr: full NumPy array of ESC-50 dataset converted into mel spectrogram16    :param prefix: defines prefix for distinquishing labels and training data17    """18    total_examples = np_arr.shape[0]19    num_folds = 520    test_length = int(total_examples / num_folds)21    for i in range(num_folds):22        test_up = i * test_length23        test_down = (i + 1) * test_length24        tr_up_1 = 025        tr_down_1 = test_up26        tr_up_2 = test_down27        tr_down_2 = total_examples28        tr_fold = split_arr(arr=np_arr, up1=tr_up_1, down1=tr_down_1, up2=tr_up_2, down2=tr_down_2)29        test_fold = slice_arr(np_arr, test_up, test_down)30        print("\n\nSaving " + prefix + " fold " + str(i + 1))31        np.save("dataset/train_" + prefix + "_fold_" + str(i + 1) + ".npy", tr_fold)32        np.save("dataset/test_" + prefix + "_fold_" + str(i + 1) + ".npy", test_fold)33        print("Test: [" + str(test_up) + " : " + str(test_down)34              + "] Train: [" + str(tr_up_1) + " : " + str(tr_down_1) + "], ["35              + str(tr_up_2) + " : " + str(tr_down_2) + "]")36def split_arr(arr, up1, down1, up2, down2):37    s1 = slice_arr(arr, up1, down1)38    s2 = slice_arr(arr, up2, down2)39    if s1 is None and s2 is None:40        raise RuntimeError()41    if s1 is None:42        return s243    if s2 is None:44        return s145    return np.concatenate((s1, s2))46def slice_arr(arr, up, down):47    s1 = None48    if up != down:49        s1 = arr[up:down]50    return s151split_to_folds(labels, "labels")...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!!
