Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: recipes/list_primes.py

Issue 1421843006: Add simple depends_on API. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 from recipe_engine.recipe_api import Property
2 from recipe_engine import config
3 import math
4
5 # This recipe computes all the primes up to the value up_to.
6
7 DEPS = [
8 'recipe_engine/properties',
9 ]
10
11 PROPERTIES = {
12 'up_to': Property(kind=int, default=50),
13 }
14
15 RETURN_SCHEMA = config.ReturnSchema(
16 result=config.List(int)
17 )
18
19 def is_prime(val):
20 if val % 2 == 0:
21 return False
22 for div in range(3, math.ceil(math.sqrt(val))):
23 if val % div == 0:
24 return False
25 return True
26
27 def RunSteps(api, up_to):
28 all_primes = []
29 prime = 2
30 while prime < up_to:
31 all_primes.append(prime)
32 res = api.depend_on('next_prime', {'curr_prime': prime})
33 prime = res.result
34 if not is_prime(prime):
35 raise api.StepFailure("OH NOES")
36
37 return RETURN_SCHEMA(result=all_primes)
38
39 def GenTests(api):
40 yield (
41 api.test('basic') +
42 api.properties(up_to=3) +
43 api.depend_on('next_prime', {'result': 3})
44 )
45
46 yield (
47 api.test('failure') +
48 api.properties(up_to=10) +
49 api.depend_on('next_prime', {'result': 4})
50 )
OLDNEW
« no previous file with comments | « recipes/dm.py ('k') | recipes/next_prime.py » ('j') | recipes/top.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698