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: do not use built-in random and add proper linter check #698

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

jansegre
Copy link
Member

@jansegre jansegre commented Jul 12, 2023

Motivation

Some tests are still using the built-in random module, which makes it so we can't reproduce a random case.

Acceptance Criteria

  • use self.rng (from tests.TestCase) insead of random
  • make self.rng use the seed from self.seed_config, using a random seed when it is None
  • introduce a custom linter script mechanism, porting the version check into it
  • add a custom linter to make sure we don't use the built-in random again

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@jansegre jansegre self-assigned this Jul 12, 2023
@jansegre jansegre requested a review from msbrogli as a code owner July 12, 2023 17:30
@jansegre jansegre force-pushed the refactor/no-builtin-random branch from cdb4777 to a39864a Compare July 12, 2023 18:09
@jansegre jansegre requested a review from luislhl July 12, 2023 18:15
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #698 (33abcac) into master (02a3548) will increase coverage by 0.00%.
The diff coverage is 50.00%.

❗ Current head 33abcac differs from pull request most recent head ba13778. Consider uploading reports for the commit ba13778 to get more accurate results

@@           Coverage Diff           @@
##           master     #698   +/-   ##
=======================================
  Coverage   84.12%   84.12%           
=======================================
  Files         246      246           
  Lines       20448    20450    +2     
  Branches     2759     2760    +1     
=======================================
+ Hits        17201    17203    +2     
  Misses       2673     2673           
  Partials      574      574           
Impacted Files Coverage Δ
hathor/consensus/consensus.py 97.84% <0.00%> (-2.16%) ⬇️
hathor/metrics.py 86.30% <ø> (ø)
hathor/p2p/manager.py 72.58% <100.00%> (ø)
hathor/pubsub.py 96.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

msbrogli
msbrogli previously approved these changes Jul 12, 2023
tests/unittest.py Outdated Show resolved Hide resolved
msbrogli
msbrogli previously approved these changes Jul 12, 2023
@@ -78,15 +78,15 @@ isort-check:
yamllint:
yamllint .

.PHONY: check-version
check-version:
bash ./extras/check_version.sh $(VERSION)
Copy link
Collaborator

@luislhl luislhl Jul 12, 2023

Choose a reason for hiding this comment

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

I think we will need to adapt the .github/workflows/docker.yml, because we used this arg there.

Since you ported it to be an env var, we should set it as an env var there instead. Besides migrating to the new check-custom there as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, right, I'll fix it.

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. I've fixed it and tested with act with a wrong and correct tag and both work as expected.

@jansegre jansegre force-pushed the refactor/no-builtin-random branch from 33abcac to ba13778 Compare July 12, 2023 22:27
@jansegre jansegre merged commit 6a2891f into master Jul 12, 2023
@jansegre jansegre deleted the refactor/no-builtin-random branch July 12, 2023 22:56
@jansegre jansegre mentioned this pull request Jul 24, 2023
2 tasks
This was referenced Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants