Best Python code snippet using hypothesis
test_framerate.py
Source:test_framerate.py
1import collections2import dataclasses3import fractions4import unittest5import vtc6from typing import Optional, Type, Union, Tuple, List, NamedTuple7# We'll use this to set up our test cases.8@dataclasses.dataclass9class FramerateParseCase:10 source: Union[vtc.FramerateSource, bytes, Tuple[int, int, int]]11 ntsc_arg: Optional[bool] = None12 expected_playback: Optional[fractions.Fraction] = None13 expected_timebase: Optional[fractions.Fraction] = None14 expected_drop_frame: bool = False15 expected_ntsc: bool = False16 expected_error: Optional[Type[BaseException]] = None17 expected_error_text: str = ""18 def __str__(self) -> str:19 return f"{repr(self.source)} -> {self.expected_playback}"20class TestTimebaseBasics(unittest.TestCase):21 def test_timebase_parse(self) -> None:22 cases = [23 # 23.976 ---------24 # ----------------25 FramerateParseCase(26 source="23.976",27 expected_playback=fractions.Fraction(24000, 1001),28 expected_timebase=fractions.Fraction(24, 1),29 expected_ntsc=True,30 ),31 FramerateParseCase(32 source=23.976,33 expected_playback=fractions.Fraction(24000, 1001),34 expected_timebase=fractions.Fraction(24, 1),35 expected_ntsc=True,36 ),37 FramerateParseCase(38 source="23.98",39 expected_playback=fractions.Fraction(24000, 1001),40 expected_timebase=fractions.Fraction(24, 1),41 expected_ntsc=True,42 ),43 FramerateParseCase(44 source=23.98,45 expected_playback=fractions.Fraction(24000, 1001),46 expected_timebase=fractions.Fraction(24, 1),47 expected_ntsc=True,48 ),49 FramerateParseCase(50 source=fractions.Fraction(24000, 1001),51 expected_playback=fractions.Fraction(24000, 1001),52 expected_timebase=fractions.Fraction(24, 1),53 expected_ntsc=True,54 ),55 FramerateParseCase(56 source=fractions.Fraction(1001, 24000),57 expected_playback=fractions.Fraction(24000, 1001),58 expected_timebase=fractions.Fraction(24, 1),59 expected_ntsc=True,60 ),61 FramerateParseCase(62 source=(24000, 1001),63 expected_playback=fractions.Fraction(24000, 1001),64 expected_timebase=fractions.Fraction(24, 1),65 expected_ntsc=True,66 ),67 FramerateParseCase(68 source=(1001, 24000),69 expected_playback=fractions.Fraction(24000, 1001),70 expected_timebase=fractions.Fraction(24, 1),71 expected_ntsc=True,72 ),73 FramerateParseCase(74 source="24000/1001",75 expected_playback=fractions.Fraction(24000, 1001),76 expected_timebase=fractions.Fraction(24, 1),77 expected_ntsc=True,78 ),79 FramerateParseCase(80 source="1001/24000",81 expected_playback=fractions.Fraction(24000, 1001),82 expected_timebase=fractions.Fraction(24, 1),83 expected_ntsc=True,84 ),85 FramerateParseCase(86 source=vtc.Framerate("24000/1001"),87 expected_playback=fractions.Fraction(24000, 1001),88 expected_timebase=fractions.Fraction(24, 1),89 expected_ntsc=True,90 ),91 # NTSC = False should explicitly set the timebase to the same value.92 FramerateParseCase(93 source=fractions.Fraction(24000, 1001),94 ntsc_arg=False,95 expected_playback=fractions.Fraction(24000, 1001),96 expected_timebase=fractions.Fraction(24000, 1001),97 expected_ntsc=False,98 ),99 # 24.0 -----------100 # ----------------101 FramerateParseCase(102 source="24.0",103 expected_playback=fractions.Fraction(24, 1),104 expected_timebase=fractions.Fraction(24, 1),105 ),106 FramerateParseCase(107 source=24.0,108 expected_playback=fractions.Fraction(24, 1),109 expected_timebase=fractions.Fraction(24, 1),110 ),111 FramerateParseCase(112 source="24",113 expected_playback=fractions.Fraction(24, 1),114 expected_timebase=fractions.Fraction(24, 1),115 ),116 FramerateParseCase(117 source=24,118 expected_playback=fractions.Fraction(24, 1),119 expected_timebase=fractions.Fraction(24, 1),120 ),121 FramerateParseCase(122 source=fractions.Fraction(24, 1),123 expected_playback=fractions.Fraction(24, 1),124 expected_timebase=fractions.Fraction(24, 1),125 ),126 FramerateParseCase(127 source=fractions.Fraction(1, 24),128 expected_playback=fractions.Fraction(24, 1),129 expected_timebase=fractions.Fraction(24, 1),130 ),131 FramerateParseCase(132 source=(24, 1),133 expected_playback=fractions.Fraction(24, 1),134 expected_timebase=fractions.Fraction(24, 1),135 ),136 FramerateParseCase(137 source=(1, 24),138 expected_playback=fractions.Fraction(24, 1),139 expected_timebase=fractions.Fraction(24, 1),140 ),141 FramerateParseCase(142 source="24/1",143 expected_playback=fractions.Fraction(24, 1),144 expected_timebase=fractions.Fraction(24, 1),145 ),146 FramerateParseCase(147 source="1/24",148 expected_playback=fractions.Fraction(24, 1),149 expected_timebase=fractions.Fraction(24, 1),150 ),151 FramerateParseCase(152 source=vtc.Framerate("24/1"),153 expected_playback=fractions.Fraction(24, 1),154 expected_timebase=fractions.Fraction(24, 1),155 ),156 # 29.97 ----------157 # ----------------158 FramerateParseCase(159 source="29.97",160 expected_playback=fractions.Fraction(30000, 1001),161 expected_timebase=fractions.Fraction(30, 1),162 expected_ntsc=True,163 ),164 FramerateParseCase(165 source=29.97,166 expected_playback=fractions.Fraction(30000, 1001),167 expected_timebase=fractions.Fraction(30, 1),168 expected_ntsc=True,169 ),170 FramerateParseCase(171 source="29.97",172 expected_playback=fractions.Fraction(30000, 1001),173 expected_timebase=fractions.Fraction(30, 1),174 expected_ntsc=True,175 ),176 FramerateParseCase(177 source="29.97",178 expected_playback=fractions.Fraction(30000, 1001),179 expected_timebase=fractions.Fraction(30, 1),180 expected_ntsc=True,181 ),182 FramerateParseCase(183 source="29.97",184 expected_playback=fractions.Fraction(30000, 1001),185 expected_timebase=fractions.Fraction(30, 1),186 expected_drop_frame=True,187 expected_ntsc=True,188 ),189 FramerateParseCase(190 source="29.97",191 expected_playback=fractions.Fraction(30000, 1001),192 expected_timebase=fractions.Fraction(30, 1),193 expected_drop_frame=True,194 expected_ntsc=True,195 ),196 FramerateParseCase(197 source=fractions.Fraction(30000, 1001),198 expected_playback=fractions.Fraction(30000, 1001),199 expected_timebase=fractions.Fraction(30, 1),200 expected_ntsc=True,201 ),202 FramerateParseCase(203 source=fractions.Fraction(1001, 30000),204 expected_playback=fractions.Fraction(30000, 1001),205 expected_timebase=fractions.Fraction(30, 1),206 expected_ntsc=True,207 ),208 FramerateParseCase(209 source=(30000, 1001),210 expected_playback=fractions.Fraction(30000, 1001),211 expected_timebase=fractions.Fraction(30, 1),212 expected_ntsc=True,213 ),214 FramerateParseCase(215 source=(1001, 30000),216 expected_playback=fractions.Fraction(30000, 1001),217 expected_timebase=fractions.Fraction(30, 1),218 expected_ntsc=True,219 ),220 FramerateParseCase(221 source="30000/1001",222 expected_playback=fractions.Fraction(30000, 1001),223 expected_timebase=fractions.Fraction(30, 1),224 expected_ntsc=True,225 ),226 FramerateParseCase(227 source="1001/30000",228 expected_playback=fractions.Fraction(30000, 1001),229 expected_timebase=fractions.Fraction(30, 1),230 expected_ntsc=True,231 ),232 FramerateParseCase(233 source=vtc.Framerate("30000/1001"),234 expected_playback=fractions.Fraction(30000, 1001),235 expected_timebase=fractions.Fraction(30, 1),236 expected_ntsc=True,237 ),238 # Passing an explicit false to ntsc should lead to a false result.239 FramerateParseCase(240 source="30000/1001",241 ntsc_arg=False,242 expected_playback=fractions.Fraction(30000, 1001),243 expected_timebase=fractions.Fraction(30000, 1001),244 expected_ntsc=False,245 ),246 # 30.0 -----------247 # ----------------248 FramerateParseCase(249 source="30",250 expected_playback=fractions.Fraction(30, 1),251 expected_timebase=fractions.Fraction(30, 1),252 ),253 FramerateParseCase(254 source=30,255 expected_playback=fractions.Fraction(30, 1),256 expected_timebase=fractions.Fraction(30, 1),257 ),258 FramerateParseCase(259 source="30.0",260 expected_playback=fractions.Fraction(30, 1),261 expected_timebase=fractions.Fraction(30, 1),262 ),263 FramerateParseCase(264 source=30.0,265 expected_playback=fractions.Fraction(30, 1),266 expected_timebase=fractions.Fraction(30, 1),267 ),268 FramerateParseCase(269 source=fractions.Fraction(30, 1),270 expected_playback=fractions.Fraction(30, 1),271 expected_timebase=fractions.Fraction(30, 1),272 ),273 FramerateParseCase(274 source=fractions.Fraction(1, 30),275 expected_playback=fractions.Fraction(30, 1),276 expected_timebase=fractions.Fraction(30, 1),277 ),278 FramerateParseCase(279 source=(30, 1),280 expected_playback=fractions.Fraction(30, 1),281 expected_timebase=fractions.Fraction(30, 1),282 ),283 FramerateParseCase(284 source=(1, 30),285 expected_playback=fractions.Fraction(30, 1),286 expected_timebase=fractions.Fraction(30, 1),287 ),288 FramerateParseCase(289 source="30/1",290 expected_playback=fractions.Fraction(30, 1),291 expected_timebase=fractions.Fraction(30, 1),292 ),293 FramerateParseCase(294 source="1/30",295 expected_playback=fractions.Fraction(30, 1),296 expected_timebase=fractions.Fraction(30, 1),297 ),298 FramerateParseCase(299 source=vtc.Framerate("30/1"),300 expected_playback=fractions.Fraction(30, 1),301 expected_timebase=fractions.Fraction(30, 1),302 ),303 # 47.95 ----------304 # ----------------305 FramerateParseCase(306 source="47.95",307 expected_playback=fractions.Fraction(48000, 1001),308 expected_timebase=fractions.Fraction(48, 1),309 expected_ntsc=True,310 ),311 FramerateParseCase(312 source=47.95,313 expected_playback=fractions.Fraction(48000, 1001),314 expected_timebase=fractions.Fraction(48, 1),315 expected_ntsc=True,316 ),317 FramerateParseCase(318 source=fractions.Fraction(48000, 1001),319 expected_playback=fractions.Fraction(48000, 1001),320 expected_timebase=fractions.Fraction(48, 1),321 expected_ntsc=True,322 ),323 FramerateParseCase(324 source=fractions.Fraction(1001, 48000),325 expected_playback=fractions.Fraction(48000, 1001),326 expected_timebase=fractions.Fraction(48, 1),327 expected_ntsc=True,328 ),329 FramerateParseCase(330 source=(48000, 1001),331 expected_playback=fractions.Fraction(48000, 1001),332 expected_timebase=fractions.Fraction(48, 1),333 expected_ntsc=True,334 ),335 FramerateParseCase(336 source=(1001, 48000),337 expected_playback=fractions.Fraction(48000, 1001),338 expected_timebase=fractions.Fraction(48, 1),339 expected_ntsc=True,340 ),341 FramerateParseCase(342 source="48000/1001",343 expected_playback=fractions.Fraction(48000, 1001),344 expected_timebase=fractions.Fraction(48, 1),345 expected_ntsc=True,346 ),347 FramerateParseCase(348 source="1001/48000",349 expected_playback=fractions.Fraction(48000, 1001),350 expected_timebase=fractions.Fraction(48, 1),351 expected_ntsc=True,352 ),353 FramerateParseCase(354 source=vtc.Framerate("48000/1001"),355 expected_playback=fractions.Fraction(48000, 1001),356 expected_timebase=fractions.Fraction(48, 1),357 expected_ntsc=True,358 ),359 # 48.0 -----------360 # ----------------361 FramerateParseCase(362 source="48",363 expected_playback=fractions.Fraction(48, 1),364 expected_timebase=fractions.Fraction(48, 1),365 ),366 FramerateParseCase(367 source=48,368 expected_playback=fractions.Fraction(48, 1),369 expected_timebase=fractions.Fraction(48, 1),370 ),371 FramerateParseCase(372 source=48.0,373 expected_playback=fractions.Fraction(48, 1),374 expected_timebase=fractions.Fraction(48, 1),375 ),376 FramerateParseCase(377 source=fractions.Fraction(48, 1),378 expected_playback=fractions.Fraction(48, 1),379 expected_timebase=fractions.Fraction(48, 1),380 ),381 FramerateParseCase(382 source=fractions.Fraction(1, 48),383 expected_playback=fractions.Fraction(48, 1),384 expected_timebase=fractions.Fraction(48, 1),385 ),386 FramerateParseCase(387 source=(48, 1),388 expected_playback=fractions.Fraction(48, 1),389 expected_timebase=fractions.Fraction(48, 1),390 ),391 FramerateParseCase(392 source=(1, 48),393 expected_playback=fractions.Fraction(48, 1),394 expected_timebase=fractions.Fraction(48, 1),395 ),396 FramerateParseCase(397 source="48/1",398 expected_playback=fractions.Fraction(48, 1),399 expected_timebase=fractions.Fraction(48, 1),400 ),401 FramerateParseCase(402 source="1/48",403 expected_playback=fractions.Fraction(48, 1),404 expected_timebase=fractions.Fraction(48, 1),405 ),406 FramerateParseCase(407 source=vtc.Framerate("48/1"),408 expected_playback=fractions.Fraction(48, 1),409 expected_timebase=fractions.Fraction(48, 1),410 ),411 # 59.94 ----------412 # ----------------413 FramerateParseCase(414 source="59.94",415 expected_playback=fractions.Fraction(60000, 1001),416 expected_timebase=fractions.Fraction(60, 1),417 expected_ntsc=True,418 ),419 FramerateParseCase(420 source=59.94,421 expected_playback=fractions.Fraction(60000, 1001),422 expected_timebase=fractions.Fraction(60, 1),423 expected_ntsc=True,424 ),425 FramerateParseCase(426 source=fractions.Fraction(60000, 1001),427 expected_playback=fractions.Fraction(60000, 1001),428 expected_timebase=fractions.Fraction(60, 1),429 expected_ntsc=True,430 ),431 FramerateParseCase(432 source=fractions.Fraction(1001, 60000),433 expected_playback=fractions.Fraction(60000, 1001),434 expected_timebase=fractions.Fraction(60, 1),435 expected_ntsc=True,436 ),437 FramerateParseCase(438 source=(60000, 1001),439 expected_playback=fractions.Fraction(60000, 1001),440 expected_timebase=fractions.Fraction(60, 1),441 expected_ntsc=True,442 ),443 FramerateParseCase(444 source=(1001, 60000),445 expected_playback=fractions.Fraction(60000, 1001),446 expected_timebase=fractions.Fraction(60, 1),447 expected_ntsc=True,448 ),449 FramerateParseCase(450 source="60000/1001",451 expected_playback=fractions.Fraction(60000, 1001),452 expected_timebase=fractions.Fraction(60, 1),453 expected_ntsc=True,454 ),455 FramerateParseCase(456 source="1001/60000",457 expected_playback=fractions.Fraction(60000, 1001),458 expected_timebase=fractions.Fraction(60, 1),459 expected_ntsc=True,460 ),461 FramerateParseCase(462 source=vtc.Framerate("60000/1001"),463 expected_playback=fractions.Fraction(60000, 1001),464 expected_timebase=fractions.Fraction(60, 1),465 expected_ntsc=True,466 ),467 # 60.0 -----------468 # ----------------469 FramerateParseCase(470 source="60",471 expected_playback=fractions.Fraction(60, 1),472 expected_timebase=fractions.Fraction(60, 1),473 ),474 FramerateParseCase(475 source=60,476 expected_playback=fractions.Fraction(60, 1),477 expected_timebase=fractions.Fraction(60, 1),478 ),479 FramerateParseCase(480 source="60.0",481 expected_playback=fractions.Fraction(60, 1),482 expected_timebase=fractions.Fraction(60, 1),483 ),484 FramerateParseCase(485 source=60.0,486 expected_playback=fractions.Fraction(60, 1),487 expected_timebase=fractions.Fraction(60, 1),488 ),489 FramerateParseCase(490 source=fractions.Fraction(60, 1),491 expected_playback=fractions.Fraction(60, 1),492 expected_timebase=fractions.Fraction(60, 1),493 ),494 FramerateParseCase(495 source=fractions.Fraction(1, 60),496 expected_playback=fractions.Fraction(60, 1),497 expected_timebase=fractions.Fraction(60, 1),498 ),499 FramerateParseCase(500 source=(60, 1),501 expected_playback=fractions.Fraction(60, 1),502 expected_timebase=fractions.Fraction(60, 1),503 ),504 FramerateParseCase(505 source=(1, 60),506 expected_playback=fractions.Fraction(60, 1),507 expected_timebase=fractions.Fraction(60, 1),508 ),509 FramerateParseCase(510 source="60/1",511 expected_playback=fractions.Fraction(60, 1),512 expected_timebase=fractions.Fraction(60, 1),513 ),514 FramerateParseCase(515 source="1/60",516 expected_playback=fractions.Fraction(60, 1),517 expected_timebase=fractions.Fraction(60, 1),518 ),519 FramerateParseCase(520 source=vtc.Framerate("60/1"),521 expected_playback=fractions.Fraction(60, 1),522 expected_timebase=fractions.Fraction(60, 1),523 ),524 # 199.88 ---------525 # ----------------526 FramerateParseCase(527 source="119.88",528 expected_playback=fractions.Fraction(120000, 1001),529 expected_timebase=fractions.Fraction(120, 1),530 expected_ntsc=True,531 ),532 FramerateParseCase(533 source=119.88,534 expected_playback=fractions.Fraction(120000, 1001),535 expected_timebase=fractions.Fraction(120, 1),536 expected_ntsc=True,537 ),538 FramerateParseCase(539 source=fractions.Fraction(120000, 1001),540 expected_playback=fractions.Fraction(120000, 1001),541 expected_timebase=fractions.Fraction(120, 1),542 expected_ntsc=True,543 ),544 FramerateParseCase(545 source=fractions.Fraction(1001, 120000),546 expected_playback=fractions.Fraction(120000, 1001),547 expected_timebase=fractions.Fraction(120, 1),548 expected_ntsc=True,549 ),550 FramerateParseCase(551 source=(120000, 1001),552 expected_playback=fractions.Fraction(120000, 1001),553 expected_timebase=fractions.Fraction(120, 1),554 expected_ntsc=True,555 ),556 FramerateParseCase(557 source=(1001, 120000),558 expected_playback=fractions.Fraction(120000, 1001),559 expected_timebase=fractions.Fraction(120, 1),560 expected_ntsc=True,561 ),562 FramerateParseCase(563 source="120000/1001",564 expected_playback=fractions.Fraction(120000, 1001),565 expected_timebase=fractions.Fraction(120, 1),566 expected_ntsc=True,567 ),568 FramerateParseCase(569 source="1001/120000",570 expected_playback=fractions.Fraction(120000, 1001),571 expected_timebase=fractions.Fraction(120, 1),572 expected_ntsc=True,573 ),574 FramerateParseCase(575 source=vtc.Framerate("120000/1001"),576 expected_playback=fractions.Fraction(120000, 1001),577 expected_timebase=fractions.Fraction(120, 1),578 expected_ntsc=True,579 ),580 # 120.0 -----------581 # ----------------582 FramerateParseCase(583 source="120",584 expected_playback=fractions.Fraction(120, 1),585 expected_timebase=fractions.Fraction(120, 1),586 ),587 FramerateParseCase(588 source=120,589 expected_playback=fractions.Fraction(120, 1),590 expected_timebase=fractions.Fraction(120, 1),591 ),592 FramerateParseCase(593 source="120.0",594 expected_playback=fractions.Fraction(120, 1),595 expected_timebase=fractions.Fraction(120, 1),596 ),597 FramerateParseCase(598 source=120.0,599 expected_playback=fractions.Fraction(120, 1),600 expected_timebase=fractions.Fraction(120, 1),601 ),602 FramerateParseCase(603 source=fractions.Fraction(120, 1),604 expected_playback=fractions.Fraction(120, 1),605 expected_timebase=fractions.Fraction(120, 1),606 ),607 FramerateParseCase(608 source=fractions.Fraction(1, 120),609 expected_playback=fractions.Fraction(120, 1),610 expected_timebase=fractions.Fraction(120, 1),611 ),612 FramerateParseCase(613 source=(120, 1),614 expected_playback=fractions.Fraction(120, 1),615 expected_timebase=fractions.Fraction(120, 1),616 ),617 FramerateParseCase(618 source=(1, 120),619 expected_playback=fractions.Fraction(120, 1),620 expected_timebase=fractions.Fraction(120, 1),621 ),622 FramerateParseCase(623 source="120/1",624 expected_playback=fractions.Fraction(120, 1),625 expected_timebase=fractions.Fraction(120, 1),626 ),627 FramerateParseCase(628 source="1/120",629 expected_playback=fractions.Fraction(120, 1),630 expected_timebase=fractions.Fraction(120, 1),631 ),632 FramerateParseCase(633 source=vtc.Framerate("120/1"),634 expected_playback=fractions.Fraction(120, 1),635 expected_timebase=fractions.Fraction(120, 1),636 ),637 # ERRORS ----------638 # -----------------639 FramerateParseCase(640 source="Not A FrameRate",641 expected_error=ValueError,642 expected_error_text=(643 "could not parse Framerate value of 'Not A FrameRate'"644 ),645 ),646 FramerateParseCase(647 source=(24, 1, 0),648 expected_error=ValueError,649 expected_error_text=(650 "Framerate tuple value must contain exactly 2 values, got 3"651 ),652 ),653 FramerateParseCase(654 source=b"not a string",655 expected_error=TypeError,656 expected_error_text=(657 "unsupported type for Framerate conversion: <class 'bytes'>"658 ),659 ),660 FramerateParseCase(661 source="not.afloat",662 expected_error=ValueError,663 expected_error_text="could not parse Framerate value of 'not.afloat'",664 ),665 FramerateParseCase(666 source=29.97,667 ntsc_arg=False,668 expected_drop_frame=True,669 expected_error=ValueError,670 expected_error_text=(671 "ntsc must be [True] or [None] if drop_frame is [True]"672 ),673 ),674 FramerateParseCase(675 source=29.97,676 ntsc_arg=False,677 expected_error=ValueError,678 expected_error_text=(679 "non-whole-number floats values cannot be parsed when ntsc=False. "680 "use precise fraction.Fraction value instead"681 ),682 ),683 ]684 for case in cases:685 with self.subTest(str(case)):686 if case.expected_error is not None:687 with self.assertRaises(case.expected_error) as err:688 vtc.Framerate(689 case.source, # type: ignore690 ntsc=case.ntsc_arg,691 dropframe=case.expected_drop_frame,692 )693 self.assertEqual(694 str(err.exception),695 case.expected_error_text,696 "error message text expected",697 )698 continue699 tb = vtc.Framerate(700 case.source, # type: ignore701 ntsc=case.ntsc_arg,702 dropframe=case.expected_drop_frame,703 )704 print("\nPARSED:", tb)705 self.assertEqual(706 tb.playback, case.expected_playback, "playback expected"707 )708 self.assertEqual(709 tb.timebase, case.expected_timebase, "timebase expected"710 )711 self.assertEqual(712 tb.dropframe,713 case.expected_drop_frame,714 "drop frame is expected",715 )716 self.assertEqual(tb.ntsc, case.expected_ntsc, "ntsc value is expected")717 def test_parse_drop_frame(self) -> None:718 fr = vtc.Framerate(29.97, dropframe=True)719 self.assertEqual(720 fr.playback, fractions.Fraction(30000, 1001), "tb frac expected"721 )722 self.assertTrue(fr.dropframe, "tb is drop frame")723 def test_parse_error_drop_frame_bad_value(self) -> None:724 with self.assertRaises(ValueError) as error:725 vtc.Framerate(23.98, dropframe=True)726 self.assertEqual(727 str(error.exception),728 "drop_frame may only be true if framerate is divisible by "729 "30000/1001 (29.97)",730 "error message expected",731 )732 def test_repr(self) -> None:733 class Case(NamedTuple):734 value: vtc.Framerate735 expected: str736 cases: List[Case] = [737 Case(vtc.Framerate(24), "[24]"),738 Case(vtc.Framerate(29.97, ntsc=True), "[29.97 NTSC]"),739 Case(vtc.Framerate(29.97, dropframe=True), "[29.97 NTSC DF]"),740 ]741 for case in cases:742 with self.subTest(str(case.value)):743 self.assertEqual(repr(case.value), case.expected)744 def test_equality(self) -> None:745 class Case(NamedTuple):746 fr1: vtc.Framerate747 fr2: vtc.Framerate748 equal: bool749 cases: List[Case] = [750 Case(vtc.Framerate(23.98), vtc.Framerate(23.98), True),751 Case(vtc.Framerate(23.98), vtc.Framerate("24000/1001"), True),752 Case(vtc.Framerate(23.98), vtc.Framerate("24000/1001", ntsc=False), False),753 Case(vtc.Framerate(23.98), vtc.Framerate(29.97), False),754 Case(vtc.Framerate(29.97, dropframe=True), vtc.Framerate(29.97), False),755 ]756 for case in cases:757 with self.subTest(f"{repr(case.fr1)} == {repr(case.fr2)} | {case.equal}"):758 self.assertEqual(case.equal, case.fr1 == case.fr2, "check equality")759 def test_equality_usupported_type(self) -> None:...
flow.py
Source:flow.py
...28 self.mole_flow = mole_flow29 # flow composition30 if len(mass_fractions) == const.COMP_COUNT:31 self.mass_fractions = rf.norm(mass_fractions)32 self.mole_fractions = rf.convert_mass_to_mole_fractions(33 self.mass_fractions, const.MR)34 self.volume_fractions = rf.convert_mass_to_volume_fractions(35 self.mass_fractions, const.DENSITY)36 elif len(mole_fractions) == const.COMP_COUNT:37 self.mole_fractions = rf.norm(mole_fractions)38 self.mass_fractions = rf.convert_mole_to_mass_fractions(39 self.mole_fractions, const.MR)40 self.volume_fractions = rf.convert_mole_to_volume_fractions(41 self.mole_fractions, const.MR, const.DENSITY)42 elif len(volume_fractions) == const.COMP_COUNT:43 self.volume_fractions = rf.norm(volume_fractions)44 self.mass_fractions = rf.convert_volume_to_mass_fractions(45 self.volume_fractions, const.DENSITY)46 self.mole_fractions = rf.convert_volume_to_mole_fractions(47 self.volume_fractions, const.MR, const.DENSITY)48 elif len(mass_flows) == const.COMP_COUNT:49 self.mass_flows = mass_flows50 self.mass_fractions = rf.convert_flows_to_fractions(mass_flows)51 self.mass_flow = sum(self.mass_flows)52 self.mole_fractions = rf.convert_mass_to_mole_fractions(53 self.mass_fractions, const.MR)54 self.volume_fractions = rf.convert_mass_to_volume_fractions(55 self.mass_fractions, const.DENSITY)56 elif len(volume_flows) == const.COMP_COUNT:57 self.volume_flows = volume_flows58 self.volume_fractions = rf.convert_flows_to_fractions(volume_flows)59 self.std_liquid_volume_flow = sum(self.volume_flows)60 self.mass_fractions = rf.convert_volume_to_mass_fractions(61 self.volume_fractions, const.DENSITY)62 self.mole_fractions = rf.convert_volume_to_mole_fractions(63 self.volume_fractions, const.MR, const.DENSITY)64 elif len(mole_flows) == const.COMP_COUNT:65 self.mole_flows = mole_flows66 self.mole_fractions = rf.convert_flows_to_fractions(self.mole_flows)67 self.mole_flow = sum(self.mole_flows)68 self.mass_fractions = rf.convert_mole_to_mass_fractions(69 self.mole_fractions, const.MR)70 self.volume_fractions = rf.convert_mole_to_volume_fractions(71 self.mole_fractions, const.MR, const.DENSITY)72 # flow rates73 if self.mass_flow:74 self.volume_flows = rf.convert_mass_to_volume_flows(75 self.mass_flows, const.DENSITY)76 self.mole_flows = rf.convert_mass_to_mole_flows(77 self.mass_flows, const.MR)78 self.std_liquid_volume_flow = rf.get_volume_flow_rate(79 self.volume_flows)80 self.mole_flow = rf.get_mole_flow_rate(self.mole_flows)81 elif self.std_liquid_volume_flow:82 self.mass_flows = rf.convert_volume_to_mass_flows(83 self.volume_flows, const.DENSITY)84 self.mole_flows = rf.convert_volume_to_mole_flows(...
pb213.py
Source:pb213.py
1# -------------------------------------------------------------------------------2# Name: pb2133# Purpose: project euler4# Created: 07/02/20155# -------------------------------------------------------------------------------6import numpy7import fractions8import time9import sys10class Problem():11 def __init__(self):12 self.n = 3013 self.size = self.n**214 self.number_iter = 5015 self.transition = numpy.zeros((self.size, self.size))16 def init_transition(self):17 for k in range(self.size):18 i = k // self.n19 j = k % self.n20 if i in range(1, self.n-1):21 if j in range(1, self.n-1):22 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 4)23 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 4)24 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 4)25 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 4)26 elif j == 0:27 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 3)28 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 3)29 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 3)30 else:31 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 3)32 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 3)33 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 3)34 elif i == 0:35 if j in range(1, self.n-1):36 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 3)37 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 3)38 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 3)39 elif j == 0:40 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 2)41 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 2)42 else:43 self.transition[k][(i+1)*self.n+j] = fractions.Fraction(1, 2)44 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 2)45 else:46 if j in range(1, self.n-1):47 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 3)48 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 3)49 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 3)50 elif j == 0:51 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 2)52 self.transition[k][i*self.n+(j+1)] = fractions.Fraction(1, 2)53 else:54 self.transition[k][(i-1)*self.n+j] = fractions.Fraction(1, 2)55 self.transition[k][i*self.n+(j-1)] = fractions.Fraction(1, 2)56 def solve(self):57 self.init_transition()58 mat = numpy.matrix(self.transition)**self.number_iter59 print(round(numpy.sum(numpy.prod(1-mat[:, p]) for p in range(self.size)), 6))60def main():61 start = time.perf_counter()62 u = Problem()63 u.solve()64 print('temps d execution', time.perf_counter() - start, 'sec')65if __name__ == '__main__':...
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!!