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

Spruce up deterministic_cache #1195

Merged
merged 1 commit into from
Aug 17, 2018
Merged

Conversation

langner
Copy link
Member

@langner langner commented Aug 16, 2018

Next bit for #347.

This includes several things:

  • Improved (hopefully) docstrings and a module docstring with a little example
  • Moved cache key helper functions to module level - these were static methods so it felt natural to move them out of the class... but I'm not 100% there was a reason for doing this. If so, I can move back, although @staticmethod IMO is best used sparingly.
  • Refactored unit tests to test public API instead of the internal helper funcs. Again, assumed this is a good thing, but not 100% there wasn't some decision to test internal functions throughout the library.

Copy link
Member

@drvinceknight drvinceknight left a comment

Choose a reason for hiding this comment

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

This looks great to me: thank you @langner 👍

The failure on appveyor is (again) because of #1187: once #1194 is merged that should hopefully (almost certainly!) stop happening :)

@drvinceknight
Copy link
Member

The failure on appveyor is (again) because of #1187: once #1194 is merged that should hopefully (almost certainly!) stop happening :)

I've set the build going again.

cache[key2] = result2
...
if some_key in cache:
do_something(cache[some_key]
Copy link
Member

Choose a reason for hiding this comment

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

nit: missing )

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.

"""Validate a deterministic cache player key.

The key should always be a 3-tuple, with a pair of axelrod.Player
instnaces and one integer. Both players should be deterministic.
Copy link
Member

Choose a reason for hiding this comment

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

nit: instances

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.

@@ -27,6 +28,9 @@ def tearDownClass(cls):
os.remove(cls.test_save_file)
os.remove(cls.test_load_file)

def setUp(self):
self.cache = DeterministicCache()
Copy link
Member

Choose a reason for hiding this comment

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

Does this create a shared cache across all tests? That could cause some confusion.

Copy link
Member

Choose a reason for hiding this comment

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

I see that the tests all appear logically correct in that self.cache is only used for expected invalid keys, however I think I'd prefer that they each instantiate a new one.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. But since setUp is called before every test method, self.cache is assigned a new, empty cache for each one. Was that your concern?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, thanks for the explanation.

* Improve docstrings and add module docstring
* Move key helper functions to module level
* Refactored unit tests to test public API
@marcharper marcharper merged commit ab03629 into Axelrod-Python:master Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants