def store_build_details(build_document, type): build = build_document['build'] doc = get_build_document(build, type) os = build_document['os'] component = build_document['component'] name = build_document['name'] sub_component = build_document[ 'subComponent'] if "subComponent" in build_document else "" implemented_in = getImplementedIn(component, sub_component) if (type not in ALLJOBS): ALLJOBS[type] = {} if os not in ALLJOBS[type]: ALLJOBS[type][os] = {} if component not in ALLJOBS[type][os]: ALLJOBS[type][os][component] = {} ALLJOBS[type][os][component][name] = { "totalCount": build_document['totalCount'], "url": build_document['url'], "priority": build_document['priority'], "implementedIn": implemented_in } if os not in doc['os']: doc['os'][os] = {} if component not in doc['os'][os]: doc['os'][os][component] = {} existing_builds = doc['os'][os][component] if name in existing_builds: build_exist = [ t for t in existing_builds[name] if t['build_id'] == build_document['build_id'] ] if build_exist.__len__() != 0: return else: existing_builds[name] = [] build_to_store = { "build_id": build_document['build_id'], "claim": "", "totalCount": build_document['totalCount'], "result": build_document['result'], "duration": build_document['duration'], "url": build_document['url'], "priority": build_document['priority'], "failCount": build_document['failCount'], "color": build_document['color'] if 'color' in build_document else '', "deleted": False, "olderBuild": False, "disabled": False } doc['os'][os][component][name].append(build_to_store) pydash.sort(doc['os'][os][component][name], key=lambda item: item['build_id'], reverse=True) existing_builds[name][0]['olderBuild'] = False for existing_build in existing_builds[name][1:]: existing_build['olderBuild'] = True get_total_fail_count(doc) client = CLIENTS['builds'] client.upsert(build, doc)
def test_sort_comparison_key_exception(): raised = False try: _.sort([], comparison=lambda: None, key=lambda: None) except Exception: raised = True assert raised
def sanitize(): client = CLIENTS[buildBucketName] query = "select meta().id from `builds` where `build` is not null" for row in client.n1ql_query(N1QLQuery(query)): build_id = row['id'] document = client.get(build_id).value for OS, os_type in document['os'].items(): for COMPONENT, component in os_type.items(): for JOBNAME, jobName in component.items(): pydash.sort(jobName, key=lambda item: item['build_id'], reverse=True) for build in jobName[1:]: build['olderBuild'] = True get_total_fail_count(document) client.upsert(build_id, document)
def handle(self, *app_labels, **options): try: if app_labels and len(app_labels) > 0: app_configs = [ apps.get_app_config(app_label) for app_label in app_labels ] else: app_configs = [ AppConfig.create(app_label) for app_label in settings.INSTALLED_APPS ] except (LookupError, ImportError) as e: raise CommandError( "%s. Are you sure your INSTALLED_APPS setting is correct?" % e) seeders = [] for app_config in app_configs: try: module_seeders = import_module('%s.%s' % (app_config.name, 'seeders')) except ImportError: continue if callable(getattr(module_seeders, 'handle', None)): seeders.append({ 'order': getattr(module_seeders, 'order', 0), 'handle': module_seeders.handle }) else: raise AttributeError( "You should define 'handle' method in %s." % (app_config.name + '.seeders')) seeders = pydash.sort(seeders, key=lambda item: item['order']) for seeder in seeders: seeder['handle'](self) self.stdout.write( self.style.SUCCESS('Database seeding completed successfully.'))
def test_sort_comparator_key_exception(): with pytest.raises(ValueError): _.sort([], comparator=lambda: None, key=lambda: None)
def test_sort(case, expected): array = case[0] assert _.sort(*case) == expected assert array == expected
def sort_mentions(mentions): return _.sort(mentions, key=lambda obj: obj['offset'])