How to use expected_duration method in Kiwi

Best Python code snippet using Kiwi_python

model_break.py

Source:model_break.py Github

copy

Full Screen

...154 if len(name) < 1:155 raise ValueError("Invalid value for `name`, length must be greater than or equal to `1`")156 self._name = name157 @property158 def expected_duration(self):159 """160 Gets the expected_duration of this ModelBreak.161 Format: RFC-3339 P[n]Y[n]M[n]DT[n]H[n]M[n]S. The expected length of the break.162 :return: The expected_duration of this ModelBreak.163 :rtype: str164 """165 return self._expected_duration166 @expected_duration.setter167 def expected_duration(self, expected_duration):168 """169 Sets the expected_duration of this ModelBreak.170 Format: RFC-3339 P[n]Y[n]M[n]DT[n]H[n]M[n]S. The expected length of the break.171 :param expected_duration: The expected_duration of this ModelBreak.172 :type: str173 """174 if expected_duration is None:175 raise ValueError("Invalid value for `expected_duration`, must not be `None`")176 if len(expected_duration) < 1:177 raise ValueError("Invalid value for `expected_duration`, length must be greater than or equal to `1`")178 self._expected_duration = expected_duration179 @property180 def is_paid(self):181 """...

Full Screen

Full Screen

test_Clip.py

Source:test_Clip.py Github

copy

Full Screen

1"""Clip tests."""2import copy3import numpy as np4import pytest5from moviepy.Clip import Clip6from moviepy.video.VideoClip import BitmapClip, ColorClip7def test_clip_equality():8 bitmap = [["RR", "RR"], ["RB", "RB"]]9 different_bitmap = [["RR", "RB"], ["RB", "RB"]]10 different_duration_bitmap = [["RR", "RR"], ["RB", "RB"], ["RR", "RR"]]11 clip = BitmapClip(bitmap, fps=1)12 same_clip = BitmapClip(bitmap, fps=1)13 different_clip = BitmapClip(different_bitmap, fps=1)14 different_duration_clip = BitmapClip(different_duration_bitmap, fps=1)15 assert clip == same_clip16 assert clip != different_clip17 assert clip != different_duration_clip18 assert different_clip != different_duration_clip19def test_clip_with_is_mask():20 clip = BitmapClip([["RR", "GG"]], fps=1)21 assert not clip.is_mask22 assert clip.with_is_mask(True).is_mask23 assert not clip.with_is_mask(False).is_mask24@pytest.mark.parametrize(25 (26 "start",27 "end",28 "duration",29 "new_start",30 "change_end",31 "expected_end",32 "expected_duration",33 ),34 (35 (0, 3, 3, 1, True, 4, 3),36 (0, 3, 3, 1, False, 3, 2), # not change_end37 ),38)39def test_clip_with_start(40 start,41 end,42 duration,43 new_start,44 change_end,45 expected_end,46 expected_duration,47):48 clip = (49 ColorClip(color=(255, 0, 0), size=(2, 2))50 .with_fps(1)51 .with_duration(duration)52 .with_end(end)53 .with_start(start)54 )55 new_clip = clip.with_start(new_start, change_end=change_end)56 assert new_clip.end == expected_end57 assert new_clip.duration == expected_duration58@pytest.mark.parametrize(59 ("duration", "start", "end", "expected_start", "expected_duration"),60 (61 (3, 1, 2, 1, 1),62 (3, 1, None, 1, 3), # end is None63 (3, None, 4, 1, 3), # start is None64 ),65)66def test_clip_with_end(duration, start, end, expected_start, expected_duration):67 clip = ColorClip(color=(255, 0, 0), size=(2, 2), duration=duration).with_fps(1)68 if start is not None:69 clip = clip.with_start(start)70 else:71 clip.start = None72 clip = clip.with_end(end)73 assert clip.start == expected_start74 assert clip.duration == expected_duration75@pytest.mark.parametrize(76 (77 "duration",78 "start",79 "end",80 "new_duration",81 "change_end",82 "expected_duration",83 "expected_start",84 "expected_end",85 ),86 (87 (5, None, None, 3, True, 3, 0, 3),88 ("00:00:05", 1, 6, 3, True, 3, 1, 4), # change end89 ((0, 0, 5), 1, 6, 3, False, 3, 3, 6), # change start90 (5, None, None, None, False, ValueError, None, None),91 ),92)93def test_clip_with_duration(94 duration,95 start,96 end,97 new_duration,98 change_end,99 expected_duration,100 expected_start,101 expected_end,102):103 clip = ColorClip(color=(255, 0, 0), size=(2, 2)).with_fps(1).with_duration(duration)104 if start is not None:105 clip = clip.with_start(start)106 if end is not None:107 clip = clip.with_end(end)108 if hasattr(expected_duration, "__traceback__"):109 with pytest.raises(expected_duration):110 clip.with_duration(new_duration, change_end=change_end)111 else:112 clip = clip.with_duration(new_duration, change_end=change_end)113 assert clip.duration == expected_duration114 assert clip.start == expected_start115 assert clip.end == expected_end116@pytest.mark.parametrize(117 "copy_func",118 (119 lambda clip: clip.copy(),120 lambda clip: copy.copy(clip),121 lambda clip: copy.deepcopy(clip),122 ),123 ids=(124 "clip.copy()",125 "copy.copy(clip)",126 "copy.deepcopy(clip)",127 ),128)129def test_clip_copy(copy_func):130 """Clip must be copied with `.copy()` method, `copy.copy()` and131 `copy.deepcopy()` (same behaviour).132 """133 clip = Clip()134 other_clip = Clip()135 # shallow copy of clip136 for attr in clip.__dict__:137 setattr(clip, attr, "foo")138 copied_clip = copy_func(clip)139 # assert copied attributes140 for attr in copied_clip.__dict__:141 assert getattr(copied_clip, attr) == getattr(clip, attr)142 # other instances are not edited143 assert getattr(copied_clip, attr) != getattr(other_clip, attr)144@pytest.mark.parametrize(145 ("duration", "start_time", "end_time", "expected_duration"),146 (147 (1, 0, None, 1),148 (3, 0, 2, 2),149 (3, 1, 2, 1),150 (3, -2, 2, 1), # negative start_time151 (3, 4, None, ValueError), # start_time > duration152 (3, 3, None, ValueError), # start_time == duration153 (3, 1, -1, 1), # negative end_time154 (None, 1, -1, ValueError), # negative end_time for clip without duration155 ),156)157def test_clip_subclip(duration, start_time, end_time, expected_duration):158 if duration is None:159 clip = ColorClip(color=(255, 0, 0), size=(2, 2)).with_fps(1)160 else:161 clip = BitmapClip([["RR", "GG"] for _ in range(duration)], fps=1)162 if hasattr(expected_duration, "__traceback__"):163 with pytest.raises(expected_duration):164 clip.subclip(start_time=start_time, end_time=end_time)165 else:166 sub_clip = clip.subclip(start_time=start_time, end_time=end_time)167 assert sub_clip.duration == expected_duration168@pytest.mark.parametrize(169 ("start_time", "end_time", "expected_frames"),170 (171 (172 1,173 2,174 [["RR", "RR"], ["BB", "BB"]],175 ),176 (177 1,178 3,179 [["RR", "RR"]],180 ),181 (182 2,183 3,184 [["RR", "RR"], ["GG", "GG"]],185 ),186 (187 0,188 1,189 [["GG", "GG"], ["BB", "BB"]],190 ),191 (192 0,193 2,194 [["BB", "BB"]],195 ),196 ),197)198def test_clip_cutout(start_time, end_time, expected_frames):199 clip = BitmapClip([["RR", "RR"], ["GG", "GG"], ["BB", "BB"]], fps=1)200 new_clip = clip.cutout(start_time, end_time)201 assert new_clip == BitmapClip(expected_frames, fps=1)202def test_clip_memoize():203 clip = BitmapClip([["RR", "RR"], ["GG", "GG"], ["BB", "BB"]], fps=1)204 assert not clip.memoize205 memoize_clip = clip.with_memoize(True)206 assert memoize_clip.memoize207 # get_frame memoizing208 memoize_clip.memoized_t = 5209 memoize_clip.memoized_frame = "foo"210 assert memoize_clip.get_frame(5) == "foo"211 assert isinstance(memoize_clip.get_frame(1), np.ndarray)212if __name__ == "__main__":...

Full Screen

Full Screen

_status.py

Source:_status.py Github

copy

Full Screen

1from __future__ import annotations2from datetime import datetime, timedelta3from typing import Literal, Union4from ..model import FrozenModel5class _IdleBase(FrozenModel):6 expected_duration: timedelta7 tries: int8class _RunningBase(_IdleBase):9 begin_at: datetime10class _CompletedBase(_RunningBase):11 end_at: datetime12 def run(self) -> Running:13 """Run the step again."""14 return Running(15 expected_duration=self.expected_duration,16 tries=self.tries + 1,17 begin_at=datetime.now(),18 )19class Skipped(_IdleBase):20 """Did not run the step."""21 status_type: Literal["skipped"] = "skipped"22class Completed(_CompletedBase):23 """Successfully completed the step without failure or cancellation."""24 status_type: Literal["completed"] = "completed"25class Cancelled(_CompletedBase):26 """The user or system cancelled the step.27 Either due to:28 * press CTRL+C29 * receive SIGTERM signal30 * etc.31 """32 status_type: Literal["cancelled"] = "cancelled"33class Failed(_CompletedBase):34 """The step failed due to an error."""35 status_type: Literal["failed"] = "failed"36class Running(_RunningBase):37 """The step currently runs."""38 status_type: Literal["running"] = "running"39 def cancel(self) -> Cancelled:40 """Cancel the step."""41 return Cancelled(42 expected_duration=self.expected_duration,43 tries=self.tries,44 begin_at=self.begin_at,45 end_at=datetime.now(),46 )47 def complete(self) -> Completed:48 """Mark that the step completed successfully (without error)."""49 return Completed(50 expected_duration=self.expected_duration,51 tries=self.tries,52 begin_at=self.begin_at,53 end_at=datetime.now(),54 )55 def fail(self) -> Failed:56 """Mark that the step failed with an error."""57 return Failed(58 expected_duration=self.expected_duration,59 tries=self.tries,60 begin_at=self.begin_at,61 end_at=datetime.now(),62 )63class Idle(_IdleBase):64 """The step is idle and waits for someone to run or skip it."""65 status_type: Literal["idle"] = "idle"66 def run(self) -> Running:67 """Run the step for the first time."""68 return Running(69 expected_duration=self.expected_duration, tries=1, begin_at=datetime.now()70 )71 def skip(self) -> Skipped:72 """Skip the step (mark that we did not run it)."""73 return Skipped(expected_duration=self.expected_duration, tries=0)74# State machine:75#76# Idle --> Skipped77# |78# `----> Running --> Completed --> Running79# |80# |------> Cancelled --> Running81# |82# `------> Failed -----> Running83#...

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