How to use test_frame_name method in Playwright Python

Best Python code snippet using playwright-python

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

frame_test.py

Source: frame_test.py Github

copy
1#!/usr/bin/env python
2
3#  Copyright Contributors to the OpenCue Project
4#
5#  Licensed under the Apache License, Version 2.0 (the "License");
6#  you may not use this file except in compliance with the License.
7#  You may obtain a copy of the License at
8#
9#    http://www.apache.org/licenses/LICENSE-2.0
10#
11#  Unless required by applicable law or agreed to in writing, software
12#  distributed under the License is distributed on an "AS IS" BASIS,
13#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#  See the License for the specific language governing permissions and
15#  limitations under the License.
16
17"""Tests for `opencue.wrappers.frame`."""
18
19from __future__ import print_function
20from __future__ import division
21from __future__ import absolute_import
22import time
23import unittest
24
25import mock
26
27from opencue.compiled_proto import depend_pb2
28from opencue.compiled_proto import job_pb2
29import opencue.wrappers.frame
30import opencue.wrappers.job
31import opencue.wrappers.layer
32
33
34TEST_FRAME_NAME = 'testFrame'
35
36
37@mock.patch('opencue.cuebot.Cuebot.getStub')
38class FrameTests(unittest.TestCase):
39
40    def testEat(self, getStubMock):
41        stubMock = mock.Mock()
42        stubMock.Eat.return_value = job_pb2.FrameEatResponse()
43        getStubMock.return_value = stubMock
44
45        frame = opencue.wrappers.frame.Frame(
46            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.WAITING))
47        frame.eat()
48
49        stubMock.Eat.assert_called_with(
50            job_pb2.FrameEatRequest(frame=frame.data), timeout=mock.ANY)
51
52    def testKill(self, getStubMock):
53        stubMock = mock.Mock()
54        stubMock.Kill.return_value = job_pb2.FrameKillResponse()
55        getStubMock.return_value = stubMock
56
57        frame = opencue.wrappers.frame.Frame(
58            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
59        frame.kill()
60
61        stubMock.Kill.assert_called_with(
62            job_pb2.FrameKillRequest(frame=frame.data), timeout=mock.ANY)
63
64    def testRetry(self, getStubMock):
65        stubMock = mock.Mock()
66        stubMock.Retry.return_value = job_pb2.FrameRetryResponse()
67        getStubMock.return_value = stubMock
68
69        frame = opencue.wrappers.frame.Frame(
70            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
71        frame.retry()
72
73        stubMock.Retry.assert_called_with(
74            job_pb2.FrameRetryRequest(frame=frame.data), timeout=mock.ANY)
75
76    def testGetWhatDependsOnThis(self, getStubMock):
77        dependId = 'ddd-dddd-ddd'
78        stubMock = mock.Mock()
79        stubMock.GetWhatDependsOnThis.return_value = job_pb2.FrameGetWhatDependsOnThisResponse(
80            depends=depend_pb2.DependSeq(depends=[depend_pb2.Depend(id=dependId)]))
81        getStubMock.return_value = stubMock
82
83        frame = opencue.wrappers.frame.Frame(
84            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
85        depends = frame.getWhatDependsOnThis()
86
87        stubMock.GetWhatDependsOnThis.assert_called_with(
88            job_pb2.FrameGetWhatDependsOnThisRequest(frame=frame.data), timeout=mock.ANY)
89        self.assertEqual(len(depends), 1)
90        self.assertEqual(depends[0].id(), dependId)
91
92    def testGetWhatThisDependsOn(self, getStubMock):
93        dependId = 'ddd-dddd-ddd'
94        stubMock = mock.Mock()
95        stubMock.GetWhatThisDependsOn.return_value = job_pb2.FrameGetWhatThisDependsOnResponse(
96            depends=depend_pb2.DependSeq(depends=[depend_pb2.Depend(id=dependId)]))
97        getStubMock.return_value = stubMock
98
99        frame = opencue.wrappers.frame.Frame(
100            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
101        depends = frame.getWhatThisDependsOn()
102
103        stubMock.GetWhatThisDependsOn.assert_called_with(
104            job_pb2.FrameGetWhatThisDependsOnRequest(frame=frame.data), timeout=mock.ANY)
105        self.assertEqual(len(depends), 1)
106        self.assertEqual(depends[0].id(), dependId)
107
108    def testCreateDependencyOnFrame(self, getStubMock):
109        dependId = 'ddd-dddd-ddd'
110        stubMock = mock.Mock()
111        stubMock.CreateDependencyOnFrame.return_value = \
112            job_pb2.FrameCreateDependencyOnFrameResponse(depend=depend_pb2.Depend(id=dependId))
113        getStubMock.return_value = stubMock
114
115        dependFrameName = 'frameDependTest'
116        frame = opencue.wrappers.frame.Frame(
117            job_pb2.Frame(name=TEST_FRAME_NAME))
118        dependOnFrame = opencue.wrappers.frame.Frame(
119            job_pb2.Frame(name=dependFrameName))
120        depend = frame.createDependencyOnFrame(dependOnFrame)
121
122        stubMock.CreateDependencyOnFrame.assert_called_with(
123            job_pb2.FrameCreateDependencyOnFrameRequest(frame=frame.data,
124                                                        depend_on_frame=dependOnFrame.data),
125            timeout=mock.ANY)
126        self.assertEqual(depend.id(), dependId)
127
128    def testCreateDependencyOnJob(self, getStubMock):
129        dependId = 'ddd-dddd-ddd'
130        stubMock = mock.Mock()
131        stubMock.CreateDependencyOnJob.return_value = \
132            job_pb2.FrameCreateDependencyOnJobResponse(depend=depend_pb2.Depend(id=dependId))
133        getStubMock.return_value = stubMock
134
135        dependJobName = 'jobDependTest'
136        frame = opencue.wrappers.frame.Frame(
137            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
138        dependOnJob = opencue.wrappers.job.Job(
139            job_pb2.Job(name=dependJobName))
140        depend = frame.createDependencyOnJob(dependOnJob)
141
142        stubMock.CreateDependencyOnJob.assert_called_with(
143            job_pb2.FrameCreateDependencyOnJobRequest(frame=frame.data, job=dependOnJob.data),
144            timeout=mock.ANY)
145        self.assertEqual(depend.id(), dependId)
146
147    def testCreateDependencyOnLayer(self, getStubMock):
148        dependId = 'ddd-dddd-ddd'
149        stubMock = mock.Mock()
150        stubMock.CreateDependencyOnLayer.return_value = \
151            job_pb2.FrameCreateDependencyOnLayerResponse(depend=depend_pb2.Depend(id=dependId))
152        getStubMock.return_value = stubMock
153
154        dependLayerName = 'layerDependTest'
155        frame = opencue.wrappers.frame.Frame(
156            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
157        dependOnLayer = opencue.wrappers.layer.Layer(
158            job_pb2.Layer(name=dependLayerName))
159        depend = frame.createDependencyOnLayer(dependOnLayer)
160
161        stubMock.CreateDependencyOnLayer.assert_called_with(
162            job_pb2.FrameCreateDependencyOnLayerRequest(frame=frame.data, layer=dependOnLayer.data),
163            timeout=mock.ANY)
164        self.assertEqual(depend.id(), dependId)
165
166    def testMarkAsWaiting(self, getStubMock):
167        stubMock = mock.Mock()
168        stubMock.MarkAsWaiting.return_value = job_pb2.FrameMarkAsWaitingResponse()
169        getStubMock.return_value = stubMock
170
171        frame = opencue.wrappers.frame.Frame(
172            job_pb2.Frame(name=TEST_FRAME_NAME, state=job_pb2.RUNNING))
173        frame.markAsWaiting()
174
175        stubMock.MarkAsWaiting.assert_called_with(
176            job_pb2.FrameMarkAsWaitingRequest(frame=frame.data), timeout=mock.ANY)
177
178    def testRunTimeZero(self, getStubMock):
179        zeroFrame = opencue.wrappers.frame.Frame(
180            job_pb2.Frame(name=TEST_FRAME_NAME, start_time=0, stop_time=1000))
181        self.assertEqual(zeroFrame.runTime(), 0)
182
183    def testRunTimeRunning(self, getStubMock):
184        curTime = int(time.time())
185        startTime = 100
186        expected = curTime - startTime
187        runningFrame = opencue.wrappers.frame.Frame(
188            job_pb2.Frame(name=TEST_FRAME_NAME, start_time=startTime, stop_time=0))
189        threshold = abs(runningFrame.runTime() - expected)
190        self.assertTrue(threshold < 1)
191
192    def testRunTimeDone(self, getStubMock):
193        startTime = 100
194        stopTime = 500
195        expected = stopTime - startTime
196        runningFrame = opencue.wrappers.frame.Frame(
197            job_pb2.Frame(name=TEST_FRAME_NAME, start_time=startTime, stop_time=stopTime))
198        self.assertEqual(runningFrame.runTime(), expected)
199
200
201class FrameEnumTests(unittest.TestCase):
202
203    def testCheckpointState(self):
204        self.assertEqual(opencue.api.Frame.CheckpointState.DISABLED,
205                         opencue.compiled_proto.job_pb2.DISABLED)
206        self.assertEqual(opencue.api.Frame.CheckpointState.DISABLED, 0)
207
208    def testFrameExitStatus(self):
209        self.assertEqual(opencue.api.Frame.FrameExitStatus.NO_RETRY,
210                         opencue.compiled_proto.job_pb2.NO_RETRY)
211        self.assertEqual(opencue.api.Frame.FrameExitStatus.NO_RETRY, 256)
212
213    def testFrameState(self):
214        self.assertEqual(opencue.api.Frame.FrameState.RUNNING,
215                         opencue.compiled_proto.job_pb2.RUNNING)
216        self.assertEqual(opencue.api.Frame.FrameState.RUNNING, 2)
217
218
219if __name__ == '__main__':
220    unittest.main()
221
Full Screen

HW1_to_final.py

Source: HW1_to_final.py Github

copy
1import sys,os
2from collections import Counter
3
4hw2_sub_filename = sys.argv[1]
5new_folder_name = sys.argv[2]
6
7os.mkdir(new_folder_name)
8
9f_orig = open(hw2_sub_filename , 'r')
10f_test = open('./mfcc/test.ark' , 'r')
11
12smooth = False
13
14test_frame_name = set()
15for row in f_test:
16  framename = row.rstrip().split()[0]
17  filename = framename.split('_')[0] + '_' + framename.split('_')[1]
18  test_frame_name.add(filename)
19# print(test_frame_name)
20
21f_orig.readline()
22
23
24
25def SeqToPhone(frame_seq):
26  PhoneSeq = []
27  cur = None
28  for s in frame_seq:
29    if s != cur:
30      PhoneSeq.append(s)
31      cur = s
32  return PhoneSeq
33
34def SmoothSeq(frame_seq,window = 3):
35  new_seq = []
36  for i in range(len(frame_seq)-window+1):
37    tmp = frame_seq[i:i+window]
38    x = Counter(tmp).most_common(1)[0]
39    
40    if x[1] >= 2:
41      new_seq.append(x[0])
42    
43    # new_seq.append(x[0])
44  return new_seq
45
46cur_inst = None
47phone_seq = []
48w = []
49whole_seq = []
50name_seq = []
51for row in f_orig:
52  lab = row.rstrip().split(",")
53  name_seq.append(lab[0])
54  inst_name = lab[0].split("_")
55  inst_name = inst_name[0] + "_" + inst_name[1]
56  if inst_name != cur_inst :
57    if cur_inst:
58      if smooth:
59        new_seq = SeqToPhone( SmoothSeq(phone_seq) )
60      else:
61        new_seq = SeqToPhone( phone_seq )
62      """
63      if new_seq[0] == 'L':
64	      del new_seq[0]
65	    if new_seq[-1] == 'L':
66	      del new_seq[-1]
67      """
68      # print("".join(new_seq))
69      w.append([cur_inst , " ".join(new_seq)])
70    phone_seq = []
71    phone_seq.append(lab[1])
72    cur_inst = inst_name
73  phone_seq.append(lab[1])
74  whole_seq.append(lab[1])
75
76if smooth:
77  new_seq = SeqToPhone( SmoothSeq(phone_seq) )
78else:
79  new_seq = SeqToPhone( phone_seq )
80"""
81if new_seq[0] == 'L':
82  del new_seq[0]
83if new_seq[-1] == 'L':
84  del new_seq[-1]
85"""
86  # print("".join(new_seq))
87w.append([cur_inst , " ".join(new_seq)])
88
89for ans in w:
90  # print(ans[0])
91  if ans[0] in test_frame_name:
92    f = open(new_folder_name+'/'+ans[0] , 'w')
93    f.write(ans[1])
94    f.close()
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Python on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)