red-balloon-89377
10/24/2018, 4:40 PMscheduler.product_request(Snapshot, [UrlToFetch])
, so long as there is an @rule
of the form @rule(Snapshot, [Select(UrlToFetch)])
. I have an intrinsic rule, introduced in https://github.com/pantsbuild/pants/pull/6660. But when I try to do this in tests it doesn’t recognize the rule:
def test_download(self):
scheduler = self.scheduler(rules, include_trace_on_error=True)
url = UrlToFetch("<http://google.com>")
snapshot, = scheduler.product_request(Snapshot, subjects=[url])
self.assert_equal_with_printing('a', str(snapshot))
This is inside tests/python/pants_test/engine/test_engine.py
witty-crayon-22786
10/24/2018, 4:52 PMwitty-crayon-22786
10/24/2018, 4:52 PMwitty-crayon-22786
10/24/2018, 4:53 PMwitty-crayon-22786
10/24/2018, 4:54 PMred-balloon-89377
10/24/2018, 4:54 PMwitty-crayon-22786
10/24/2018, 5:01 PM@rule
to act as indirection therewitty-crayon-22786
10/24/2018, 5:03 PMTestBase
can add additional rules, so if in a test you add an @rule
like class WorkaroundSnapshot(datatype([('snapshot', Snapshot)])): pass
@rule(WorkaroundSnapshot, [Select(UrlToFetch)])
def workaround(url_to_fetch):
x = yield Get(Snapshot, UrlToFetch, url_to_fetch)
yield x
witty-crayon-22786
10/24/2018, 5:03 PMwitty-crayon-22786
10/24/2018, 5:03 PMred-balloon-89377
10/24/2018, 5:04 PM@rule(Snapshot, [Select(UrlToFetch)])
? if the intrinsic rule is not recognized, this should work right?red-balloon-89377
10/24/2018, 5:05 PMwitty-crayon-22786
10/24/2018, 5:07 PMwitty-crayon-22786
10/24/2018, 5:08 PMX
for Y
, and that's the smallest example of thatred-balloon-89377
10/24/2018, 5:08 PMwitty-crayon-22786
10/24/2018, 5:09 PMwitty-crayon-22786
10/24/2018, 5:09 PMRoot
... the rule graph differentiates between roots and inner nodes ... in odd ways that i only somewhat understand and have been trying to improvered-balloon-89377
10/24/2018, 5:10 PMred-balloon-89377
10/24/2018, 5:14 PMno rule was available to compute UrlToFetch with parameter type ()
. From the error it looks like it’s trying to build an UrlToFetch, which is weird because I give it one (this is with the tiny rule you gave me).witty-crayon-22786
10/24/2018, 5:19 PM()
?witty-crayon-22786
10/24/2018, 5:20 PMred-balloon-89377
10/24/2018, 5:20 PMdef test_download(self):
rules = [download]
# rules = []
scheduler = self.scheduler(rules, include_trace_on_error=True)
# print("BL: scheduler.".format(scheduler._scheduler._))
url = UrlToFetch("<http://google.com>")
snapshot, = scheduler.product_request(WorkaroundSnapshot, subjects=[url])
self.assert_equal_with_printing('a', str(snapshot))
witty-crayon-22786
10/24/2018, 5:20 PMscheduler.product_request(Snapshot, subjects=[UrlToFetch("<http://google.com>")])
should definitely identify that as a UrlToFetch
witty-crayon-22786
10/24/2018, 5:20 PMwitty-crayon-22786
10/24/2018, 5:21 PMwitty-crayon-22786
10/24/2018, 5:21 PMwitty-crayon-22786
10/24/2018, 5:24 PMdownload
?witty-crayon-22786
10/24/2018, 5:24 PMwitty-crayon-22786
10/24/2018, 5:24 PMred-balloon-89377
10/24/2018, 5:24 PM@rule(WorkaroundSnapshot, [Select(UrlToFetch)])
def download(url):
s = yield Get(Snapshot, UrlToFetch, url)
yield
witty-crayon-22786
10/24/2018, 5:27 PMTestBase
. confirmingred-balloon-89377
10/24/2018, 5:40 PMpants_test/engine/test_fs.py
we do create new schedulers, but we manually register all the fs rules as rootsred-balloon-89377
10/24/2018, 5:51 PMwitty-crayon-22786
10/24/2018, 5:51 PMwitty-crayon-22786
10/24/2018, 5:52 PMwitty-crayon-22786
10/24/2018, 5:52 PMred-balloon-89377
10/24/2018, 5:52 PMdef test_download(self):
scheduler = self.mk_scheduler(rules=create_fs_rules())
snapshot = scheduler.product_request(Snapshot, subjects=[UrlToFetch("<http://science-binaries.local.twitter.com/home/third_party/source/python/wheels/Babel-2.5.3-py2.py3-none-any.whl>")])
assert(snapshot)
workswitty-crayon-22786
10/24/2018, 5:52 PMred-balloon-89377
10/24/2018, 5:52 PMtest_fs.py
)witty-crayon-22786
10/24/2018, 5:53 PMwitty-crayon-22786
10/24/2018, 5:53 PMTestBase
scheduler is completely bare... with only the intrinsicswitty-crayon-22786
10/24/2018, 5:54 PMred-balloon-89377
10/24/2018, 5:56 PMtest_engine.py
, the class EngineTest
does not inherit from TestBase
red-balloon-89377
10/24/2018, 5:56 PMwitty-crayon-22786
10/24/2018, 5:57 PMwitty-crayon-22786
10/24/2018, 5:57 PMred-balloon-89377
10/24/2018, 5:59 PMred-balloon-89377
10/24/2018, 5:59 PMtest_fs.py
from the beginning this should not have been a problemred-balloon-89377
10/24/2018, 5:59 PMRootRule(UrlToFetch)
witty-crayon-22786
10/24/2018, 5:59 PMred-balloon-89377
10/24/2018, 6:00 PMwitty-crayon-22786
10/24/2018, 6:01 PMwitty-crayon-22786
10/24/2018, 6:01 PMred-balloon-89377
10/24/2018, 6:01 PM