U vi@sddlmZddlmZmZmZmZmZmZm Z m Z ddl m Z ddl Z ddl mZmZddlmZmZmZddlmZddlmZdd lmZmZd d lmZd d lmZd d lmZeZ GdddeZ!edeee!ddfdddZ"ee ejeefeeedddZ#dS))contextmanager)AnyDict GeneratorList NamedTupleOptionalTupleUnion)warnN) Observabletyping) NotificationOnErrorOnNext)parse)NewThreadScheduler)Callable RelativeTime) ReactiveTest)Recorded) TestSchedulerc@seZdZUeeeeegeeffgeeefe d<ee e e ee e fefe egeefe d<ee e e ee e fefe egeefe d<ee e e ee e fefe egeeefe d<dS)MarblesContextstartZcoldhotexpN)__name__ __module__ __qualname__rr r rrr__annotations__strrrfloat Exceptionr$r$J/opt/alt/python38/lib/python3.8/site-packages/reactivex/testing/marbles.pyrs$ (    r?)timespanreturnc#s<tdddddddfdd ttttgttfftttd fd d }dttt ttt ftftt tttd fd d }dttt ttt ftftt ttd fdd }dttt ttt ftftt ttd fdd }zt ||||VW5dXdS)as Initialize a :class:`rx.testing.TestScheduler` and return a namedtuple containing the following functions that wrap its methods. :func:`cold()`: Parse a marbles string and return a cold observable :func:`hot()`: Parse a marbles string and return a hot observable :func:`start()`: Start the test scheduler, invoke the create function, subscribe to the resulting sequence, dispose the subscription and return the resulting records :func:`exp()`: Parse a marbles string and return a list of records Examples: >>> with marbles_testing() as (start, cold, hot, exp): ... obs = hot("-a-----b---c-|") ... ex = exp( "-a-----b---c-|") ... results = start(obs) ... assert results == ex The underlying test scheduler is initialized with the following parameters: - created time = 100.0s - subscribed = 200.0s - disposed = 1000.0s **IMPORTANT**: regarding :func:`hot()`, a marble declared as the first character will be skipped by the test scheduler. E.g. hot("a--b--") will only emit b. gY@g@@gi@FNr(cs(rtdtddr$tdtdddS)NzAcontext functions should not be called outside of with statement.) stacklevelz?start() should only be called one time inside a with statement.)r UserWarningr$)outside_of_context start_calledr$r%checkTszmarbles_testing..check)creater(csPt|tr0|ttdfdd }|}n|}j|d}d|jS)Nr)csS)Nr$r$Zcreate_r$r%default_createlsz;marbles_testing..test_start..default_create)r0created subscribeddisposedT) isinstancer rrmessages)r0r2Zcreate_functionZ mock_observer)r/r3r5 schedulerr.r4r1r% test_startcs z#marbles_testing..test_start)stringlookuperrorr(cst|||d}t|S)N)r'Z time_shiftr;r<)rmessages_to_records)r:r;r<r7)r4r'r$r% test_expected|sz&marbles_testing..test_expectedcstj|||dS)N)r'r;r<) reactivexZ from_marbles)r:r;r<)r/r'r$r% test_coldsz"marbles_testing..test_coldcs tj|||d}|S)N)r'Zduetimer;r<r8)r?r)r:r;r<Zhot_obs)r/r8r4r'r$r%test_hotsz!marbles_testing..test_hotT)NN)NN)NN) rr r rrrrr!rrr"r#r)r'r9r>r@rAr$)r/r3r5r-r8r.r4r'r%marbles_testing%sJ(  rB)r7r(cCsg}|D]v}|\}}t|ttfr,t|}n |jd}t|trPt||j}n$t|trjt ||j }n t |}| |q|S)z\ Helper function to convert messages returned by parse() to a list of Recorded. i) r6intr" microsecondsrrZon_nextvaluerZon_error exceptionZ on_completedappend)r7recordsmessagetimeZ notificationZtime_recordr$r$r%r=s      r=)r&)$ contextlibrr rrrrrrr r warningsr r?r Zreactivex.notificationrrrZreactivex.observable.marblesrZreactivex.schedulerrZreactivex.typingrrZ reactivetestrZrecordedrZ testschedulerrZnew_thread_schedulerrrBr=r$r$r$r%s. (