Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing truncate() call on BytesIO object #52

Merged
merged 2 commits into from Apr 5, 2017

Conversation

toudi
Copy link
Contributor

@toudi toudi commented Apr 5, 2017

When subsequent payload to be pushed by mocket was shorter than previous one, additional data were dumped. This was because BytesIO object had longer length; calling truncate() on the BytesIO object solves this problem

code to reproduce the problem, before this patch:

@mocketize
def test_something():
    Mocket.register(
        MocketEntry(
            ('example.com', 80),
            [
                b'this is some long payload'
                b'short',
            ]
        ),
    )

then, when one would use socket object, and call recv on it, one would get part of the first payload with the second call

one, additional data were dumped. This was because BytesIO object had
the longer length; calling truncate() on the BytesIO object solves this
problem
@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage increased (+0.002%) to 99.101% when pulling ea61139 on toudi:add-missing-truncate-call into 53cc4cf on mindflayer:master.

@toudi
Copy link
Contributor Author

toudi commented Apr 5, 2017

I don't know why travis build is failing on 3.7

output from my own py.test:

platform linux -- Python 3.7.0a0, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/toudi/.pyenv/versions/3.7-dev/bin/python3.7
cachedir: .cache
rootdir: /home/toudi/projects/prywatne/python-mocket, inifile: setup.cfg
plugins: cov-2.4.0
collected 14 items 

tests/main/test_http.py::TrueHttpEntryTestCase::test_truesendall PASSED
tests/main/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_chunk_recording PASSED
tests/main/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_dump_from_recording PASSED
tests/main/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_gzip_recording PASSED
tests/main/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_recording PASSED
tests/main/test_http.py::TrueHttpEntryTestCase::test_wrongpath_truesendall PASSED
tests/main/test_http.py::HttpEntryTestCase::test_file_object PASSED
tests/main/test_http.py::HttpEntryTestCase::test_multipart PASSED
tests/main/test_http.py::HttpEntryTestCase::test_register PASSED
tests/main/test_http.py::HttpEntryTestCase::test_request_bodies PASSED
tests/main/test_http.py::HttpEntryTestCase::test_same_url_different_methods PASSED
tests/main/test_http.py::HttpEntryTestCase::test_sendall PASSED
tests/main/test_http.py::HttpEntryTestCase::test_sendall_double PASSED
tests/main/test_http.py::HttpEntryTestCase::test_sendall_json PASSED

----------- coverage: platform linux, python 3.7.0-alpha-0 -----------
Name                                 Stmts   Miss  Cover   Missing
------------------------------------------------------------------
mocket/__init__.py                       4      0   100%
mocket/mocket.py                       266     30    89%   59, 66-78, 84, 88, 91, 124, 141, 144-148, 170-172, 206, 326-327, 379, 389, 394-396, 404, 435
mocket/mockhttp.py                      84      1    99%   75
mocket/mockredis.py                     48     48     0%   2-77
mocket/plugins/__init__.py               0      0   100%
mocket/plugins/pook_mock_engine.py      43     43     0%   1-65
------------------------------------------------------------------
TOTAL                                  445    122    73%

@mindflayer mindflayer merged commit 1483f9d into mindflayer:master Apr 5, 2017
@mindflayer
Copy link
Owner

Thank you so much for your contribution. I have no idea on why this is failing but I'm sure I've seen the error before, and I am still not able to reproduce it.

@mindflayer
Copy link
Owner

@toudi are you actively using mocket? If so, in which way? Feel free to point me to a public repo, if this is the case.

@toudi
Copy link
Contributor Author

toudi commented Apr 5, 2017

@mindflayer I am writing unit tests for websocket library => https://github.com/wildfoundry/dataplicity-lomond

how can I download new version from pypi ?

@mindflayer
Copy link
Owner

You mean you'd like to install a new version with your patch?

@toudi
Copy link
Contributor Author

toudi commented Apr 5, 2017

well, I thought this was the whole point of patching code :D otherwise I would have to point tox / pytest to github repo

@mindflayer
Copy link
Owner

mindflayer commented Apr 5, 2017 via email

@toudi
Copy link
Contributor Author

toudi commented Apr 5, 2017

lol, no problem ;)

@mindflayer
Copy link
Owner

mindflayer commented Apr 5, 2017

Enjoy it!
https://pypi.python.org/pypi/mocket/1.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants