Skip to content

Commit

Permalink
Script to regenerate test fixtures
Browse files Browse the repository at this point in the history
Upgrading Pyre requires updating test fixtures with any upstream changes
to Pyre's query results for the `simple_class.py` fixture.

This adds a new `scripts/` directory to the repo, with a script to
regenerate test fixtures. The script regenerates the cache data fixture,
and updates the `TypeInferenceProvider` tests to use `assertDictEqual`
and helpful error messages for better behavior in future mismatches.

This also includes a slight bump to Pyre 0.9.10 to fix install issues on
Apple Silicon M1 Macs, and regenerated fixtures using the script above.
  • Loading branch information
amyreese committed Feb 21, 2023
1 parent 8aebbb6 commit 8f9355e
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 244 deletions.
8 changes: 0 additions & 8 deletions libcst/matchers/_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ def _gather_constructed_visit_funcs(
_assert_not_concrete("visit", func)
for matcher in matchers:
casted_matcher = cast(BaseMatcherNode, matcher)
# pyre-fixme[6]: Expected
# `Sequence[typing.Callable[[cst._nodes.base.CSTNode], None]]` for 2nd
# param but got `Tuple[*Tuple[(CSTNode) -> None, ...], (CSTNode) ->
# None]`.
constructed_visitors[casted_matcher] = (
*constructed_visitors.get(casted_matcher, ()),
func,
Expand Down Expand Up @@ -362,10 +358,6 @@ def _gather_constructed_leave_funcs(
_assert_not_concrete("leave", func)
for matcher in matchers:
casted_matcher = cast(BaseMatcherNode, matcher)
# pyre-fixme[6]: Expected
# `Sequence[typing.Callable[[cst._nodes.base.CSTNode], None]]` for 2nd
# param but got `Tuple[*Tuple[(CSTNode) -> None, ...], (CSTNode) ->
# None]`.
constructed_visitors[casted_matcher] = (
*constructed_visitors.get(casted_matcher, ()),
func,
Expand Down
8 changes: 7 additions & 1 deletion libcst/metadata/tests/test_type_inference_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _test_simple_class_helper(test: UnitTest, wrapper: MetadataWrapper) -> None:
)
@skipIf(sys.platform == "win32", "TypeInferenceProvider doesn't support windows")
class TypeInferenceProviderTest(UnitTest):
maxDiff = None

@classmethod
def setUpClass(cls) -> None:
os.chdir(TEST_SUITE_PATH)
Expand All @@ -80,7 +82,11 @@ def test_gen_cache(self, source_path: Path, data_path: Path) -> None:
root_path=source_path.parent, paths=[source_path.name], timeout=None
)
data: PyreData = json.loads(data_path.read_text())
self.assertEqual(data, cache[source_path.name])
self.assertDictEqual(
data,
cache[source_path.name],
"Pyre query result mismatch, try running `scripts/regenerate-fixtures.py`?",
)

@data_provider(
((TEST_SUITE_PATH / "simple_class.py", TEST_SUITE_PATH / "simple_class.json"),)
Expand Down
Loading

0 comments on commit 8f9355e

Please sign in to comment.