U vi@sddlmZmZmZmZmZmZmZddlZddlm Z m Z mZddl m Z ddl mZddlmZddlmZdd lmZdd lmZdd lmZed ZGd ddeZdS))AnyCallableListOptionalTypeVarUnioncastN) Observableabctyping) Disposable)VirtualTimeScheduler)Recorded)ColdObservable) HotObservable MockObserver) ReactiveTest_TcseZdZdZdZdejejeee j dfdd Z de e geefe ee ee eeedfdd Zeeeeeefeed d d Zeeeeeefeed d dZeedddZZS) TestSchedulerzTest time scheduler used for testing applications and libraries built using Reactive Extensions. All time, both absolute and relative is specified as integer ticksFN)duetimeactionstatereturncs(t|tr|n||}t|||S)aSchedules an action to be executed at the specified virtual time. Args: duetime: Absolute virtual time at which to execute the action. action: Action to be executed. state: State passed to the action to be executed. Returns: Disposable object used to cancel the scheduled action (best effort). ) isinstancefloatZ to_secondssuperschedule_absolute)selfrrr __class__P/opt/alt/python38/lib/python3.8/site-packages/reactivex/testing/testscheduler.pyrszTestScheduler.schedule_absolute)createcreated subscribeddisposedrcs|ptj}|ptj}|ptj}|ddd tjttjdfdd }| ||d tjttjdfdd }| ||d tjttjdfdd }| ||t S) a$Starts the test scheduler and uses the specified virtual times to invoke the factory function, subscribe to the resulting sequence, and dispose the subscription. Args: create: Factory method to create an observable sequence. created: Virtual time at which to invoke the factory to create an observable sequence. subscribed: Virtual time at which to subscribe to the created observable sequence. disposed: Virtual time at which to dispose the subscription. Returns: Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active. N) schedulerrrcsdk rnttS)z&Called at create time. Defaults to 100N) reactivexneverr r(r)r$sourcer"r# action_createRsz*TestScheduler.start..action_createcsrj|dtS)z)Called at subscribe time. Defaults to 200)r() subscriber r+)observerr, subscriptionr"r#action_subscribe\sz-TestScheduler.start..action_subscribecsr tS)z(Called at dispose time. Defaults to 1000)Zdisposer r+)r0r"r#action_disposegsz+TestScheduler.start..action_dispose)N)N)N) rr%r&r'create_observerr Z SchedulerBaserDisposableBaserrstart)rr$r%r&r'r-r1r2r )r$r/r,r0r#r5/s:       zTestScheduler.start)argsrcGs<|rt|dtr|d}nttttt|}t||S)aCreates a hot observable using the specified timestamped notification messages either as a list or by multiple arguments. Args: messages: Notifications to surface through the created sequence at their specified absolute virtual times. Returns hot observable sequence that can be used to assert the timing of subscriptions and notifications. r)rrrrrlistrrr6messagesr"r"r#create_hot_observablets z#TestScheduler.create_hot_observablecGs<|rt|dtr|d}nttttt|}t||S)aCreates a cold observable using the specified timestamped notification messages either as an array or arguments. Args: args: Notifications to surface through the created sequence at their specified virtual time offsets from the sequence subscription time. Returns: Cold observable sequence that can be used to assert the timing of subscriptions and notifications. r)rr7rrrrrr8r"r"r#create_cold_observables z$TestScheduler.create_cold_observable)rcCst|S)zCreates an observer that records received notification messages and timestamps those. Return an Observer that can be used to assert the timing of received notifications. r)rr"r"r#r3szTestScheduler.create_observer)N)NNNN)__name__ __module__ __qualname____doc__Z__test__r Z AbsoluteTimeZScheduledActionrr r4rrrr rrrr5rrrrr:rr;r3 __classcell__r"r"r r#rs6F  r)r rrrrrrrr)r r Zreactivex.disposabler Zreactivex.schedulerr Zreactivex.testing.recordedrZcoldobservablerZ hotobservablerZ mockobserverrZ reactivetestrrrr"r"r"r#s$