How to use _titleize method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

defaults.py

Source:defaults.py Github

copy

Full Screen

...44 file_name_sans_ext = re.sub('\..*$', '', file_name)45 name_ndx = out_col_ndx_map['Name']46 name = row[name_ndx]47 if not name:48 name = row[name_ndx] = _titleize(file_name_sans_ext)49 desc_ndx = out_col_ndx_map['Description']50 if not row[desc_ndx]:51 row[desc_ndx] = name52 user_id_ndx = out_col_ndx_map['User Defined ID']53 if not row[user_id_ndx]:54 row[user_id_ndx] = (55 inflection.underscore(file_name_sans_ext).replace(' ', '_')56 )57def _add_reagents_defaults(row, out_col_ndx_map, experiment_type=None):58 """59 Makes default values as necessary for the following required columns:60 * `Name` - derived from the `Analyte Reported` and `Catalog Number`61 * `Catalog Number` - `NA`62 * `User Defined ID` - lower-case `Catalog Number` followed by `_reagent`63 * `Description` copied from `Name`64 """65 cat_nbr_ndx = out_col_ndx_map['Catalog Number']66 cat_nbr = row[cat_nbr_ndx]67 if not cat_nbr:68 cat_nbr = row[cat_nbr_ndx] = 'NA'69 analyte = row[out_col_ndx_map['Analyte Reported']]70 if not analyte:71 raise MungeError("Required Analyte Reported value is missing")72 # The default name is used for both the name and the default73 # user id.74 if cat_nbr.lower() == 'na':75 name_parts = [analyte]76 if experiment_type:77 name_parts.append(experiment_type)78 else:79 name_parts = [cat_nbr]80 name_parts.append('Reagent')81 def_name = ' '.join(name_parts)82 name_ndx = out_col_ndx_map['Name']83 name = row[name_ndx]84 if not name:85 name = row[name_ndx] = def_name86 # The default user id is derived from the name.87 user_id_ndx = out_col_ndx_map['User Defined ID']88 if not row[user_id_ndx]:89 row[user_id_ndx] = _name_to_id(def_name)90 # The default description is the name.91 desc_ndx = out_col_ndx_map['Description']92 if not row[desc_ndx]:93 row[desc_ndx] = name94def _add_treatments_defaults(row, out_col_ndx_map, experiment_type=None):95 """96 Makes default values as necessary for the following required columns:97 * `Name` - derived from the treatment values98 * `User Defined ID` - lower-case, underscored `Name` and `Amount Value`99 * `Use Treatment?` - default is `Yes`100 """101 name_ndx = out_col_ndx_map['Name']102 name = row[name_ndx]103 if not name:104 name = _default_treatment_name(row, out_col_ndx_map)105 if not name:106 raise MungeError("Required Name value could not be inferred from " +107 "the " + ','.join(attrs) + " attributes")108 row[name_ndx] = name109 user_id_ndx = out_col_ndx_map['User Defined ID']110 if not row[user_id_ndx]:111 row[user_id_ndx] = _name_to_id(name)112 use_treatment_ndx = out_col_ndx_map['Use Treatment?']113 if not row[use_treatment_ndx]:114 row[use_treatment_ndx] = 'Yes'115def _default_treatment_name(row, out_col_ndx_map, experiment_type=None):116 qualifiers = [_treatment_name_qualifier(row, out_col_ndx_map, type)117 for type in TREATMENT_QUALIFIER_TYPES]118 qualifier_s = ', '.join(filter(None, qualifiers))119 return qualifier_s if qualifier_s else None120def _treatment_name_qualifier(row, out_col_ndx_map, treatment_type):121 value_ndx = out_col_ndx_map[treatment_type + ' Value']122 value = row[value_ndx]123 if value != None:124 unit_ndx = out_col_ndx_map[treatment_type + ' Unit']125 unit = row[unit_ndx]126 if unit != 'Not Specified':127 return ' '.join((value, unit))128def _add_subjectAnimals_defaults(row, out_col_ndx_map):129 """130 Makes default values as necessary for the following required columns:131 * `Age Unit` - `Days`132 * `Age Event` - `Age at infection`133 """134 age_unit_ndx = out_col_ndx_map['Age Unit']135 age_unit = row[age_unit_ndx]136 if not age_unit:137 row[age_unit_ndx] = 'Days'138 age_event_ndx = out_col_ndx_map['Age Event']139 age_event = row[age_event_ndx]140 if not age_event:141 row[age_event_ndx] = 'Age at infection'142def _add_samples_defaults(row, out_col_ndx_map, experiment_type=None):143 """144 Makes default values as necessary for the following required columns:145 * `Experiment ID` - lower-case, underscored `Experiment Name`146 * `Planned Visit ID` - `Study ID` followed by `d` and the147 `Study Time Collected`148 * `Biosample ID` - lower-case, underscored `Biosample Name`,149 if present, otherwise the `Expsample ID`, if present,150 otherwise derived from the `Subject ID`, `Treatment ID(s)`151 and `Experiment ID`152 * `Expsample ID` - derived from the `Biosample ID`, `Treatment ID`153 and Experiment ID154 """155 experiment_id_ndx = out_col_ndx_map['Experiment ID']156 if not row[experiment_id_ndx]:157 name_ndx = out_col_ndx_map['Experiment Name']158 name = row[name_ndx]159 if not name:160 msg = "Both the Experiment ID and Name values are missing"161 raise MungeError(msg)162 row[experiment_id_ndx] = _name_to_id(name)163 visit_id_ndx = out_col_ndx_map['Planned Visit ID']164 visit_id = row[visit_id_ndx]165 if not visit_id:166 visit_id = _default_visit_id(out_col_ndx_map, 'Study Time Collected',167 row)168 row[visit_id_ndx] = visit_id169 biosample_id_ndx = out_col_ndx_map['Biosample ID']170 biosample_id = row[biosample_id_ndx]171 if not biosample_id:172 biosample_id = _default_biosample_id(row, out_col_ndx_map)173 row[biosample_id_ndx] = biosample_id174 expsample_id_ndx = out_col_ndx_map['Expsample ID']175 if not row[expsample_id_ndx]:176 row[expsample_id_ndx] = biosample_id177def _default_biosample_id(row, out_col_ndx_map):178 expsample_id_ndx = out_col_ndx_map['Expsample ID']179 expsample_id = row[expsample_id_ndx]180 if expsample_id:181 return expsample_id182 name_ndx = out_col_ndx_map['Biosample Name']183 name = row[name_ndx]184 if name:185 return _name_to_id(name)186 subject_id_ndx = out_col_ndx_map['Subject ID']187 subject_id = row[subject_id_ndx]188 if not subject_id:189 raise MungeError("The Biosample ID, Expsample ID, Biosample Name" +190 " and Subject ID values are missing")191 experiment_id_ndx = out_col_ndx_map['Experiment ID']192 experiment_id = row[experiment_id_ndx]193 if not experiment_id:194 raise MungeError("The Biosample ID, Expsample ID, Biosample Name" +195 " and Experiment ID values are missing")196 time_ndx = out_col_ndx_map['Study Time Collected']197 time = row[time_ndx]198 if not time:199 raise MungeError("The Biosample ID, Expsample ID, Biosample Name" +200 " and Study Time Collected values are missing")201 time_unit_ndx = out_col_ndx_map['Study Time Collected Unit']202 time_unit = row[time_unit_ndx]203 if not time_unit:204 raise MungeError("The Biosample ID, Expsample ID, Biosample Name" +205 " and Study Time Collected Unit values are missing")206 treatment_ids_ndx = out_col_ndx_map['Treatment ID(s)']207 treatment_ids = row[treatment_ids_ndx]208 if not treatment_ids:209 raise MungeError("The Biosample ID, Expsample ID, Biosample Name" +210 " and Treatment ID(s) values are missing")211 return '_'.join((subject_id, re.sub(', *', '_', treatment_ids),212 time_unit[0].lower() + time, experiment_id))213def _default_visit_id(out_col_ndx_map, study_day_column, row, experiment_type=None):214 """215 :return: the `Study ID` followed by `d` and the study day216 """217 study_id = row[out_col_ndx_map['Study ID']]218 if not study_id:219 raise MungeError("Required Study ID value is missing")220 day = row[out_col_ndx_map[study_day_column]]221 if day == None:222 raise MungeError("Required %s value is missing" % study_day_column)223 day_id = 'd' + str(day)224 return '_'.join((study_id.lower(), day_id))225def _add_assessments_defaults(row, out_col_ndx_map, experiment_type=None):226 """227 Makes default values as necessary for the following required columns:228 * `Planned Visit ID` - `Study ID` followed by `d` and the `Study Day`229 * `Panel Name Reported` - copied from the `Assessment Type`230 * `Assessment Panel ID` - derived from the `Panel Name Reported`231 * `User Defined ID` - derived from the `Subject ID`, `Planned Visit ID`232 and `Component Name Reported`233 """234 visit_id_ndx = out_col_ndx_map['Planned Visit ID']235 visit_id = row[visit_id_ndx]236 if not visit_id:237 visit_id = _default_visit_id(out_col_ndx_map, 'Study Day', row)238 row[visit_id_ndx] = visit_id239 panel_name_ndx = out_col_ndx_map['Panel Name Reported']240 panel_name = row[panel_name_ndx]241 if not panel_name:242 type = row[out_col_ndx_map['Assessment Type']]243 if not type:244 raise MungeError("Neither the Panel Name Reported nor the " +245 "Assessment Type value is missing")246 panel_name = row[panel_name_ndx] = type247 panel_id_ndx = out_col_ndx_map['Assessment Panel ID']248 panel_id = row[panel_id_ndx]249 if not panel_id:250 panel_id = row[panel_id_ndx] = panel_name.lower().replace(' ', '_')251 user_id_ndx = out_col_ndx_map['User Defined ID']252 if not row[user_id_ndx]:253 subject_id = row[out_col_ndx_map['Subject ID']]254 if not subject_id:255 raise MungeError("Required Subject ID value is missing")256 component_name_ndx = out_col_ndx_map['Component Name Reported']257 component_name = row[component_name_ndx]258 if not component_name:259 raise MungeError("Required Component Name Reported value is missing")260 row[user_id_ndx] = '_'.join((subject_id, visit_id, component_name.lower()))261def _name_to_id(name):262 return re.sub(r'[^\w]', '_', name).lower()263def _titleize(s):264 """265 Tweaks `inflection.titleize` to preserve acronyms.266 >>> print(inflection.titleize('AB_CdeXYZ_Name'))267 Ab Cde Xyz Name268 >>> print(defaults._titleize('AB_CdeXYZ_Name'))269 AB Cde XYZ Name270 """271 acronyms = re.findall('[A-Z][A-Z]+', s)272 recapitalize = {acronym.capitalize(): acronym for acronym in acronyms}273 title = inflection.titleize(s)274 for k, v in recapitalize.items():275 title = title.replace(k, v)276 return title277"""The default callbuck functions."""278DEF_CALLBACKS = dict(protocols=_add_protocols_defaults,279 treatments=_add_treatments_defaults,280 reagents=_add_reagents_defaults,281 subjectAnimals=_add_subjectAnimals_defaults,282 experimentSamples=_add_samples_defaults,...

Full Screen

Full Screen

slack_webhook.py

Source:slack_webhook.py Github

copy

Full Screen

...30 Returns:31 str: base64 encoded str32 """33 return b64encode(inp.encode()).decode()34def _titleize(inp: str) -> str:35 """_titleize.36 Args:37 inp (str): inp38 Returns:39 str: titlized str (i.e foo_bar == Foo Bar)40 """41 arr = inp.split("_")42 return " ".join(i.title() for i in arr)43def _json_str(inp: str) -> str:44 """_json_str.45 Args:46 inp (str): inp47 Returns:48 str: json escaped string...

Full Screen

Full Screen

name.py

Source:name.py Github

copy

Full Screen

...56 return name57 raise RuntimeError(58 "this type is not named, please considering use NewNamedType(<name>, <type>)"59 )60def _titleize(name: str) -> str:61 if not name:62 return name63 name = str(name)64 return "{}{}".format(name[0].upper(), name[1:])65class NameGuesser:66 def __init__(67 self,68 resolver: NameResolver,69 *,70 formatter: t.Callable[[str], str] = _titleize,71 _aliases: t.Optional[t.Dict[object, str]] = None,72 _joiners: t.Optional[73 t.Dict[object, t.Callable[[t.Type[t.Any], t.Tuple[t.Any, ...]], str]]74 ] = None,...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-pageobjects automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful