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

adding round trip test for lzma #16

Merged
merged 14 commits into from
May 25, 2020
Merged

adding round trip test for lzma #16

merged 14 commits into from
May 25, 2020

Conversation

Cheukting
Copy link
Contributor

Adding the round trip test for lzma. Only option that is testing is the compresslever (preset) however, according to the documentation there are other options such as format=FORMAT_XZ, check=-1 Shall I add that? I know I can use st.build to add them (cannot use sampled from because some options are only available to certain settings)

@Cheukting
Copy link
Contributor Author

Travis failed but I have run the tests locally right after I have clone the repo (before changing anything) and it failed, so hope it's not because of me 😛

@pganssle
Copy link
Collaborator

@Cheukting I believe this is failing because of the formatting check. If you run tox -e check locally it will reformat your code and you can commit that. (On mobile I can't really see the difference in the Travis diff, so I assume it's a whitespace thing).

@Zac-HD
Copy link
Owner

Zac-HD commented May 17, 2020

there are other options such as format=FORMAT_XZ, check=-1 Shall I add that? I know I can use st.builds() to add them (cannot use st.sampled_from() because some options are only available to certain settings)

Yes, please do! You can actually use st.sampled_from(), and then use hypothesis.assume() inside the test to reject any invalid combinations.

@Cheukting
Copy link
Contributor Author

I break it into 2 cases, I think that's easier than using assume. However, I got this error:

======================================================================
ERROR: test_lzma_round_trip_format_xz (tests.test_compression.TestLZMA)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/cheuktingho/Contribution/stdlib-property-tests/tests/test_compression.py", line 53, in test_lzma_round_trip_format_xz
    payload=st.binary(),
  File "/Users/cheuktingho/.pyenv/versions/stdlib-test/lib/python3.7/site-packages/hypothesis/core.py", line 1102, in wrapped_test
    raise the_error_hypothesis_found
  File "/Users/cheuktingho/Contribution/stdlib-property-tests/tests/test_compression.py", line 62, in test_lzma_round_trip_format_xz
    payload, format="FORMAT_XZ", check=check, preset=compresslevel
  File "/Users/cheuktingho/.pyenv/versions/3.7.3/lib/python3.7/lzma.py", line 318, in compress
    comp = LZMACompressor(format, check, preset, filters)
TypeError: an integer is required (got type str)

Which I don't understand when I look at the source code: https://github.com/python/cpython/blob/c1f1ddf30a595c2bfa3c06e54fb03fa212cd28b5/Lib/zipfile.py#L612

Can't see where the arguments are taken here.

@Zac-HD
Copy link
Owner

Zac-HD commented May 18, 2020

Nice, that looks good.

The 'bug' in your test is that format="FORMAT_XZ" should be format=lzma.FORMAT_XZ - it's a module-level constant (which happens to be an integer imported from the _lzma module, but that's not relevant to us).

As a style issue, I think it would be easier for readers to compare these two tests if we pass the same arguments to each. That means adding format=st.just(lzma.FORMAT_XZ) to the first; though I think I prefer to omit the check argument (i.e. keep the status quo) over check=st.just(-1), since there doesn't seem to be a named constant for that default argument.

@Zac-HD
Copy link
Owner

Zac-HD commented May 18, 2020

Main hint is to pip install tox and then run tox locally - it'll do all the formatting for you, as well as installing all the dependencies in a virtual environment and running the tests.

@Zac-HD
Copy link
Owner

Zac-HD commented May 19, 2020

I suggest using @st.composite to write a custom strategy lzma_filters(), which should make reading the error messages a lot easier, at least.

After that I'd make the strategy less general, until the test passes, and just leave a # TODO: comment block explaining that we're only testing a small subset of possible filters. That's a much better starting point for future testers than the there-is-no-test status quo!

@Cheukting
Copy link
Contributor Author

Yes, I can rewrite the filter strategy. Will try another push today.

@Cheukting
Copy link
Contributor Author

I have rewritten the filter strategy, will try to loosen the test to make it pass.

tests/test_compression.py Outdated Show resolved Hide resolved
Comment on lines +20 to +21
-U
git+https://github.com/Zac-HD/hypothesmith.git
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase on master to get rid of this bit.

@Zac-HD
Copy link
Owner

Zac-HD commented May 20, 2020

Cross-reference: HypothesisWorks/hypothesis#2430

@Cheukting
Copy link
Contributor Author

refactor again, will need some thought on the test cases. Will continue later today

@Zac-HD Zac-HD merged commit dad48fa into Zac-HD:master May 25, 2020
@Zac-HD
Copy link
Owner

Zac-HD commented May 25, 2020

🎉

Thanks @Cheukting!

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.

3 participants