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

Changed testing framework (Pytest) #275

Merged
merged 19 commits into from
Jan 29, 2020
Merged

Conversation

vishav1771
Copy link
Contributor

@vishav1771 vishav1771 commented Jan 23, 2020

Description

Changed testing framework from Unittest to Pytest

Motivation and Context

Fixes #212

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 January 23, 2020 20:38
@vishav1771 vishav1771 requested review from csadorf and removed request for a team January 23, 2020 20:38
@vishav1771 vishav1771 changed the title Changed testing framework (Pytest) [WIP]Changed testing framework (Pytest) Jan 23, 2020
@vishav1771 vishav1771 requested a review from vyasr January 23, 2020 20:40
@bdice
Copy link
Member

bdice commented Jan 24, 2020

@vishav1771 Nice work! I'm not able to review this PR right now (nor am I assigned) but I wanted to say thank you, since this is a pretty large task. 😄

@bdice bdice added the enhancement New feature or request label Jan 24, 2020
@vyasr
Copy link
Contributor

vyasr commented Jan 24, 2020

I agree, this is fantastic! I'll have a look at this as soon as possible.

Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

@vishav1771 Thank you for spearheading this effort! That's awesome!

I've started reviewing, but it will obviously take a bit of time to actually complete this due to the sheer volume of proposed changes. I can already promise that I will not be able to do this before the beginning of next week.

However, if you could in the meantime respond to my initial comments and change requests and also look into reasons behind the falling CI pipeline that would help accelerate the process and be very much appreciated.

tests/test_buffered_mode.py Outdated Show resolved Hide resolved

def test_basic_and_nested(self):
def test_basic_and_nested(self,setUp):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand the purpose of the setUp argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setUp is the function we want to run before running test

Copy link
Contributor

@csadorf csadorf Jan 27, 2020

Choose a reason for hiding this comment

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

But it is not actually executed, is it?

tests/test_h5store.py Outdated Show resolved Hide resolved
tests/test_h5store.py Outdated Show resolved Hide resolved
tests/test_h5store.py Outdated Show resolved Hide resolved
@csadorf
Copy link
Contributor

csadorf commented Jan 24, 2020

Also, I forgot to mention: You've marked the PR as work-in-progress ([WIP]), GitHub has recently added a feature to mark PRs as work-in-progress directly when you open them. Would be great if you could use that feature next time, because it prevents the bot from automatically assigning reviewers and you have better control in signalling them when the PR is actually ready for review.

@vishav1771
Copy link
Contributor Author

Sure, I will keep in mind next time :)

@codecov
Copy link

codecov bot commented Jan 25, 2020

Codecov Report

Merging #275 into master will increase coverage by 0.02%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
+ Coverage   64.91%   64.93%   +0.02%     
==========================================
  Files          40       40              
  Lines        5626     5635       +9     
==========================================
+ Hits         3652     3659       +7     
- Misses       1974     1976       +2
Impacted Files Coverage Δ
signac/core/synceddict.py 95.92% <100%> (+0.9%) ⬆️
signac/contrib/import_export.py 84.89% <100%> (+0.11%) ⬆️
signac/contrib/project.py 90.51% <50%> (-0.36%) ⬇️
signac/core/jsondict.py 95.32% <0%> (-0.59%) ⬇️

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 745d307...8115f86. Read the comment docs.

@vishav1771 vishav1771 changed the title [WIP]Changed testing framework (Pytest) Changed testing framework (Pytest) Jan 25, 2020
tests/test_diff.py Outdated Show resolved Hide resolved
tests/test_h5store.py Outdated Show resolved Hide resolved
tests/test_h5store.py Outdated Show resolved Hide resolved
tests/test_h5store.py Outdated Show resolved Hide resolved
tests/test_job.py Outdated Show resolved Hide resolved
tests/test_buffered_mode.py Outdated Show resolved Hide resolved
tests/test_shell.py Show resolved Hide resolved
tests/test_shell.py Outdated Show resolved Hide resolved
tests/test_sync.py Outdated Show resolved Hide resolved
@csadorf
Copy link
Contributor

csadorf commented Jan 27, 2020

Great, this looks like it's almost done! There are a few minor things that should be fixed, but overall pretty good. One thing that I would like to see applied across all files is that the name pattern for BaseXTest is changed to TestXBase instead of TestBaseX.

Also, if you could make sure that the changes are meeting our formatting guidelines, which are listed in the contribution guidelines. You can use tools like flake8 and autopep8 to run an automatic check.

Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

You accidentally introduced a typo with this commit, otherwise good.

tests/test_project.py Outdated Show resolved Hide resolved
@csadorf
Copy link
Contributor

csadorf commented Jan 27, 2020

@vishav1771 Would you mind assigning yourself to the related issue: #212 ?

@vishav1771
Copy link
Contributor Author

@csadorf

@vishav1771 Would you mind assigning yourself to the related issue: #212 ?

Sorry for the inconvenience, but I am not able to assign myself this issue. I tried following the official guide, but still, no results. Can you please guide me!

@bdice
Copy link
Member

bdice commented Jan 27, 2020

@csadorf

@vishav1771 Would you mind assigning yourself to the related issue: #212 ?

Sorry for the inconvenience, but I am not able to assign myself this issue. I tried following the official guide, but still, no results. Can you please guide me!

@csadorf @vishav1771 Vishav does not have permissions to assign himself, and we cannot assign him unless he comments on the issue. Some repos have an “assigner bot” that allows users to claim issues. The bot watches for a comment like “assign me” or “take this issue” and it has write access to add them as an assignee since they have commented. More info: https://help.github.com/en/github/managing-your-work-on-github/assigning-issues-and-pull-requests-to-other-github-users

You can assign up to 10 people to each issue or pull request, including yourself, anyone who has commented on the issue or pull request, anyone with write permissions to the repository, and organization members with read permissions to the repository. For more information, see "Access permissions on GitHub."

tests/test_project.py Outdated Show resolved Hide resolved
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

Ok, great! Looks good! One last thing from my side: Can you update the instructions for test execution in the README?

Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@bdice bdice added this to the v1.4.0 milestone Jan 27, 2020
@vishav1771 vishav1771 requested review from bdice and removed request for vyasr January 29, 2020 14:06
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.

I am requesting some changes, and I will apply those changes directly so this PR can move forward (otherwise it will block progress on some other PRs that affect tests).

README.md Show resolved Hide resolved
changelog.txt Outdated
@@ -19,6 +19,7 @@ Changed
+++++++

- Workspace directory is created when ``Project`` is initialized (#267, #271).
- Changed testing framework from ``unittest`` to ``pytest`` (#212, #275)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Changed testing framework from ``unittest`` to ``pytest`` (#212, #275)
- Changed testing framework from ``unittest`` to ``pytest`` (#212, #275).

tests/test_buffered_mode.py Show resolved Hide resolved

def test_contains(self):
self.assertFalse('0' in self.c)
assert not ('0' in self.c)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert not ('0' in self.c)
assert '0' not in self.c

del self.c[_id]
self.assertFalse(_id in self.c)
assert not (_id in self.c)
Copy link
Member

Choose a reason for hiding this comment

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

You might do a search for assert not to make sure that this gets changed across the whole PR. In general x not in y is better than not (x in y).

Suggested change
assert not (_id in self.c)
assert _id not in self.c


def test_interface_deepcopy(self):
job = self.open_job(dict(a=0)).init()
copy.deepcopy(job.sp).a = 1
self.assertFalse(job in self.project)
assert not (job in self.project)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert not (job in self.project)
assert job not in self.project

@@ -2,7 +2,7 @@
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
import os
import unittest

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -1,14 +1,15 @@
# Copyright (c) 2017 The Regents of the University of Michigan
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
import unittest

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -516,10 +518,6 @@ def test_nested_types_dict_conversion(self):
sad.items()
assert type(sad['a']) is SAD
sad.values()
assert type(sad['a']) is SAD
assert type(sad['a']), SAD
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert type(sad['a']), SAD
assert type(sad['a']) is SAD


if __name__ == '__main__':
unittest.main()
assert type(sad['a']), SAD
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert type(sad['a']), SAD
assert type(sad['a']) is SAD

@bdice
Copy link
Member

bdice commented Jan 29, 2020

@vishav1771 I don't have permissions to push to your fork. Can you enable "Allow edits from maintainers" on this PR?
https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork

Copy link
Contributor

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

A couple of small changes, then this is good to go! Thanks for the huge effort on this PR.

sleep(1.0)
with open(job.doc._filename, 'wb') as file:
file.write(json.dumps({'a': not x}).encode())
self.assertIn(job.doc._filename, cm.exception.files)
print(cm.value)
print(job.doc._filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these prints.

collection.reset_mock()
for fn in ('a_0.txt', 'a_1.txt'):
os.remove(os.path.join(self._tmp_dir.name, fn))
N = len(index)
index = list(signac.index(root=self._tmp_dir.name, tags={'test1'}))
self.assertEqual(len(index), N - 1)
assert len(index) == N - 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert len(index) == N - 1
assert len(index) == (N - 1)

assert bool(jsd)
assert len(jsd) == 1
assert key in jsd
assert key in jsd
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete this line? This test is identical to the one above.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this is deliberately testing twice.

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to correct myself, doesn't look like this duplication here is crucial.

@vishav1771
Copy link
Contributor Author

@vishav1771 I don't have permissions to push to your fork. Can you enable "Allow edits from maintainers" on this PR?

Enabled :)

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.

Thanks again @vishav1771, I think this is complete.

@vyasr vyasr merged commit c9810b9 into glotzerlab:master Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Adopt the pytest library for testing
4 participants