Skip to content

Commit

Permalink
split
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherry committed Nov 22, 2024
1 parent 640a19e commit 9bb921c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions livekit-rtc/tests/test_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,32 @@ def test_args():

args_calls = []

@emitter.on("whatever_args")
@emitter.on("whatever")
def on_whatever(first, second, third):
args_calls.append((first, second, third))

emitter.emit("whatever_args", 1, 2, 3)
emitter.emit("whatever_args", 1, 2, 3, 4, 5) # only 3 arguments will be passed
emitter.emit("whatever", 1, 2, 3)
emitter.emit("whatever", 1, 2, 3, 4, 5) # only 3 arguments will be passed

assert args_calls == [(1, 2, 3), (1, 2, 3)]

with pytest.raises(TypeError):
emitter.emit("whatever_args", 1, 2)
emitter.emit("whatever", 1, 2)


def test_varargs():
EventTypes = Literal["whatever"]

emitter = EventEmitter[EventTypes]()

varargs_calls = []

@emitter.on("whatever_varargs")
@emitter.on("whatever")
def on_whatever_varargs(*args):
varargs_calls.append(args)

emitter.emit("whatever_varargs", 1, 2, 3, 4, 5)
emitter.emit("whatever_varargs", 1, 2)
emitter.emit("whatever", 1, 2, 3, 4, 5)
emitter.emit("whatever", 1, 2)

assert varargs_calls == [(1, 2, 3, 4, 5), (1, 2)]

Expand Down

0 comments on commit 9bb921c

Please sign in to comment.