-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Caching for fine-grained incremental mode #4483
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
Changes from 1 commit
22918dc
e5afefd
b1a5a25
e386820
39c2709
22dd19a
bbd49a2
376db14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
from mypy.test.testtypegen import ignore_node | ||
from mypy.types import TypeStrVisitor, Type | ||
from mypy.util import short_type | ||
import pytest # type: ignore # no pytest in typeshed | ||
|
||
|
||
class FineGrainedSuite(DataSuite): | ||
|
@@ -41,31 +42,40 @@ class FineGrainedSuite(DataSuite): | |
] | ||
base_path = test_temp_dir | ||
optional_out = True | ||
# Whether to use the fine-grained cache in the testing. This is overridden | ||
# by a trivial subclass to produce a suite that uses the cache. | ||
use_cache = False | ||
|
||
# Decide whether to skip the test. This could have been structured | ||
# as a filter() classmethod also, but we want the tests reported | ||
# as skipped, not just elided. | ||
def should_skip(self, testcase: DataDrivenTestCase) -> bool: | ||
if self.use_cache: | ||
if testcase.name.endswith("-skip-cache"): return True | ||
# TODO: In caching mode we currently don't well support | ||
# starting from cached states with errors in them. | ||
if testcase.output and testcase.output[0] != '==': return True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above. |
||
else: | ||
if testcase.name.endswith("-skip-nocache"): return True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above. |
||
|
||
def run_case(self, testcase: DataDrivenTestCase) -> None: | ||
self.run_case_inner(testcase, cache=False) | ||
|
||
# Reset the test case and run it again with caching on | ||
testcase.teardown() | ||
testcase.setup() | ||
self.run_case_inner(testcase, cache=True) | ||
return False | ||
|
||
def run_case_inner(self, testcase: DataDrivenTestCase, cache: bool) -> None: | ||
# TODO: In caching mode we currently don't well support | ||
# starting from cached states with errors in them. | ||
if cache and testcase.output and testcase.output[0] != '==': return | ||
def run_case(self, testcase: DataDrivenTestCase) -> None: | ||
if self.should_skip(testcase): | ||
pytest.skip() | ||
return | ||
|
||
main_src = '\n'.join(testcase.input) | ||
sources_override = self.parse_sources(main_src) | ||
print("Testing with cache: ", cache) | ||
messages, manager, graph = self.build(main_src, testcase, sources_override, | ||
build_cache=cache, enable_cache=cache) | ||
build_cache=self.use_cache, | ||
enable_cache=self.use_cache) | ||
a = [] | ||
if messages: | ||
a.extend(normalize_messages(messages)) | ||
|
||
fine_grained_manager = None | ||
if not cache: | ||
if not self.use_cache: | ||
fine_grained_manager = FineGrainedBuildManager(manager, graph) | ||
|
||
steps = testcase.find_steps() | ||
|
@@ -90,7 +100,7 @@ def run_case_inner(self, testcase: DataDrivenTestCase, cache: bool) -> None: | |
# cache, now we need to set it up | ||
if fine_grained_manager is None: | ||
messages, manager, graph = self.build(main_src, testcase, sources_override, | ||
build_cache=False, enable_cache=cache) | ||
build_cache=False, enable_cache=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the change to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. This path only executes when the cache is on. |
||
fine_grained_manager = FineGrainedBuildManager(manager, graph) | ||
|
||
new_messages = fine_grained_manager.update(modules) | ||
|
@@ -103,11 +113,10 @@ def run_case_inner(self, testcase: DataDrivenTestCase, cache: bool) -> None: | |
# Normalize paths in test output (for Windows). | ||
a = [line.replace('\\', '/') for line in a] | ||
|
||
modestr = "in cache mode " if cache else "" | ||
assert_string_arrays_equal( | ||
testcase.output, a, | ||
'Invalid output {}({}, line {})'.format( | ||
modestr, testcase.file, testcase.line)) | ||
'Invalid output ({}, line {})'.format( | ||
testcase.file, testcase.line)) | ||
|
||
if testcase.triggered: | ||
assert_string_arrays_equal( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Tests for fine-grained incremental checking using the cache. | ||
|
||
All of the real code for this lives in testfinegrained.py. | ||
""" | ||
|
||
# We can't "import FineGrainedSuite from ..." because that will cause pytest | ||
# to collect the non-caching tests when running this file. | ||
import mypy.test.testfinegrained | ||
|
||
|
||
class FineGrainedCacheSuite(mypy.test.testfinegrained.FineGrainedSuite): | ||
use_cache = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: move
return True
to a separate line.