Minor update to common.format_seconds
#414
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@micahflee ,
I used
divmod
to declutter and simplify the calculation of days, hours, minutes and seconds. Importingmath
becomes unnecessary (although I didn't remove themath
import yet though since my other PR #413 rearranges the imports to one line each and I didn't want a merge conflict).I made one other change. The current implementation of
format_seconds
returns an empty string ifseconds == 0
. Although the odds are quite small of that actually happening, I thought0s
might fit better with the theme of "human-readable". That is what the extra check inif seconds or not human_readable
is for.I've actually been writing tests for these last couple functions I've sent PR's for. I didn't want to push them yet since they were using
pytest
specific tests. Example:Instead of writing one function per test,
parametrize
helps to cut down on verbosity. As you probably know, stacking multiple asserts inside one regular test function has the disadvantage of stopping after the first fail and not running any tests left below it. Also, less helpful error messages.Anyways, if you approve of using
pytest
then I would gladly send a PR with these types of tests.