numberoverzero / bottom

asyncio-based rfc2812-compliant IRC Client
http://bottom-docs.readthedocs.io
MIT License
74 stars 23 forks source link

return event name from RawClient.wait() #47

Closed Yay295 closed 7 years ago

Yay295 commented 7 years ago

Not particularly useful on it's own, but very useful when using the wait_for function as implemented in examples/common.py.

codecov[bot] commented 7 years ago

Codecov Report

Merging #47 into master will decrease coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
- Coverage   99.31%   99.31%   -0.01%     
==========================================
  Files           5        5              
  Lines         436      435       -1     
  Branches      119      119              
==========================================
- Hits          433      432       -1     
  Misses          2        2              
  Partials        1        1
Impacted Files Coverage Δ
bottom/client.py 98.95% <100%> (+0.01%) :arrow_up:
bottom/pack.py 100% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bab0f3b...16c8054. Read the comment docs.

Yay295 commented 7 years ago

I'm not really sure how to make a test, but I think it should look something like that. Though not exactly that apparently.

numberoverzero commented 7 years ago

I'll pull that down and see if I can fix it. The structure looks correct from here..

numberoverzero commented 7 years ago

Sneaky! Needs a nonlocal (and an extra space before the function definition for flake8).

Can you allow changes for pull requests or change the function to the following?

def test_wait_return_value(client, flush):
    """ The value returned should be the same as the value given. """
    event_name = "test_wait_return_value"
    returned_name = ""

    async def waiter():
        nonlocal returned_name
        returned_name = await client.wait(event_name)

    client.loop.create_task(waiter())
    flush()
    client.trigger(event_name)
    flush()
    assert returned_name is event_name
numberoverzero commented 7 years ago

Woo! Thanks for the enhancement :)