Best Python code snippet using tox_python
program_layer.py
Source:program_layer.py
...31log = logging.getLogger()32class ProgramLayer(BaseController):33 @expose('hollyrosa.templates.visiting_group.edit_layers')34 @validate(validators={"visiting_group_id": validators.UnicodeString()})35 @require(Any(has_level('staff'), has_level('pl'), msg='Only PL and staff members may change layers configuration'))36 def edit_layers(self, visiting_group_id):37 vgroup = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)38 vgroup_layers = vgroup.get('layers', list())39 # ...make map of layers from list of layers, keyed on id40 vgroup_layers_map = dict()41 for tmp_vgroup_layer in vgroup_layers:42 vgroup_layers_map[tmp_vgroup_layer['layer_id']] = tmp_vgroup_layer43 # ...get all visiting group that possibly could be mapped44 vgroups_in_daterange = getVisitingGroupsInDatePeriod(getHollyCouch(), vgroup['from_date'], vgroup['to_date'])45 # ...build data struct for dojo spreadsheet / grid46 grid_items = list()47 for tmp_vgroup_row in vgroups_in_daterange:48 tmp_vgroup = tmp_vgroup_row.doc49 if tmp_vgroup['_id'] != vgroup['_id']:50 if tmp_vgroup['_id'] in vgroup_layers_map.keys():51 grid_items.append(dict(layer_id=tmp_vgroup['_id'], name=tmp_vgroup['name'], connect=True,52 colour=vgroup_layers_map[tmp_vgroup['_id']]['colour'])) # change colours53 else:54 grid_items.append(55 dict(layer_id=tmp_vgroup['_id'], name=tmp_vgroup['name'], connect=False, colour="#fff"))56 grid_data = dict(identifier='layer_id', items=grid_items)57 layer_data = json.dumps(grid_data)58 return dict(visiting_group=vgroup, layer_data=layer_data, reFormatDate=reFormatDate)59 @expose()60 @validate(validators={"visiting_group_id": validators.UnicodeString()})61 @require(Any(has_level('pl'), msg='Only PL may change layers configuration'))62 def update_visiting_group_program_layers(self, visiting_group_id, save_button=None, layer_data=''):63 log.info("update_visiting_group_program_layers")64 ensurePostRequest(request, __name__)65 vgroup = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)66 vgroup_layers = vgroup.get('layers', list())67 layer_json = json.loads(layer_data)68 layer_to_save = list()69 for tmp_layer_data in layer_json['items']:70 if tmp_layer_data['connect']:71 layer_to_save.append(dict(layer_id=tmp_layer_data['layer_id'], colour=tmp_layer_data['colour'],72 name=tmp_layer_data['name']))73 vgroup['layers'] = layer_to_save74 getHollyCouch()[vgroup['_id']] = vgroup75 raise redirect(request.referer)76 @expose('hollyrosa.templates.visiting_group.program_booking_layers')77 @validate(validators={"visiting_group_id": validators.UnicodeString()})78 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),79 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))80 def layers(self, visiting_group_id):81 vgroup = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)82 notes = [n.doc for n in getNotesForTarget(getHollyCouch(), visiting_group_id)]83 return dict(visiting_group=vgroup,84 notes=notes,85 tags=[],86 reFormatDate=reFormatDate,87 program_state_map=bokn_status_map)88 def get_program_layer_bookings(self, visiting_group, layer_title, layer_colour):89 bookings = []90 for tmp in get_bookings_of_visiting_group(getHollyCouch(), visiting_group['name'], '<- MATCHES NO GROUP ->'):91 tmp_doc = tmp.doc92 tmp_doc['layer_title'] = layer_title93 tmp_doc['layer_colour'] = layer_colour94 bookings.append(tmp_doc)95 return bookings96 @expose('hollyrosa.templates.program_booking_layers_show_printable_table')97 @validate(validators={"visiting_group_id": validators.UnicodeString(), "hide_comment": validators.Int()})98 @require(Any(has_level('pl'), has_level('staff'), has_level('view'), has_level('vgroup'),99 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))100 def layers_printable(self, visiting_group_id, hide_comment=1):101 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)102 date_range = dateRange(visiting_group['from_date'], visiting_group['to_date'])103 number_of_days = len(date_range)104 width_ratio = (100.0 / (number_of_days + 1))105 # ...TODO organize bookings per layer bucket106 result = self.program_layer_get_days_helper(visiting_group_id)107 result['notes'] = []108 result['tags'] = []109 result['reFormatDate'] = reFormatDate110 result['visiting_group'] = visiting_group111 slot_id_time_id_map = result['slot_id_time_map']112 bookings = dict()113 layers = visiting_group.get('layers', list())114 layers.append(dict(title=visiting_group['name'], colour='#ffe', layer_id=visiting_group_id))115 unscheduled_bookings = []116 # ...code repeat for making used_activities117 activities = dict()118 used_activities_keys = dict()119 for x in getAllActivities(getHollyCouch()):120 activities[x.key[1]] = x.doc121 for tmp_layer in layers:122 tmp_visiting_group = common_couch.getVisitingGroup(getHollyCouch(), tmp_layer['layer_id'])123 bookings_list = self.get_program_layer_bookings(tmp_visiting_group, tmp_visiting_group['name'],124 tmp_layer['colour'])125 for tmp_booking in bookings_list:126 tmp_booking['layer_colour'] = tmp_layer['colour']127 if '' != tmp_booking['slot_id']:128 tmp_time_id = slot_id_time_id_map[tmp_booking['slot_id']]129 hide_cache_content_in_booking(tmp_booking)130 tmp_id = tmp_booking['booking_day_id'] + ':' + tmp_time_id131 if tmp_id not in bookings:132 bookings[tmp_id] = list()133 bookings[tmp_id].append(tmp_booking)134 else:135 hide_cache_content_in_booking(tmp_booking)136 unscheduled_bookings.append(tmp_booking)137 # ...fix used activities138 used_activities_keys[tmp_booking['activity_id']] = 1139 used_activities_keys[activities[tmp_booking['activity_id']]['activity_group_id']] = 1140 result['bookings'] = bookings141 result['width_ratio'] = width_ratio142 result['unscheduled_bookings'] = unscheduled_bookings143 visiting_group_language = visiting_group.get('language', default_language)144 result['booking_info_notes'] = get_booking_info_notes_with_matched_language(getHollyCouch(),145 used_activities_keys,146 visiting_group_language)147 return result148 @expose("json")149 @validate(validators={"visiting_group_id": validators.UnicodeString()})150 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),151 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))152 def program_layer_get_days(self, visiting_group_id):153 return self.program_layer_get_days_helper(visiting_group_id)154 def getTimeIdMapping(self):155 time_id_mapping = dict(FM='fm', EM='em')156 time_id_mapping[u'Kväll'] = 'eve'157 time_id_mapping['After hours'] = 'afh'158 return time_id_mapping159 def fillInGeneralizedSlotRow(self, time_id_mapping, any_slot_row_in_schema, generalized_slot_row, layer_times):160 for tmp_slot_row in any_slot_row_in_schema:161 tmp_item = {}162 for k, v in tmp_slot_row.items():163 if k != 'slot_id':164 tmp_item[k] = v165 if k == 'title':166 layer_times.append(dict(title=v, symbol=time_id_mapping[v]))167 generalized_slot_row.append(tmp_item)168 def program_layer_get_days_helper(self, visiting_group_id):169 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)170 # ...create temporary mapping title-> id, in the future, this should be based on time rather on the title (171 # which can be dangerous)172 time_id_mapping = self.getTimeIdMapping()173 booking_days = [bd.doc for bd in174 getBookingDays(getHollyCouch(), visiting_group['from_date'], visiting_group['to_date'])]175 schema_id_map = dict()176 for b in booking_days:177 schema_id_map[b['day_schema_id']] = b178 # ...now, if we have too many day schema ids, we have a problem...179 # TODO dangerous below, we can have diffreent schemas for different days180 first_booking_day = booking_days[0]181 schema_id = first_booking_day['day_schema_id']182 schema_doc = getHollyCouch()[schema_id]183 schema = schema_doc['schema']184 # ...if we assume the same layout for every slot row, we can get first row in schema and use it as template185 any_slot_row_in_schema = schema[list(schema.keys())[0]][186 1:] # skip first part, now we have four time-slots that can be used187 # ...it would be best if we now could clean out the slot_id from the mapping188 generalized_slot_row = []189 layer_times = []190 # ...will change its parameters191 self.fillInGeneralizedSlotRow(time_id_mapping, any_slot_row_in_schema, generalized_slot_row, layer_times)192 # ...iterate through schema and find FM EM etc193 # iterate through schema and find the slot_id maping.194 layer_days = []195 for d in booking_days:196 tmp_item = dict(booking_day_id=d['_id'], date=d['date'])197 layer_days.append(tmp_item)198 # ...199 program_layers = visiting_group.get('layers', [])200 # ...I need to build this mapping from booking_day_id:slot_id:layer_id to datetime bucket201 # so iterate through all schema rows and look at time,202 slot_id_time_map = {}203 for tmp_schema_id in schema_id_map.keys():204 tmp_schema_doc = getHollyCouch()[tmp_schema_id]205 tmp_schema = tmp_schema_doc['schema']206 for tmp_activity_id, tmp_activity_row in tmp_schema.items():207 for tmp_slot in tmp_activity_row[1:]:208 tmp_time = tmp_slot['title']209 slot_id_time_map[tmp_slot['slot_id']] = time_id_mapping[tmp_time]210 # TODO return activity title map211 activity_title_map = getActivityTitleMap(getHollyCouch())212 return dict(layer_time=layer_times, layer_days=layer_days, slot_id_time_map=slot_id_time_map,213 visiting_group_id=visiting_group_id, activity_title_map=activity_title_map,214 program_layers=program_layers)215 @expose("json")216 @validate(validators={"visiting_group_id": validators.UnicodeString(), "layer_title": validators.UnicodeString(),217 "layer_colour": validators.UnicodeString()})218 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),219 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))220 def program_layer_get_bookings(self, visiting_group_id, layer_title='', layer_colour='#fff'):221 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)222 bookings = self.get_program_layer_bookings(visiting_group, layer_title, layer_colour)223 processed_bookings = list()224 for b in bookings:225 hide_cache_content_in_booking(b)226 processed_bookings.append(b)227 bucket_texts = []228 for tmp in getAllProgramLayerBucketTexts(getHollyCouch(), visiting_group_id):229 tmp_doc = tmp.doc230 tmp_doc['layer_title'] = visiting_group['name']231 tmp_doc['layer_colour'] = '#fff' # layer_colour232 # TODO: check if we want to hide comments. Really. Probably more dependent on who is logged in. Like233 # program staff or visiting group234 bucket_texts.append(tmp_doc)235 return dict(bookings=processed_bookings, bucket_texts=bucket_texts)236 @expose("json")237 @validate(validators={"visiting_group_id": validators.UnicodeString(), "layer_text_id": validators.UnicodeString()})238 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),239 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))240 def program_layer_edit_text(self, visiting_group_id, layer_text_id=''):241 is_new = (layer_text_id == '')242 if is_new:243 layer_text = DataContainer(text='', title='', program_layer_text_id='', state=0)244 else:245 layer_text = common_couch.getLayerText(getHollyCouch(), layer_text_id)246 return dict(layer_text=layer_text)247 @expose("json")248 @validate(validators={"visiting_group_id": validators.UnicodeString(), "booking_day_id": validators.UnicodeString(),249 "bucket_time": validators.UnicodeString(), "layer_text_id": validators.UnicodeString(),250 "text": validators.UnicodeString(), "title": validators.UnicodeString()})251 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),252 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))253 def program_layer_save_layer_text(self, visiting_group_id='', booking_day_id='', bucket_time='', layer_text_id='',254 text='', title=''):255 log.info("program_layer_save_layer_text")256 ensurePostRequest(request, __name__)257 is_new = (layer_text_id == '')258 if is_new:259 id = genUID(type='program_layer_text')260 # ...if slot_id is none, we need to figure out slot_id of bucket_time OR we simply save bucket_time261 layer_text = dict(type='program_layer_text', subtype='layer_text', state=0, booking_day_id=booking_day_id,262 bucket_time=bucket_time)263 # ...populate sheets and computed sheets?264 layer_text['text'] = text265 layer_text['title'] = title266 layer_text['visiting_group_id'] = visiting_group_id267 getHollyCouch()[id] = layer_text268 else:269 layer_text = common_couch.getLayerText(getHollyCouch(), layer_text_id)270 layer_text['text'] = text271 layer_text['title'] = title272 getHollyCouch()[layer_text['_id']] = layer_text273 # TODO call it bucket text or layer text ?274 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)275 layer_text['layer_title'] = visiting_group['name']276 layer_text['layer_colour'] = "#fff"277 return dict(layer_text=layer_text)278 @expose("json")279 @validate(validators={"visiting_group_id": validators.UnicodeString(), "booking_day_id": validators.UnicodeString(),280 "bucket_time": validators.UnicodeString()})281 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),282 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))283 def program_layer_new_layer_text(self, visiting_group_id='', booking_day_id='', bucket_time=''):284 layer_text = dict(type='program_layer_text', subtype='layer_text', status=0, booking_day_id=booking_day_id,285 bucket_time=bucket_time, text='', title='', visiting_group_id=visiting_group_id)286 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), visiting_group_id)287 layer_text['layer_title'] = visiting_group['name']288 layer_text['layer_colour'] = "#fff"289 return dict(layer_text=layer_text)290 @expose("json")291 @validate(validators={"layer_text_id": validators.UnicodeString()})292 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),293 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))294 def program_layer_get_layer_text(self, layer_text_id=''):295 layer_text = common_couch.getLayerText(getHollyCouch(), layer_text_id)296 visiting_group = common_couch.getVisitingGroup(getHollyCouch(), layer_text['visiting_group_id'])297 layer_text['layer_title'] = visiting_group['name']298 layer_text['layer_colour'] = "#fff"299 layer_text['layer_text_id'] = layer_text['_id']300 return dict(layer_text=layer_text)301 @expose("json")302 @validate(validators={"layer_text_id": validators.UnicodeString()})303 @require(Any(has_level('pl'), has_level('staff'), has_level('vgroup'),304 msg=u'Du måste vara inloggad för att få tillgång till program lagren'))305 def program_layer_delete_layer_text(self, layer_text_id):306 log.info("program_layer_delete_layer_text()")307 ensurePostRequest(request, __name__)308 layer_text = common_couch.getLayerText(getHollyCouch(), layer_text_id)309 layer_text['state'] = -100310 getHollyCouch()[layer_text_id] = layer_text...
note.py
Source:note.py
...35 def view(self, url):36 """Abort the request with a 404 HTTP status code."""37 abort(404)38 @expose('hollyrosa.templates.note.edit_note')39 @require(Any(has_level('staff'), has_level('pl'), has_level('view'),40 msg='Only staff members and viewers may view visiting group properties'))41 def add_note(self, target_id):42 tmpl_context.form = create_edit_note_form43 note_o = dict(text='', target_id=target_id, note_id='')44 return dict(note=note_o)45 @expose('hollyrosa.templates.note.edit_attachment')46 @require(Any(has_level('staff'), has_level('pl'), has_level('view'),47 msg='Only staff members and viewers may view visiting group properties'))48 def add_attachment(self, target_id):49 tmpl_context.form = create_edit_attachment_form50 attachment_o = dict(text='', target_id=target_id, attachment_id='')51 return dict(attachment=attachment_o)52 @expose('hollyrosa.templates.note.edit_note')53 @require(Any(has_level('staff'), has_level('pl'), has_level('view'),54 msg='Only staff members and viewers may view visiting group properties'))55 def edit_note(self, note_id=None, visiting_group_id=None):56 tmpl_context.form = create_edit_note_form57 if note_id == '':58 note_o = DataContainer(text='', target_id=visiting_group_id, note_id='')59 else:60 note_o = common_couch.getNote(getHollyCouch(), note_id)61 return dict(note=note_o)62 @expose('hollyrosa.templates.note.edit_attachment')63 @require(Any(has_level('staff'), has_level('pl'), has_level('view'),64 msg='Only staff members and viewers may view visiting group properties'))65 def edit_attachment(self, note_id=None, visiting_group_id=None):66 attachment_id = note_id67 tmpl_context.form = create_edit_attachment_form68 if attachment_id == '':69 attachment_o = dict(text='', target_id=visiting_group_id, note_id='')70 else:71 attachment_o = common_couch.getAttachment(getHollyCouch(), attachment_id)72 return dict(attachment=attachment_o)73 @expose("json")74 @require(Any(is_user('user.erspl'), has_level('staff'), has_level('view'),75 msg='Only staff members and viewers may view visiting group properties'))76 def get_notes_for_visiting_group(self, id):77 notes = [n.doc for n in getNotesForTarget(getHollyCouch(), id)]78 return dict(notes=notes, id=id)79 @expose()80 @require(Any(is_user('root'), has_level('staff'), has_level('pl'), has_level('view'),81 msg='Only staff members and viewers may view visiting group properties'))82 def save_note(self, target_id, note_id, text):83 log.info('save_note()')84 ensurePostRequest(request, __name__)85 timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')86 if note_id == '' or note_id is None:87 note_o = dict(type='note', note_id=genUID(type='note'), target_id=target_id, note_state=0, tags=list(),88 history=list(), text='')89 note_change = 'new'90 note_o['timestamp'] = timestamp91 else:92 note_o = common_couch.getNote(getHollyCouch(), note_id)93 history = note_o['history']94 if history is None:95 history = list()96 else:97 history.append([timestamp, note_o['text']])98 note_o['history'] = history99 note_change = 'changed'100 note_o['last_changed_by'] = getLoggedInUserId(request)101 note_o['text'] = cleanHtml(text)102 getHollyCouch()[note_o['note_id']] = note_o103 remember_note_change(getHollyCouch(), target_id=target_id, note_id=note_o['note_id'],104 changed_by=getLoggedInUserId(request), note_change=note_change)105 if 'visiting_group' in note_o['target_id']:106 redirect_to = url('/visiting_group/show_visiting_group', params=dict(visiting_group_id=note_o['target_id']))107 raise redirect(redirect_to)108 elif 'activity' in note_o['target_id']:109 redirect_to = url('/activity/view', params=dict(activity_id=note_o['target_id']))110 raise redirect(redirect_to)111 else:112 # TODO: where do we go from here ?113 raise redirect('/') # redirect(request.referrer)114 @expose()115 @require(Any(is_user('root'), has_level('staff'), has_level('pl'), has_level('view'),116 msg='Only staff members and viewers may view visiting group properties'))117 def save_attachment(self, target_id, text, attachment, _id='', **kwargs):118 log.debug("save_attachment()")119 ensurePostRequest(request, __name__)120 timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')121 if _id == '':122 attachment_o = dict(type='attachment', _id=genUID(type='attachment'), target_id=target_id,123 attachment_state=0, tags=list(), history=list(), text='')124 # attachment_change = 'new'125 attachment_o['timestamp'] = timestamp126 else:127 attachment_o = common_couch.getAttachment(getHollyCouch(), _id)128 history = attachment_o['history']129 if history is None:130 history = list()131 else:132 history.append([timestamp, attachment_o['text']])133 attachment_o['history'] = history134 # attachment_change = 'changed'135 attachment_o['last_changed_by'] = getLoggedInUserId(request)136 attachment_o['text'] = cleanHtml(text if text is not None else '')137 getHollyCouch()[attachment_o['_id']] = attachment_o138 file = request.POST['attachment']139 if file != '':140 getHollyCouch().put_attachment(attachment_o, attachment.file, filename=attachment.filename)141 # TODO FIX BELOW remember_attachment_change(getHollyCouch(), target_id=target_id, attachment_id=attachment_o[142 # '_id'], changed_by=getLoggedInUserId(request), attachment_change=attachment_change)143 # TODO: where do we go from here?144 redirect_to = url('/')145 if 'visiting_group' in attachment_o['target_id']:146 redirect_to = url('/visiting_group/show_visiting_group',147 params=dict(visiting_group_id=attachment_o['target_id']))148 raise redirect(redirect_to)149 @expose()150 @validate(validators={"attachment_id": validators.UnicodeString(), "doc_id": validators.UnicodeString()})151 @require(Any(has_level('pl'), has_level('staff'), has_level('view'),152 msg='Only staff members may view visiting group attachments'))153 def download_attachment(self, attachment_id, doc_id):154 response.content_type = 'x-application/download'155 log.debug(u'Trying to download attachment="%s" filename="%s"' % (attachment_id, doc_id))156 headers = ('Content-Disposition',157 ('attachment;filename=%s' % doc_id).replace(u' ', u'_').replace(u'å', u'a').replace(u'ö',158 u'o').encode(159 'ascii', 'replace'))160 response.headerlist.append(headers)161 return getHollyCouch().get_attachment(attachment_id, doc_id).read()162 @expose()163 @validate(validators={"note_id": validators.UnicodeString(), "visiting_group_id": validators.UnicodeString()})164 @require(Any(has_level('pl'), has_level('staff'), msg='Only staff members may delete notes and attachments'))165 def delete_note(self, note_id, visiting_group_id):166 log.debug(u'Trying to delete note with id="%s" visting_group_id="%s"' % (note_id, visiting_group_id))167 note_o = common_couch.getCouchDBDocument(getHollyCouch(), note_id, doc_type=None)168 if note_o['target_id'] != visiting_group_id:169 abort(403) # TODO: NOT ALLOWED TO DO THIS, FORBIDDEN.170 if note_o['type'] == 'attachment':171 note_o['attachment_state'] = -100172 elif note_o['type'] == 'note':173 note_o['note_state'] = -100174 getHollyCouch()[note_id] = note_o175 # TODO: add to history...
test_experiment_scan_generator.py
Source:test_experiment_scan_generator.py
...7 spacing=10.0,8 randomise_order=False,9 limit_lower=-1.0,10 limit_upper=1.0)11 self.assertTrue(gen.has_level(0))12 self.assertEqual(gen.points_for_level(0), [0.0])13 for i in range(1, 3):14 self.assertFalse(gen.has_level(i))15 def test_expanding_one(self):16 gen = ExpandingGenerator(centre=0.0,17 spacing=1.0,18 randomise_order=False,19 limit_lower=-1.0,20 limit_upper=1.0)21 self.assertTrue(gen.has_level(0))22 self.assertEqual(gen.points_for_level(0), [0.0])23 self.assertTrue(gen.has_level(1))24 self.assertEqual(gen.points_for_level(1), [-1.0, 1.0])25 self.assertFalse(gen.has_level(2))26 def test_expanding_lower_lim(self):27 gen = ExpandingGenerator(centre=0.0,28 spacing=1.0,29 randomise_order=False,30 limit_lower=-1.0)31 self.assertTrue(gen.has_level(0))32 self.assertEqual(gen.points_for_level(0), [0.0])33 self.assertTrue(gen.has_level(1))34 self.assertEqual(gen.points_for_level(1), [-1.0, 1.0])35 self.assertTrue(gen.has_level(2))36 self.assertEqual(gen.points_for_level(2), [2.0])37 self.assertTrue(gen.has_level(10))38 self.assertEqual(gen.points_for_level(10), [10.0])39 def test_expanding_upper_lim(self):40 gen = ExpandingGenerator(centre=0.0,41 spacing=1.0,42 randomise_order=False,43 limit_upper=1.0)44 self.assertTrue(gen.has_level(0))45 self.assertEqual(gen.points_for_level(0), [0.0])46 self.assertTrue(gen.has_level(1))47 self.assertEqual(gen.points_for_level(1), [-1.0, 1.0])48 self.assertTrue(gen.has_level(2))49 self.assertEqual(gen.points_for_level(2), [-2.0])50 self.assertTrue(gen.has_level(10))51 self.assertEqual(gen.points_for_level(10), [-10.0])52 def test_expanding_no_lim(self):53 gen = ExpandingGenerator(centre=0.0, spacing=1.0, randomise_order=False)54 self.assertTrue(gen.has_level(0))55 self.assertEqual(gen.points_for_level(0), [0.0])56 self.assertTrue(gen.has_level(1))57 self.assertEqual(gen.points_for_level(1), [-1.0, 1.0])58 self.assertTrue(gen.has_level(10))59 self.assertEqual(gen.points_for_level(10), [-10.0, 10.0])60 def test_centre_empty(self):61 with self.assertRaises(ValueError):62 CentreSpanGenerator(centre=0.0,63 half_span=1.0,64 num_points=0,65 randomise_order=False)66 def test_centre_one(self):67 gen = CentreSpanGenerator(centre=0.0,68 half_span=1.0,69 num_points=1,70 randomise_order=True)71 self.assertTrue(gen.has_level(0))72 self.assertEqual(gen.points_for_level(0, np.random), [0.0])73 self.assertFalse(gen.has_level(1))74 def test_centre_two(self):75 gen = CentreSpanGenerator(centre=0.0,76 half_span=1.0,77 num_points=2,78 randomise_order=False)79 self.assertTrue(gen.has_level(0))80 self.assertEqual(gen.points_for_level(0), [-1.0, 1.0])81 self.assertFalse(gen.has_level(1))82 def test_centre_three(self):83 gen = CentreSpanGenerator(centre=0.0,84 half_span=1.0,85 num_points=3,86 randomise_order=False)87 self.assertTrue(gen.has_level(0))88 self.assertEqual(gen.points_for_level(0), [-1.0, 0.0, 1.0])89 self.assertFalse(gen.has_level(1))90 def test_centre_lower_lim(self):91 gen = CentreSpanGenerator(centre=0.0,92 half_span=1.0,93 num_points=2,94 randomise_order=False,95 limit_lower=0.0)96 self.assertTrue(gen.has_level(0))97 self.assertEqual(gen.points_for_level(0), [0.0, 1.0])98 self.assertFalse(gen.has_level(1))99 def test_centre_upper_lim(self):100 gen = CentreSpanGenerator(centre=0.0,101 half_span=1.0,102 num_points=2,103 randomise_order=False,104 limit_upper=0.0)105 self.assertTrue(gen.has_level(0))106 self.assertEqual(gen.points_for_level(0), [-1.0, 0.0])...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!