def benchmarks(size): pys_list = make_list(*range(size)) pyr_list = v(*range(size)) mut_list = list(range(size)) pys_vector_append = partial(pys_list.concat, make_list(1)) pyr_vector_append = partial(pyr_list.append, 1) mut_vector_append = partial(mut_list.append, 1) mut_list = list(range(size)) pys_vector_push = partial(pys_list.cons, 1) pyr_vector_push = partial(v(1).extend, pyr_list) mut_vector_push = partial(mut_list.insert, 0, 1) mut_list = list(range(size)) pys_vector_mutate_beginning = partial(_pys_set, 0, 'new-value', pys_list) pyr_vector_mutate_beginning = partial(pyr_list.assoc, 0, 'new-value') mut_vector_mutate_beginning = partial(mut_list.__setitem__, 0, 'new-value') mut_list = list(range(size)) middle_index = size // 2 pys_vector_mutate_middle = partial(_pys_set, middle_index, 'new-value', pys_list) pyr_vector_mutate_middle = partial(pyr_list.assoc, middle_index, 'new-value') mut_vector_mutate_middle = partial(mut_list.__setitem__, middle_index, 'new-value') mut_list = list(range(size)) pys_vector_mutate_end = partial(_pys_set, size-1, 'new-value', pys_list) pyr_vector_mutate_end = partial(pyr_list.assoc, size-1, 'new-value') mut_vector_mutate_end = partial(mut_list.__setitem__, size-1, 'new-value') benchmarks = [ (MUTABLE, VECTOR_APPEND, mut_vector_append), (PYRSISTENT, VECTOR_APPEND, pyr_vector_append), (PYSISTENCE, VECTOR_APPEND, pys_vector_append), (MUTABLE, VECTOR_PUSH, mut_vector_push), (PYRSISTENT, VECTOR_PUSH, pyr_vector_push), (PYSISTENCE, VECTOR_PUSH, pys_vector_push), (MUTABLE, VECTOR_MUTATE_BEG, mut_vector_mutate_beginning), (PYRSISTENT, VECTOR_MUTATE_BEG, pyr_vector_mutate_beginning), (PYSISTENCE, VECTOR_MUTATE_BEG, pys_vector_mutate_beginning), (MUTABLE, VECTOR_MUTATE_MID, mut_vector_mutate_middle), (PYRSISTENT, VECTOR_MUTATE_MID, pyr_vector_mutate_middle), (PYSISTENCE, VECTOR_MUTATE_MID, pys_vector_mutate_middle), (MUTABLE, VECTOR_MUTATE_END, mut_vector_mutate_end), (PYRSISTENT, VECTOR_MUTATE_END, pyr_vector_mutate_end), (PYSISTENCE, VECTOR_MUTATE_END, pys_vector_mutate_end), ] return benchmarks
def compiled_mcmc_sweep(model, methods, n_cycles): """ A declarative MCMC algorithm, running for a set number of cycles. Only the terminal value is returned to Python. """ variables_to_update = methods.keys() state = ps.make_list(*stochastics(model)) orig_state = list(state) state_index = [orig_state.index(v) for v in variables_to_update] for i in xrange(n_cycles): for v, index in zip(variables_to_update, state_index): state = methods[v].step(model, state, index_plist(state, index), v) f = th.function(orig_state, list(state), no_default_updates=True, mode='FAST_RUN') # th.printing.pydotprint(f,'f.pdf') def sweep(state_value_dict, orig_state=orig_state, f=f): "Takes a state, represented as a dict, applies n_cycles MCMC steps to it, and returns a new state represented as a dict." new_state_value_list = f(**state_value_dict) return to_namedict(orig_state, new_state_value_list) return sweep
def mcmc(model, observations, n_sweeps, n_cycles_per_sweep, methods=empty_dict, seed=None): "The full MCMC algorithm, which returns a trace." if seed: seed_model(model, seed) s = stochastics(model) # Make an initial state vector, in order. observation_value_dict = dict([(ov.name, observations[ov]) for ov in observations.keys()]) state_value = simulate_prior(model, outputs=s, arguments=observations.keys())(observation_value_dict) variables_to_update = [] for v in s: if not observations.has_key(v): variables_to_update.append(v) methods = zipmap(variables_to_update, lambda v: methods.get(v, metropolis(model, v))) sweep_fn = compiled_mcmc_sweep(model, methods, n_cycles_per_sweep) trace = ps.make_list(state_value) t = time.time() for i in xrange(n_sweeps): state_value = sweep_fn(state_value) trace = trace.cons(state_value) t = time.time()-t return trace, t
def add_stochastic(model, name, new_variable, new_factors): "Returns a stochastic variable, and a version of model that incorporates that variable." new_variable.name = name check_namedup(model, name) return new_variable, model.using( variables=model['variables'].cons(new_variable), factors=model['factors'].concat(ps.make_list(*new_factors)))
def _pys_insert(i, newv, l): if i == 0: return l.cons(newv) after = _pys_drop(i, l) if after is None: after = make_list() return _pys_take(i, l).concat(after.cons(newv))
def test_contains(): ls = make_list(1,2,3) def check_number(num): assert num in ls for number in ls: yield check_number, number
class Morning(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1') data_sources = immutable.make_dict({ 'v1': { 'top_stories': ds.TopStoriesDataSource(clientAUS), 'world_news': dss.news.WorldNews(clientAUS), 'australian_news': dss.au.News(clientAUS), } }) priority_list = immutable.make_dict({ 'v1': [ ('top_stories', 5), ('australian_news', 7), ('world_news', 5), ], }) template_names = immutable.make_dict(v1='au/morning/v1') def additional_template_data(self): sydney_tz = pytz.timezone('Australia/Sydney') date_format = "%A %d %B %Y" return immutable.make_dict( sydney_date=datetime.datetime.now(sydney_tz).strftime(date_format))
class Bookmarks(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1', 'v2') ad_tag = 'email-bookmarks' ad_config = immutable.make_dict({ 'leaderboard': 'Top', 'leaderboard2': 'Bottom' }) base_data_sources = immutable.make_dict({ 'books_picks': dss.culture.BooksEditorsPicks(client), 'book_reviews': dss.culture.BookReviews(client), 'books_blog': dss.culture.BooksBlog(client), 'book_podcasts': dss.culture.BookPodcasts(client), 'books_most_viewed': dss.culture.BooksMostViewed(client), 'how_to_draw': dss.culture.HowToDraw(client), }) data_sources = immutable.make_dict({ 'v1': base_data_sources, 'v2': base_data_sources.using(talking_points=container.for_id( 'c04946d0-6483-4b29-ad3c-37bd2e2058c8')), }) priority_list = immutable.make_dict({ 'v1': immutable.make_list(('books_picks', 5), ('books_most_viewed', 3), ('book_reviews', 3), ('books_blog', 3), ('book_podcasts', 1), ('how_to_draw', 1)), 'v2': immutable.make_list(('books_picks', 5), ('books_most_viewed', 3), ('book_reviews', 3), ('talking_points', 6), ('book_podcasts', 1), ('how_to_draw', 1)), }) template_names = immutable.make_dict({ 'v1': 'culture/bookmarks/v1', 'v2': 'culture/bookmarks/v2', })
def _pys_set(i, newv, l): after = _pys_drop(i + 1, l) if after is not None: new_and_after = after.cons(newv) else: new_and_after = make_list(newv) if i == 0: return new_and_after return _pys_take(i, l).concat(new_and_after)
class CommentIsFree(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1', 'v2', 'v3') ad_tag = 'email-speakers-corner' ad_config = {'leaderboard': 'Top'} ophan_client = OphanClient(mr.ophan_base_url, mr.ophan_key) most_shared_data_source = ds.MostSharedDataSource( most_shared_fetcher=MostSharedFetcher(ophan_client, section='commentisfree'), multi_content_data_source=ds.MultiContentDataSource( client=client, name='most_shared'), shared_count_interpolator=ds.MostSharedCountInterpolator()) discussion_client = DiscussionClient(mr.discussion_base_url) most_commented_data_source = ds.MostCommentedDataSource( discussion_fetcher=DiscussionFetcher(discussion_client, 'commentisfree'), multi_content_data_source=ds.MultiContentDataSource( client=client, name='most_commented'), comment_count_interpolator=ds.CommentCountInterpolator()) data_sources = immutable.make_dict({ 'v1': { 'uk_opinion_front': container.for_id('uk/commentisfree/regular-stories'), 'cif_cartoon': ds.CommentIsFreeCartoonDataSource(client), }, 'v3': { 'cif_most_shared': most_shared_data_source, 'cif_cartoon': ds.CommentIsFreeCartoonDataSource(client), }, 'v2': { 'cif_most_commented': most_commented_data_source, 'cif_cartoon': ds.CommentIsFreeCartoonDataSource(client), } }) priority_list = { 'v3': [('cif_cartoon', 1), ('cif_most_shared', 5)], 'v2': [('cif_cartoon', 1), ('cif_most_commented', 5)], 'v1': [ ('uk_opinion_front', 10), ('cif_cartoon', 1), ], } template_names = immutable.make_dict({ 'v3': 'comment-is-free/v3', 'v2': 'comment-is-free/v2', 'v1': 'comment-is-free/v1', })
class MediaBriefing(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1') ad_tag = 'email-media-briefing' ad_config = immutable.make_dict({ 'leaderboard_v1': 'Top', 'leaderboard_v2': 'Bottom' }) data_sources = immutable.make_dict({ 'v1': { 'media_stories': ds.MediaDataSource(mr.client), 'media_monkey': ds.MediaMonkeyDataSource(mr.client), 'media_briefing': ds.MediaBriefingDataSource(mr.client) } }) priority_list = immutable.make_dict({ 'v1': immutable.make_list(('media_stories', 10), ('media_monkey', 1), ('media_briefing', 1)), }) template_names = immutable.make_dict({'v1': 'media/media-briefing'})
class SleeveNotes(handlers.EmailTemplate): recognized_versions = ['v1', 'v2', 'v3'] ad_tag = 'email-sleeve-notes' ad_config = { 'leaderboard': 'Top', 'leaderboard2': 'Bottom', } music_editors_picks = dss.general.ItemDataSource(content_id='music', show_editors_picks=True, tags=['-tone/news']) base_data_sources = immutable.make_dict({ 'music_most_viewed': dss.general.ItemDataSource(content_id='music', show_most_viewed=True), 'music_picks': music_editors_picks, 'music_blog': dss.general.ItemDataSource(content_id='music/musicblog'), 'music_watch_listen': dss.general.ItemDataSource(content_id='music', tags=['(type/video|type/audio)']), 'music_further': music_editors_picks, }) data_sources = immutable.make_dict({ 'v1': base_data_sources, 'v2': base_data_sources, 'v3': base_data_sources, }) priorities = immutable.make_list( ('music_most_viewed', 3), ('music_picks', 5), ('music_blog', 5), ('music_watch_listen', 5), ('music_further', 3)) priority_list = immutable.make_dict({ 'v1': priorities, 'v2': priorities, 'v3': priorities }) template_names = immutable.make_dict({ 'v1': 'culture/sleeve-notes/v1', 'v2': 'culture/sleeve-notes/v2', 'v3': 'culture/sleeve-notes/v3', })
def mcmc(model, observations, n_sweeps, n_cycles_per_sweep, methods=empty_dict, seed=None): "The full MCMC algorithm, which returns a trace." if seed: seed_model(model, seed) s = stochastics(model) # Make an initial state vector, in order. observation_value_dict = dict([(ov.name, observations[ov]) for ov in observations.keys()]) state_value = simulate_prior( model, outputs=s, arguments=observations.keys())(observation_value_dict) variables_to_update = [] for v in s: if not observations.has_key(v): variables_to_update.append(v) methods = zipmap(variables_to_update, lambda v: methods.get(v, metropolis(model, v))) sweep_fn = compiled_mcmc_sweep(model, methods, n_cycles_per_sweep) trace = ps.make_list(state_value) t = time.time() for i in xrange(n_sweeps): state_value = sweep_fn(state_value) trace = trace.cons(state_value) t = time.time() - t return trace, t
class TheFlyer(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1') ad_tag = 'email-the-flyer' ad_config = {'leaderboard': 'Top'} data_sources = immutable.make_dict({ 'v1': { 'travel_picks': ds.TravelDataSource(client), 'travel_most_viewed': ds.TravelMostViewedDataSource(client), 'travel_top_ten': ds.TravelTopTenDataSource(client), 'travel_video': ds.TravelVideoDataSource(client), 'travel_tips': ds.TravelTipsDataSource(client), } }) priority_list = immutable.make_dict({ 'v1': [('travel_video', 1), ('travel_picks', 5), ('travel_most_viewed', 3), ('travel_top_ten', 5), ('travel_tips', 1)] }) template_names = immutable.make_dict({'v1': 'travel/the-flyer'})
def test_rest(): ls = make_list(1, 2) assert 2 == ls.rest.first
class Politics(handlers.EmailTemplate): recognized_versions = immutable.make_list('v1', 'v2', 'v3', 'v4') cache_bust = False ad_tag = 'email-australian-politics' ad_config = {} data_sources = immutable.make_dict({ 'v1': { 'politics_latest': au.AustralianPoliticsDataSource(client), 'politics_comment': au.AusCommentIsFreeDataSource(clientAUS), 'politics_video': au.AustralianPoliticsVideoDataSource(client) }, 'v2': { 'headlines': container.for_id('au-alpha/news/regular-stories', sort_function=sorts.au.politics_first, additional_capi_params=immutable.make_dict( {"show-tags": "keyword"})), 'politics_comment': au.AusCommentIsFreeDataSource(clientAUS), 'politics_video': au.AustralianPoliticsVideoDataSource(client), }, 'v3': { 'politics_latest': au.AustralianPoliticsDataSource(client), 'politics_most_popular': dss.mostPopular.mostPopularByTag( client, ophan_client, 'australia-news/australian-politics'), 'politics_comment': au.AusCommentIsFreeDataSource(clientAUS), 'politics_video': au.AustralianPoliticsVideoDataSource(client) }, 'v4': { 'politics_latest': au.AustralianPoliticsDataSource(client), 'politics_most_popular': dss.mostPopular.mostPopularByTag( client, ophan_client, 'australia-news/australian-politics'), 'politics_comment': au.AusCommentIsFreeDataSourceLatest(clientAUS), 'politics_video': au.AustralianPoliticsVideoDataSource(client) } }) priority_list = { 'v1': [('politics_comment', 1), ('politics_video', 1), ('politics_latest', 4)], 'v2': [ ('headlines', 4), ('politics_comment', 1), ('politics_video', 1), ], 'v3': [ ('politics_latest', 4), ('politics_most_popular', 4), ('politics_comment', 1), ('politics_video', 1), ], 'v4': [ ('politics_latest', 4), ('politics_most_popular', 4), ('politics_comment', 1), ('politics_video', 1), ] } template_names = immutable.make_dict({ 'v1': 'au/politics/v1', 'v2': 'au/politics/v2', 'v3': 'au/politics/v3', 'v4': 'au/politics/v3' })
def test_contains_negative(): ls = make_list(1, 2, 3) assert 5 not in ls
import pysistence as immutable default_list = immutable.make_list( 'http://gu-front-checker.appspot.com/', 'http://www.bbc.co.uk/news/', "http://www.thetimes.co.uk/", "http://www.telegraph.co.uk", "http://www.ft.com", "http://m.sky.com/skynews/news", "http://www.dailymail.co.uk/", "http://m.independent.co.uk", "http://www.mirror.co.uk", "http://www.aljazeera.com/", "http://www.cnn.com/", ) paul_owen = immutable.make_list( 'http://www.theguardian.com/au', 'http://www.theguardian.com/us', 'http://www.buzzfeed.com/', 'https://news.vice.com/', 'http://www.nytimes.com/', ) paul_owen_us = immutable.make_list( 'http://www.theguardian.com/uk', 'http://www.theguardian.com/us', 'http://www.theguardian.com/au', 'http://www.theguardian.com/international', 'http://www.nytimes.com', 'http://www.washingtonpost.com', 'http://www.bbc.com/news/', 'http://www.latimes.com/', 'http://www.buzzfeed.com/', 'http://news.vice.com/', 'http://www.nydailynews.com/',
def lpd(self, state, x_p): return self.lpd_(state.concat(ps.make_list(x_p)))
import pysistence as immutable default_list = immutable.make_list( 'http://gu-front-checker.appspot.com/', 'http://www.bbc.co.uk/news/', "http://www.thetimes.co.uk/", "http://www.telegraph.co.uk", "http://www.ft.com", "http://m.sky.com/skynews/news", "http://www.dailymail.co.uk/", "http://m.independent.co.uk", "http://www.mirror.co.uk", "http://www.aljazeera.com/", "http://www.cnn.com/", ) paul_owen = immutable.make_list( 'http://www.theguardian.com/au', 'http://www.theguardian.com/us', 'http://www.buzzfeed.com/', 'https://news.vice.com/', 'http://www.nytimes.com/', ) paul_owen_us = immutable.make_list( 'http://www.theguardian.com/uk', 'http://www.theguardian.com/us', 'http://www.theguardian.com/au', 'http://www.theguardian.com/international', 'http://www.nytimes.com', 'http://www.washingtonpost.com',
class DailyEmail(handlers.EmailTemplate): recognized_versions = ['v1', 'v1-register', 'india', 'v2015', 'nhs', 'categories'] ad_tag = 'email-guardian-today' ad_config = { 'leaderboard_v1': 'Top', 'leaderboard_v2': 'Bottom' } cache_bust=False base_data_sources = immutable.make_dict({ 'business': ds.BusinessDataSource(client), 'technology': tech_data.TechnologyDataSource(client), 'travel': ds.TravelDataSource(client), 'lifeandstyle': ds.LifeAndStyleDataSource(client), 'sport': ds.SportDataSource(client), 'comment': ds.CommentIsFreeDataSource(client), 'culture': ds.CultureDataSource(client), 'top_stories': ds.TopStoriesDataSource(client), 'eye_witness': ds.EyeWitnessDataSource(client), 'most_viewed': ds.MostViewedDataSource(client), }) data_sources = immutable.make_dict({ 'v1': base_data_sources, 'v1-register': base_data_sources, 'india': base_data_sources.using( india_recent = ds.IndiaDataSource(client), ), 'v2015': base_data_sources, 'nhs': base_data_sources.using( nhs_special = container.for_id('346f91dc-60a5-41f1-a78e-513f6f379cec'), top_stories = container.for_id('uk-alpha/news/regular-stories') ), 'categories': base_data_sources.using( breaking = container.for_front('uk', 'breaking'), canonical = container.for_front('uk', 'canonical'), special = container.for_front('uk', 'special'), ), }) base_priorities = immutable.make_list(('top_stories', 6), ('most_viewed', 6), ('sport', 3), ('comment', 3), ('culture', 3), ('business', 2), ('technology', 2), ('travel', 2), ('lifeandstyle', 2), ('eye_witness', 1)) priority_list = immutable.make_dict({ 'v1': base_priorities, 'v1-register': base_priorities, 'india': [('top_stories', 6), ('india_recent', 5), ('most_viewed', 6), ('sport', 3), ('comment', 3), ('culture', 3), ('business', 2), ('technology', 2), ('travel', 2), ('lifeandstyle', 2), ('eye_witness', 1)], 'v2015': base_priorities, 'nhs': base_priorities.cons(('nhs_special', 2)), 'categories': immutable.make_list( ('breaking', 5), ('canonical', 6), ('special', 1), ).concat(base_priorities.without(('top_stories', 6))), }) template_names = immutable.make_dict({ 'v1': 'uk/daily/v1', 'v1-register': 'uk/daily/v1-register', 'india': 'uk/daily/india', 'v2015': 'uk/daily/v2015', 'nhs': 'uk/daily/nhs', 'categories': 'uk/daily/categories', }) def exclude_from_deduplication(self): return immutable.make_list('eye_witness')
def full_trace(model, trace): r = remember(model) return ps.make_list(*[r(state) for state in trace])
def test_replace(): test_list = make_list(1,2,3,4) actual_list = test_list.replace(old=1, new=0) expected_list = make_list(0,2,3,4) assert actual_list == expected_list
def test_equals_uneven(): assert not make_list(1, 2, 3) == make_list(1, 2)
class DailyEmailAUS(handlers.EmailTemplate): recognized_versions = ['v1', 'v2', 'v3', 'v2015', 'v4'] cache_bust = False ad_tag = 'email-guardian-today-aus' ad_config = {'leaderboard_v1': 'Top', 'leaderboard_v2': 'Bottom'} cultureDataSource = ds.ItemPlusBlogDataSource( ds.CultureDataSource(clientAUS), au.AusCultureBlogDataSource(clientAUS)) base_data_sources = immutable.make_dict({ 'top_stories_code': ds.TopStoriesDataSource(clientAUS), 'top_stories': ds.TopStoriesDataSource(clientAUS), 'most_viewed': ds.MostViewedDataSource(clientAUS), 'aus_sport': au.SportDataSource(client), 'culture': cultureDataSource, 'comment': au.AusCommentIsFreeDataSource(clientAUS), 'lifeandstyle': ds.LifeAndStyleDataSource(clientAUS), 'technology': tech_data.TechnologyDataSource(clientAUS), 'environment': au.Environment(clientAUS), 'science': ds.ScienceDataSource(clientAUS), 'video': au.AusVideoDataSource(clientAUS), }) data_sources = { 'v1': base_data_sources, 'v2': base_data_sources.using( eye_witness=ds.EyeWitnessDataSource(clientAUS)), 'v3': base_data_sources.using(eye_witness=ds.EyeWitnessDataSource(clientAUS), most_shared=dss.social.most_shared( clientAUS, ophan_client, 'au')), 'v2015': base_data_sources, 'v4': base_data_sources.using( breaking=container.for_front('au', 'breaking'), canonical=container.for_front('au', 'canonical'), special=container.for_front('au', 'special'), ), } base_priorities = immutable.make_list( ('top_stories', 6), ('most_viewed', 6), ('aus_sport', 5), ('culture', 3), ('comment', 3), ('lifeandstyle', 3), ('technology', 2), ('environment', 2), ('science', 2), ('video', 3)) priority_list = immutable.make_dict({ 'v1': base_priorities, 'v2': base_priorities.concat(immutable.make_list(('eye_witness', 1))), 'v3': base_priorities.concat(immutable.make_list(('most_shared', 6))), 'v2015': base_priorities, 'v4': immutable.make_list( ('breaking', 5), ('canonical', 6), ('special', 1), ).concat(base_priorities.without(('top_stories', 6))), }) template_names = immutable.make_dict({ 'v1': 'au/daily/v1', 'v2': 'au/daily/v2', 'v3': 'au/daily/v3', 'v2015': 'au/daily/v2015', 'v4': 'au/daily/v4', })
def test_equals_empty(): assert not make_list(1, 2, 3) == make_list()
def test_equals_noniterable(): assert not make_list(1, 2, 3) == 1
def test_equals(): assert make_list(1, 2, 3) == make_list(1, 2, 3)
def empty_model(): "Initializes a new empty model." return ps.make_dict(variables=ps.make_list(), factors=ps.make_list(T.constant(0)), stream=th.tensor.shared_randomstreams.RandomStreams())
def add_stochastic(model, name, new_variable, new_factors): "Returns a stochastic variable, and a version of model that incorporates that variable." new_variable.name = name check_namedup(model, name) return new_variable, model.using(variables = model['variables'].cons(new_variable), factors = model['factors'].concat(ps.make_list(*new_factors)))
def test_replace_raises_error_on_nonexistant_old(): test_list = make_list(1,2,3,4) test_list.replace(old=1000, new=1)
def test_convenience(): ls = make_list(1,2,3) items = list(iter(ls)) assert items == [1,2,3]
def _pys_take(n, l): result = [] for i in range(n): result.append(l.first) l = l.rest return make_list(*result)
def test_frest(): ls = make_list(1, 2) assert 2 == ls.frest
class DailyEmailUS(handlers.EmailTemplate): minify = True cache_bust = False recognized_versions = immutable.make_list('v1', 'v3', 'v6', 'v7', 'v2015', 'v2015_v2', 'v2015_v3', 'v2015_v4', 'categories_us') ad_tag = 'email-guardian-today-us' ad_config = {'leaderboard_v1': 'Top', 'leaderboard_v2': 'Bottom'} base_data_sources = immutable.make_dict({ 'business': ds.BusinessDataSource(clientUS), 'technology': dss.technology.TechnologyDataSource(clientUS), 'sport': dss.us.SportUSDataSource(clientUS), 'comment': ds.CommentIsFreeDataSource(clientUS), 'culture': ds.CultureDataSource(clientUS), 'top_stories': ds.TopStoriesDataSource(clientUS), 'video': ds.VideoDataSource(clientUS), }) most_shared_us = ds.MostSharedDataSource( most_shared_fetcher=MostSharedFetcher(ophan_client, country='us'), multi_content_data_source=ds.MultiContentDataSource( client=clientUS, name='most_shared_us'), shared_count_interpolator=ds.MostSharedCountInterpolator()) breaking = container.for_front('us', 'breaking', additional_capi_params=immutable.make_dict( {"show-elements": "image"})) canonical = container.for_front('us', 'canonical', additional_capi_params=immutable.make_dict( {"show-elements": "image"})) special = container.for_front('us', 'special', additional_capi_params=immutable.make_dict( {"show-elements": "image"})) data_sources = immutable.make_dict({ 'v1': base_data_sources, 'v3': base_data_sources, 'v6': base_data_sources.using(most_shared_us=most_shared_us), 'v7': base_data_sources.using(most_shared_us=most_shared_us), 'v2015': base_data_sources.using(most_shared_us=most_shared_us), 'v2015_v2': base_data_sources.using(most_shared_us=most_shared_us), 'v2015_v3': base_data_sources.using(most_shared_us=most_shared_us), 'v2015_v4': base_data_sources.using(most_shared_us=most_shared_us), 'categories_us': base_data_sources.using(breaking=breaking, canonical=canonical, special=special, most_shared_us=most_shared_us) }) base_priorities = immutable.make_list( ('top_stories', 6), ('video', 3), ('sport', 3), ('comment', 3), ('culture', 3), ('business', 2), ('technology', 2), ) priority_list = immutable.make_dict({ 'v1': base_priorities, 'v3': base_priorities, 'v6': base_priorities.cons(('most_shared_us', 6), ), 'v7': base_priorities.without(('business', 2)).cons( ('most_shared_us', 6)).cons(('business', 3)), 'v2015': base_priorities.cons(('most_shared_us', 6)), 'v2015_v2': base_priorities.cons(('most_shared_us', 6)), 'v2015_v3': base_priorities.cons(('most_shared_us', 6)), 'v2015_v4': base_priorities.cons(('most_shared_us', 6)), 'categories_us': immutable.make_list(('breaking', 5), ('canonical', 6), ('special', 1), ('most_shared_us', 6)).concat(base_priorities) }) template_names = immutable.make_dict({ 'v1': 'us/daily/v1', 'v3': 'us/daily/v3', 'v6': 'us/daily/v6', 'v7': 'us/daily/v7', 'v2015': 'us/daily/v2015', 'v2015_v2': 'us/daily/v2015_v2', 'v2015_v3': 'us/daily/v2015_v3', 'v2015_v4': 'us/daily/v2015_v4', 'categories_us': 'us/daily/categories_us' })
def exclude_from_deduplication(self): return immutable.make_list()
def _make_context(self, event, db, interceptors): coeffects = make_dict(db=self._db, event=event) return make_dict(coeffects=coeffects, queue=make_list(*interceptors), stack=make_list())
def test_concat(): list1 = make_list(1, 2) list2 = make_list(3, 4) actual_list = list1 + list2 expected_list = make_list(1, 2, 3, 4) assert actual_list == expected_list
def test_without(): ls = make_list(1,2,3) assert 2 not in ls.without(2)
def test_reverse(): test_list = make_list(1,2,3,4) actual_list = test_list.reverse() expected_list = make_list(4,3,2,1) assert actual_list == expected_list