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 22, 2023
1 parent 944ff15 commit 5e7efdd
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: pip install -e .
- run: pyre --version
- run: pyre -n check
- run: python libcst/tests/test_pyre_integration.py
- run: python scripts/regenerate-fixtures.py
- run: git diff --exit-code

# Upload test coverage
Expand Down
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
10 changes: 9 additions & 1 deletion libcst/metadata/tests/test_type_inference_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import sys
from pathlib import Path
from typing import cast, Mapping, Optional
from unittest import skipIf

import libcst as cst
Expand Down Expand Up @@ -57,6 +58,8 @@ def _test_simple_class_helper(test: UnitTest, wrapper: MetadataWrapper) -> None:
)
@skipIf(sys.platform == "win32", "TypeInferenceProvider doesn't support windows")
class TypeInferenceProviderTest(UnitTest):
maxDiff: Optional[int] = None

@classmethod
def setUpClass(cls) -> None:
os.chdir(TEST_SUITE_PATH)
Expand All @@ -79,8 +82,13 @@ def test_gen_cache(self, source_path: Path, data_path: Path) -> None:
cache = TypeInferenceProvider.gen_cache(
root_path=source_path.parent, paths=[source_path.name], timeout=None
)
result = cast(Mapping[str, object], cache[source_path.name])
data: PyreData = json.loads(data_path.read_text())
self.assertEqual(data, cache[source_path.name])
self.assertDictEqual(
data,
result,
"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 5e7efdd

Please sign in to comment.