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

Show how @parameterized could replace @data_provider #558

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lpetre
Copy link
Contributor

@lpetre lpetre commented Nov 19, 2021

Summary

@data_provider seems unnecessary to include in libcst. Why not use a pypi equivalent. Here is an example using parameterized

Let me know what you think and I'll convert the rest of the tests

Test Plan

(libcstvenv) lpetre@lpetre-mbp LibCST % python -m unittest libcst._nodes.tests.test_assert
..........
----------------------------------------------------------------------
Ran 10 tests in 0.080s

OK

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 19, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #558 (842aab3) into main (d0f8fa9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #558   +/-   ##
=======================================
  Coverage   94.77%   94.77%           
=======================================
  Files         235      235           
  Lines       23274    23274           
=======================================
  Hits        22058    22058           
  Misses       1216     1216           
Impacted Files Coverage Δ
libcst/_nodes/tests/test_assert.py 100.00% <100.00%> (ø)

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 d0f8fa9...842aab3. Read the comment docs.

@zsol
Copy link
Member

zsol commented Nov 19, 2021

Do failures look decent? I'm mainly looking for if a failure message includes the inputs or at least some label.
How does this play with pyre?

@lpetre
Copy link
Contributor Author

lpetre commented Nov 19, 2021

Do failures look decent? I'm mainly looking for if a failure message includes the inputs or at least some label.

Error w/ libcst.testing.utils.data_provider

(libcstvenv) lpetre@lpetre-mbp LibCST % python -m unittest libcst._nodes.tests.test_assign
........F................
======================================================================
FAIL: test_valid_6 (libcst._nodes.tests.test_assign.AnnAssignTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/testing/utils.py", line 87, in new_test
    return member(self, **data)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/test_assign.py", line 290, in test_valid
    self.validate_node(**kwargs)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/base.py", line 77, in validate_node
    self.__assert_codegen(node, code, expected_position)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/base.py", line 114, in __assert_codegen
    self.assertEqual(module.code_for_node(node), expected)
AssertionError: 'foo :  Optional[str]  =  5' != 'for :  Optional[str]  =  5'
- foo :  Optional[str]  =  5
?   ^
+ for :  Optional[str]  =  5
?   ^

Errors with equivalent parameterized.expand:

(libcstvenv) lpetre@lpetre-mbp LibCST % python -m unittest libcst._nodes.tests.test_assign
........F................
======================================================================
FAIL: test_valid_6_Whitespace_test (libcst._nodes.tests.test_assign.AnnAssignTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/lpetre/dev/src/github.com/lpetre/libcstvenv/lib/python3.7/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/test_assign.py", line 291, in test_valid
    self.validate_node(**kwargs)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/base.py", line 77, in validate_node
    self.__assert_codegen(node, code, expected_position)
  File "/Users/lpetre/dev/src/github.com/lpetre/LibCST/libcst/_nodes/tests/base.py", line 114, in __assert_codegen
    self.assertEqual(module.code_for_node(node), expected)
AssertionError: 'foo :  Optional[str]  =  5' != 'for :  Optional[str]  =  5'
- foo :  Optional[str]  =  5
?   ^
+ for :  Optional[str]  =  5
?   ^

@lpetre
Copy link
Contributor Author

lpetre commented Nov 19, 2021

How does this play with pyre?

It doesn't. The arguments to the decorator aren't typechecked against the arguments of the test method.

I would argue that migrating to parameterized is better than the broken attempt at typing in data_provider. It doesn't feel like a feature that will be supported any time soon by pyre or mypy.

Generally I question the value of implementing a parameterized testing in libcst (vs a standalone lib)

@zsol
Copy link
Member

zsol commented Nov 20, 2021

Generally I question the value of implementing a parameterized testing in libcst (vs a standalone lib)

Fully agree.

Alright, I'm on board :)

@zsol zsol marked this pull request as draft December 29, 2021 11:48
@facebook-github-bot
Copy link

Hi @lpetre!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants