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

Added hypothesis based tesing to SyncedCollection #373

Conversation

vishav1771
Copy link
Contributor

@vishav1771 vishav1771 commented Aug 2, 2020

Description

Added hypothesis based tesing to SyncedCollection

Motivation and Context

Related to #249

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

If necessary:

  • I have updated the API documentation as part of the package doc-strings.
  • I have created a separate pull request to update the framework documentation on signac-docs and linked it here.
  • I have updated the changelog and added all related issue and pull request numbers for future reference (if applicable). See example below.

Example for a changelog entry: Fix issue with launching rockets to the moon (#101, #212).

@vishav1771 vishav1771 requested review from a team as code owners August 2, 2020 21:27
@vishav1771 vishav1771 requested review from bdice, cbkerr and a team and removed request for a team August 2, 2020 21:27
@codecov
Copy link

codecov bot commented Aug 2, 2020

Codecov Report

Merging #373 into feature/synced_collections will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@                     Coverage Diff                     @@
##           feature/synced_collections     #373   +/-   ##
===========================================================
  Coverage                       77.28%   77.28%           
===========================================================
  Files                              47       47           
  Lines                            7453     7453           
===========================================================
  Hits                             5760     5760           
  Misses                           1693     1693           

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 7605b6b...1133dbb. Read the comment docs.

Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

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

Hi @vishav1771, I have review requests attached. Overall, it's important to be sure that test refactorings do not change the behavior of tests. Please take a look at my comments. I recommend that other reviewers wait to review this thoroughly until this first round of comments are handled.

@@ -11,3 +11,4 @@ pytest-subtests==0.3.1
pydocstyle==5.0.2
pytest-cov==2.10.0
pymongo==3.10.1
hypothesis==5.23.7
Copy link
Member

Choose a reason for hiding this comment

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

Just so you know, hypothesis changes its version numbers a lot. Every PR that is merged causes a version update.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that any action needs to be taken -- just letting you know.

@@ -22,12 +26,20 @@
except ImportError:
NUMPY = False

# changing default deadline of hypothesis
settings.register_profile('ci', deadline=600)
Copy link
Member

Choose a reason for hiding this comment

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

Is this configurable via setup.cfg or another file? If so, I would prefer that.

FN_JSON = 'test.json'

PRINTABLE_NO_DOTS = printable.replace('.', ' ')

JSONDataStrategy = st.recursive(
Copy link
Member

Choose a reason for hiding this comment

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

It may be desirable to put all of our strategies into a separate module like strategies.py if they are re-used in multiple test files.

JSONDataStrategy = st.recursive(
st.none() | st.booleans() | st.floats(allow_nan=False) | st.text(printable),
lambda children: st.lists(children, max_size=5) | st.dictionaries(
st.text(PRINTABLE_NO_DOTS), children, max_size=5), max_leaves=5)
Copy link
Member

Choose a reason for hiding this comment

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

Define this after DictKeyStrategy and replace:

Suggested change
st.text(PRINTABLE_NO_DOTS), children, max_size=5), max_leaves=5)
DictKeyStrategy, children, max_size=5), max_leaves=5)

Comment on lines 73 to 74
_backend_kwargs = {'filename': self._fn_, 'write_concern': False}
yield JSONDict(**_backend_kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should just be defined in one line. We're not using any inheritance from the base class to the children classes so I don't see a reason to have the extra variable here.

Suggested change
_backend_kwargs = {'filename': self._fn_, 'write_concern': False}
yield JSONDict(**_backend_kwargs)
yield JSONDict(filename=self._fn_, write_concern=False)

@@ -520,22 +546,30 @@ def test_update_recursive(self, synced_list):
self.store(data1)
assert synced_list == data1

# inavlid data in file
# invalid data in file
Copy link
Member

Choose a reason for hiding this comment

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

😄

data2 = {'a': 1}
self.store(data2)
with pytest.raises(ValueError):
synced_list.load()

# reset the file
Copy link
Member

Choose a reason for hiding this comment

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

This may be another example of the same problematic pattern with pytest fixtures / hypothesis. I commented on this specifically because it doesn't look like the other instances and would be easy to miss in a refactoring.

synced_list2.load()
assert len(synced_list2) == 1
synced_list.clear()
synced_list2 = deepcopy(synced_list) # possibly unsafe
Copy link
Member

Choose a reason for hiding this comment

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

Why is this possibly unsafe? The previous code did not indicate that it could be unsafe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in reference to the warning we added to JSONDict. I forgot to add this last time.

assert synced_list2[0] == testdata
del synced_list2 # possibly unsafe
Copy link
Member

Choose a reason for hiding this comment

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

This deletes the copy instead of the original. This changes the behavior of the test! ⚠️ Too many variables were switched in this test -- I'm not sure if the refactoring you've done here is correct. Please look carefully.

@given(st.lists(JSONDataStrategy, max_size=5), JSONDataStrategy)
def test_nested_list(self, synced_list, testdata_list, testdata):
synced_list.reset([testdata_list])
child1 = synced_list[0]
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right. In the old code, child1 is a list: [2, 4]. Here, it looks like child1 is a "data element" (not a list). Carefully review this test.

@csadorf
Copy link
Contributor

csadorf commented Aug 4, 2020

I have no time to review this right now. But it seems to me that there are a lot of problems with hypothesis in combination with pytest and fixtures. I therefore recommend to abandon this refactoring effort.

@bdice
Copy link
Member

bdice commented Aug 4, 2020

I agree with @csadorf and stopped just short of making the same recommendation (I was tired when I finished reviewing).

@vishav1771 in terms of maximizing what you can accomplish with your last month of GSoC, I'd really like to see you work towards buffering, caching, and lazy loading. This testing PR could be picked up and finished at a later time. The expertise you've developed this summer in signac's internal data structures should be our first focus! 😊

@vishav1771
Copy link
Contributor Author

I'm closing this PR for now. Will pick up it at later.

@vishav1771 vishav1771 closed this Aug 4, 2020
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