--- you can reply above this line ---

New issue 228: Recwarn empty
https://bitbucket.org

Danilo Bellini:

Problem: Test if a function "creates" warnings or if it don't create any.

Solution:

1. For now, I'm not using "recwarn", since it didn't work in my code.
2. Call the warning creator routine inside a warnings.catch_warnings context 
manager.
3. Call warnings.simplefilter("always") before the context manager (somehow, it 
don't work when "inside" the context manager).

The code is in:

https://github.com/danilobellini/audiolazy/blob/0fe2586bb81d9bc266998ce478a267a2659d4076/audiolazy/test/test_stream.py#L235

However, I think I should be using the recwarn funcarg. I tryed this:

    class TestThub(object):
    
        @p("copies", range(5))
        @p("used_copies", range(5))
        def test_stream_tee_hub_memory_leak_warning_and_index_error(
                self, copies, used_copies, recwarn):
            data = Stream(.5, 8, 7 + 2j)
            data = thub(data, copies)
            assert isinstance(data, StreamTeeHub)
            if copies < used_copies:
                with pytest.raises(IndexError):
                    [data * n for n in xrange(used_copies)]
            else:
                [data * n for n in xrange(used_copies)]
                data.__del__()
                if copies != used_copies:
                    w = recwarn.pop()
                    assert issubclass(w.category, MemoryLeakWarning)
                    assert str(copies - used_copies) in str(w.message)
                assert recwarn.list == []

That did't work: the test in the link works, the test above "misses"/filters 
some warn() calls, and an error is given when "recwarn.pop()" is called with an 
empty recwarn. But only when used_copies > 0 (i.e., it works when used_copies 
== 0 and copies > 0).

Also, the recwarn.list isn't documented anywhere. I wanted to assert "there's 
no warning" and found no documented way with recwarn. Perhaps I can use the 
pop() method in a try block, but I think the list comparison is simpler.


--

This is an issue notification from bitbucket.org. You are receiving
this either because you are the owner of the issue, or you are
following the issue.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to