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

Refactor hash generation for testability #368

Merged
merged 4 commits into from
May 18, 2018
Merged

Conversation

sigmavirus24
Copy link
Member

After reviewing #367 I realized that this code could be more easily
tested if it was broken out from the PackageFile object. Since it was
such a tiny refactor, I went ahead, refactored it and added the
necessary tests to ensure this just works.

cc @dralley

tox.ini Outdated
@@ -6,6 +6,7 @@ deps =
coverage
pretend
pytest
py27,pypy: pyblake2
Copy link
Member Author

Choose a reason for hiding this comment

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

hashlib on py2 doesn't have a blake2b hash but pyblake2 is used for backwards compatibility there so let's install it for our testing purposes.

blake_update(content)
hasher = HashManager(filename)
hasher.hash()
hexdigest = hasher.hexdigest()
Copy link
Member Author

Choose a reason for hiding this comment

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

We could also return a namedtuple here instead of a dictionary. I didn't think it mattered much either way right now

Copy link
Member

Choose a reason for hiding this comment

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

I definitely prefer namedtuples over dicts for cases like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️ Done

return self._blake_hasher.hexdigest()
return None

def hash(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

This could get called automagically, or we could add a function that creates the object, calls this method, and then returns the hexdigest, but I wasn't sure that was necessary either

@dralley
Copy link
Contributor

dralley commented May 18, 2018

cool, thanks @sigmavirus24

Copy link
Member

@theacodes theacodes left a comment

Choose a reason for hiding this comment

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

LGTM

blake_update(content)
hasher = HashManager(filename)
hasher.hash()
hexdigest = hasher.hexdigest()
Copy link
Member

Choose a reason for hiding this comment

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

I definitely prefer namedtuples over dicts for cases like this.

After reviewing #367 I realized that this code could be more easily
tested if it was broken out from the PackageFile object. Since it was
such a tiny refactor, I went ahead, refactored it and added the
necessary tests to ensure this just works.
@codecov
Copy link

codecov bot commented May 18, 2018

Codecov Report

Merging #368 into master will increase coverage by 1.22%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
+ Coverage   73.33%   74.55%   +1.22%     
==========================================
  Files          13       13              
  Lines         645      672      +27     
  Branches       99      101       +2     
==========================================
+ Hits          473      501      +28     
+ Misses        143      142       -1     
  Partials       29       29
Impacted Files Coverage Δ
twine/package.py 86.6% <93.75%> (+5.43%) ⬆️

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 75d3cd8...c85fd6c. Read the comment docs.

@sigmavirus24 sigmavirus24 merged commit 34c08ef into master May 18, 2018
@sigmavirus24 sigmavirus24 deleted the hashing-and-testing branch May 18, 2018 19:25
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