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

Caching tests are parsed through the engine #5985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions tests/python/pants_test/cache/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import os

from pants.base.payload import Payload
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.cache.cache_setup import CacheFactory, CacheSetup
from pants.task.task import Task
from pants_test.task_test_base import TaskTestBase


class DummyLibrary(Target):
def __init__(self, address, source, *args, **kwargs):
def __init__(self, address, sources, *args, **kwargs):
payload = Payload()
payload.add_fields({'sources': self.create_sources_field(sources=[source],
payload.add_fields({'sources': self.create_sources_field(sources=sources,
sources_rel_path=address.spec_path)})
self.source = source
super(DummyLibrary, self).__init__(address=address, payload=payload, *args, **kwargs)


Expand All @@ -40,6 +40,10 @@ class LocalCachingTest(TaskTestBase):

_filename = 'f'

@classmethod
def alias_groups(cls):
return BuildFileAliases(targets={'dummy_library': DummyLibrary})

@classmethod
def task_type(cls):
return DummyTask
Expand All @@ -54,8 +58,9 @@ def setUp(self):
read_from=[self.artifact_cache],
write=True,
)
self.target = self.make_target(':t', target_type=DummyLibrary, source=self._filename)
context = self.context(for_task_types=[DummyTask], target_roots=[self.target])
self.add_to_build_file('', 'dummy_library(name = "t", source = "{}")'.format(self._filename))
self._target = self.target(':t')
context = self.context(for_task_types=[DummyTask], target_roots=[self._target])
self.task = self.create_task(context)

def test_cache_written_to(self):
Expand All @@ -65,7 +70,7 @@ def test_cache_written_to(self):
artifact_address = os.path.join(
self.artifact_cache,
CacheFactory.make_task_cache_dirname(self.task),
self.target.id,
self._target.id,
'{}.tgz'.format(vt.cache_key.hash),
)
self.assertTrue(os.path.isfile(artifact_address))
Expand All @@ -76,7 +81,7 @@ def test_cache_read_from(self):
self.assertGreater(len(invalid_vts), 0)
first_vt = invalid_vts[0]
# Mark the target invalid.
self.target.mark_invalidation_hash_dirty()
self._target.mark_invalidation_hash_dirty()
all_vts2, invalid_vts2 = self.task.execute()
# Check that running the task a second time results in a valid vt,
# implying the artifact cache was hit.
Expand Down
17 changes: 11 additions & 6 deletions tests/python/pants_test/cache/test_caching_tarball_deference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os

from pants.base.payload import Payload
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.cache.cache_setup import CacheFactory, CacheSetup
from pants.task.task import Task
Expand All @@ -22,11 +23,10 @@


class DummyCacheLibrary(Target):
def __init__(self, address, source, *args, **kwargs):
def __init__(self, address, sources, *args, **kwargs):
payload = Payload()
payload.add_fields({'sources': self.create_sources_field(sources=[source],
payload.add_fields({'sources': self.create_sources_field(sources=sources,
sources_rel_path=address.spec_path)})
self.source = source
super(DummyCacheLibrary, self).__init__(address=address, payload=payload, *args, **kwargs)


Expand Down Expand Up @@ -66,6 +66,10 @@ def execute(self):
class LocalCachingTarballDereferenceTest(TaskTestBase):
_filename = 'f'

@classmethod
def alias_groups(cls):
return BuildFileAliases(targets={'dummy_cache_library': DummyCacheLibrary})

@classmethod
def task_type(cls):
return DummyCacheTask
Expand All @@ -83,7 +87,7 @@ def _get_artifact_path(self, vt):
return os.path.join(
self.artifact_cache,
CacheFactory.make_task_cache_dirname(self.task),
self.target.id,
self._target.id,
'{}.tgz'.format(vt.cache_key.hash),
)

Expand Down Expand Up @@ -113,8 +117,9 @@ def _prepare_task(self, deference, regular_file, regular_file_in_results_dir):
regular_file=regular_file,
regular_file_in_results_dir=regular_file_in_results_dir
)
self.target = self.make_target(':t', target_type=DummyCacheLibrary, source=self._filename)
context = self.context(for_task_types=[DummyCacheTask], target_roots=[self.target])
self.add_to_build_file('', 'dummy_cache_library(name = "t", source = "{}")'.format(self._filename))
self._target = self.target(':t')
context = self.context(for_task_types=[DummyCacheTask], target_roots=[self._target])
self.task = self.create_task(context)

def _assert_dereferenced_symlink_in_cache(self, all_vts):
Expand Down