Best Python code snippet using selene_python
property_helpers.py
Source:property_helpers.py
1import os2from enum import Enum3from phoebusgen import _update_color_def, _update_font_def4class GenericTest(object):5 curr_path = os.path.dirname(__file__)6 predefined_colors = _update_color_def(curr_path + '/../phoebusgen/config/color.def')7 colors = Enum('colors', predefined_colors)8 predefined_fonts = _update_font_def(curr_path + '/../phoebusgen/config/font.def')9 fonts = Enum('fonts', predefined_fonts)10 def test_basics(self):11 self.assertEqual(self.element.get_element_value('name'), self.name)12 self.assertEqual(self.element.get_element_value('x'), str(self.x))13 self.assertEqual(self.element.get_element_value('y'), str(self.y))14 self.assertEqual(self.element.get_element_value('width'), str(self.width))15 self.assertEqual(self.element.get_element_value('height'), str(self.height))16 tool_tip = 'this is a test tooltip check it out!'17 self.element.tool_tip(tool_tip)18 self.assertEqual(self.element.get_element_value('tooltip'), tool_tip)19 self.assertEqual(self.element.root.attrib['type'], self.type)20 def test_against_file(self):21 curr_path = os.path.dirname(__file__)22 try:23 open(curr_path + '../files/widgets/{}.bob'.format(self.element.root.attrib['type']))24 except FileNotFoundError:25 print('File Not there!')26 return27 with open(curr_path + '/../files/widgets/{}.bob'.format(self.element.root.attrib['type'])) as f:28 xml = f.read()29 self.assertEqual(xml, self.element.prettify(self.element.root))30 def generic_element_test(self, tag_name, value):31 element = self.element.find_element(tag_name)32 self.assertFalse(isinstance(element, list))33 self.assertIsNotNone(element)34 if value is None:35 self.assertIsNone(element.text)36 else:37 if isinstance(value, bool):38 self.assertEqual(element.text, str(value).lower())39 else:40 self.assertEqual(element.text, str(value))41 self.element.remove_element(tag_name)42 self.assertIsNone(self.element.find_element(tag_name))43 def null_test(self, tag_name):44 self.assertIsNone(self.element.root.find(tag_name))45 # for some properties (actions, macros, you can have multiple children. Pass True to do_not_remove for these46 def child_element_test(self, parent_tag, tag_name, value, attrib, do_not_remove=False):47 parent = self.element.find_element(parent_tag)48 self.assertIsNotNone(parent)49 child = parent.find(tag_name)50 self.assertIsNotNone(child)51 if value is None:52 self.assertIsNone(child.text)53 else:54 self.assertEqual(child.text, str(value))55 self.assertEqual(child.attrib, attrib)56 if not do_not_remove:57 self.element.remove_element(parent_tag)58 self.assertIsNone(self.element.find_element(parent_tag))59class TestPVName(GenericTest):60 def test_pv_name(self):61 self.assertEqual(self.element.find_element('pv_name').text, self.pv_name)62class TestText(GenericTest):63 def test_text(self):64 self.assertEqual(self.element.find_element('text').text, self.text)65class TestFont(GenericTest):66 font_element_name = 'font'67 default_font_family = 'Liberation Sans'68 default_font_style = 'REGULAR'69 default_font_size = '14'70 def test_predefined_font(self):71 self.element.predefined_font(self.fonts.Comment)72 self.child_element_test(self.font_element_name, 'font', None, {'name': 'Comment', 'family': 'Liberation Sans', 'size': '14', 'style': 'ITALIC'})73 def test_predefined_font2(self):74 self.element.predefined_font(self.fonts.Header1)75 self.child_element_test(self.font_element_name, 'font', None, {'name': 'Header 1', 'family': 'Liberation Sans', 'size': '22', 'style': 'BOLD'})76 def test_font_family(self):77 value = 'Liberation Serif'78 self.element.font_family(value)79 self.child_element_test(self.font_element_name, 'font', None,80 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})81 def test_font_family2(self):82 value = 'Noto Sans Sinhala'83 self.element.font_family(value)84 self.child_element_test(self.font_element_name, 'font', None,85 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})86 def test_font_size(self):87 value = 72.088 self.element.font_size(value)89 self.child_element_test(self.font_element_name, 'font', None,90 {'family': self.default_font_family, 'size': str(int(value)), 'style': self.default_font_style})91 def test_font_size_wrong(self):92 value = 'tset'93 self.element.font_size(value)94 self.null_test(self.font_element_name)95 def test_multiple_fonts(self):96 size_val = 2697 self.element.font_size(size_val)98 self.element.font_style_bold_italic()99 self.child_element_test(self.font_element_name, 'font', None,100 {'family': self.default_font_family, 'size': str(int(size_val)), 'style': 'BOLD_ITALIC'})101 def test_change_font_attributes(self):102 value = 'Liberation Serif'103 self.element.font_family(value)104 self.child_element_test(self.font_element_name, 'font', None,105 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})106 value = 'Cantarell'107 self.element.font_family(value)108 self.child_element_test(self.font_element_name, 'font', None,109 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})110 def test_font_style_regular(self):111 self.element.font_style_regular()112 self.child_element_test(self.font_element_name, 'font', None,113 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'REGULAR'})114 def test_font_style_bold(self):115 self.element.font_style_bold()116 self.child_element_test(self.font_element_name, 'font', None,117 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD'})118 def test_font_style_bold_italic(self):119 self.element.font_style_bold_italic()120 self.child_element_test(self.font_element_name, 'font', None,121 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD_ITALIC'})122 def test_font_style_italic(self):123 self.element.font_style_italic()124 self.child_element_test(self.font_element_name, 'font', None,125 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'ITALIC'})126 def test_defaults(self):127 self.element.font_family(self.default_font_family)128 self.child_element_test(self.font_element_name, 'font', None,129 {'family': self.default_font_family, 'size': self.default_font_size, 'style': self.default_font_style})130class TestTitleFont(GenericTest):131 font_element_name = 'title_font'132 default_font_family = 'Liberation Sans'133 default_font_style = 'REGULAR'134 default_font_size = '14'135 def test_title_predefined_font(self):136 self.element.predefined_title_font(self.fonts.Comment)137 self.child_element_test(self.font_element_name, 'font', None, {'name': 'Comment', 'family': 'Liberation Sans', 'size': '14', 'style': 'ITALIC'})138 def test_title_predefined_font2(self):139 self.element.predefined_title_font(self.fonts.Header1)140 self.child_element_test(self.font_element_name, 'font', None, {'name': 'Header 1', 'family': 'Liberation Sans', 'size': '22', 'style': 'BOLD'})141 def test_title_font_family(self):142 value = 'Liberation Serif'143 self.element.title_font_family(value)144 self.child_element_test(self.font_element_name, 'font', None,145 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})146 def test_title_font_family2(self):147 value = 'Noto Sans Sinhala'148 self.element.title_font_family(value)149 self.child_element_test(self.font_element_name, 'font', None,150 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})151 def test_title_font_size(self):152 value = 72.0153 self.element.title_font_size(value)154 self.child_element_test(self.font_element_name, 'font', None,155 {'family': self.default_font_family, 'size': str(int(value)), 'style': self.default_font_style})156 def test_title_font_size_wrong(self):157 value = 'tset'158 self.element.title_font_size(value)159 self.null_test(self.font_element_name)160 def test_title_multiple_fonts(self):161 size_val = 26162 self.element.title_font_size(size_val)163 self.element.title_font_style_bold_italic()164 self.child_element_test(self.font_element_name, 'font', None,165 {'family': self.default_font_family, 'size': str(int(size_val)), 'style': 'BOLD_ITALIC'})166 def test_title_change_font_attributes(self):167 value = 'Liberation Serif'168 self.element.title_font_family(value)169 self.child_element_test(self.font_element_name, 'font', None,170 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})171 value = 'Cantarell'172 self.element.title_font_family(value)173 self.child_element_test(self.font_element_name, 'font', None,174 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})175 def test_title_font_style_regular(self):176 self.element.title_font_style_regular()177 self.child_element_test(self.font_element_name, 'font', None,178 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'REGULAR'})179 def test_title_font_style_bold(self):180 self.element.title_font_style_bold()181 self.child_element_test(self.font_element_name, 'font', None,182 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD'})183 def test_title_font_style_bold_italic(self):184 self.element.title_font_style_bold_italic()185 self.child_element_test(self.font_element_name, 'font', None,186 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD_ITALIC'})187 def test_title_font_style_italic(self):188 self.element.title_font_style_italic()189 self.child_element_test(self.font_element_name, 'font', None,190 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'ITALIC'})191 def test_title_defaults(self):192 self.element.title_font_family(self.default_font_family)193 self.child_element_test(self.font_element_name, 'font', None,194 {'family': self.default_font_family, 'size': self.default_font_size, 'style': self.default_font_style})195class TestLabelFont(GenericTest):196 label_font_element_name = 'label_font'197 default_font_family = 'Liberation Sans'198 default_font_style = 'REGULAR'199 default_font_size = '14'200 def test_label_predefined_font(self):201 self.element.predefined_label_font(self.fonts.Comment)202 print(self.element)203 self.child_element_test(self.label_font_element_name, 'font', None, {'name': 'Comment', 'family': 'Liberation Sans', 'size': '14', 'style': 'ITALIC'})204 def test_label_predefined_font2(self):205 self.element.predefined_label_font(self.fonts.Header1)206 print(self.element)207 self.child_element_test(self.label_font_element_name, 'font', None, {'name': 'Header 1', 'family': 'Liberation Sans', 'size': '22', 'style': 'BOLD'})208 def test_label_font_family(self):209 value = 'Liberation Serif'210 self.element.label_font_family(value)211 print(self.element)212 self.child_element_test(self.label_font_element_name, 'font', None,213 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})214 def test_label_font_family2(self):215 value = 'Noto Sans Sinhala'216 self.element.label_font_family(value)217 self.child_element_test(self.label_font_element_name, 'font', None,218 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})219 def test_label_font_size(self):220 value = 72.0221 self.element.label_font_size(value)222 self.child_element_test(self.label_font_element_name, 'font', None,223 {'family': self.default_font_family, 'size': str(int(value)), 'style': self.default_font_style})224 def test_label_font_size_wrong(self):225 value = 'tset'226 self.element.label_font_size(value)227 self.null_test(self.label_font_element_name)228 def test_label_multiple_fonts(self):229 size_val = 26230 self.element.label_font_size(size_val)231 self.element.label_font_style_bold_italic()232 self.child_element_test(self.label_font_element_name, 'font', None,233 {'family': self.default_font_family, 'size': str(int(size_val)), 'style': 'BOLD_ITALIC'})234 def test_label_change_font_attributes(self):235 value = 'Liberation Serif'236 self.element.label_font_family(value)237 self.child_element_test(self.label_font_element_name, 'font', None,238 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})239 value = 'Cantarell'240 self.element.label_font_family(value)241 self.child_element_test(self.label_font_element_name, 'font', None,242 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})243 def test_label_font_style_regular(self):244 self.element.label_font_style_regular()245 self.child_element_test(self.label_font_element_name, 'font', None,246 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'REGULAR'})247 def test_label_font_style_bold(self):248 self.element.label_font_style_bold()249 self.child_element_test(self.label_font_element_name, 'font', None,250 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD'})251 def test_label_font_style_bold_italic(self):252 self.element.label_font_style_bold_italic()253 self.child_element_test(self.label_font_element_name, 'font', None,254 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD_ITALIC'})255 def test_label_font_style_italic(self):256 self.element.label_font_style_italic()257 self.child_element_test(self.label_font_element_name, 'font', None,258 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'ITALIC'})259 def test_label_defaults(self):260 self.element.label_font_family(self.default_font_family)261 self.child_element_test(self.label_font_element_name, 'font', None,262 {'family': self.default_font_family, 'size': self.default_font_size, 'style': self.default_font_style})263class TestScaleFont(GenericTest):264 scale_font_element_name = 'scale_font'265 default_font_family = 'Liberation Sans'266 default_font_style = 'REGULAR'267 default_font_size = '14'268 def test_scale_predefined_font(self):269 self.element.predefined_scale_font(self.fonts.Comment)270 self.child_element_test(self.scale_font_element_name, 'font', None, {'name': 'Comment', 'family': 'Liberation Sans', 'size': '14', 'style': 'ITALIC'})271 def test_scale_predefined_font2(self):272 self.element.predefined_scale_font(self.fonts.Header1)273 self.child_element_test(self.scale_font_element_name, 'font', None, {'name': 'Header 1', 'family': 'Liberation Sans', 'size': '22', 'style': 'BOLD'})274 def test_scale_font_family(self):275 value = 'Liberation Serif'276 self.element.scale_font_family(value)277 self.child_element_test(self.scale_font_element_name, 'font', None,278 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})279 def test_scale_font_family2(self):280 value = 'Noto Sans Sinhala'281 self.element.scale_font_family(value)282 self.child_element_test(self.scale_font_element_name, 'font', None,283 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})284 def test_scale_font_size(self):285 value = 72.0286 self.element.scale_font_size(value)287 self.child_element_test(self.scale_font_element_name, 'font', None,288 {'family': self.default_font_family, 'size': str(int(value)), 'style': self.default_font_style})289 def test_scale_font_size_wrong(self):290 value = 'tset'291 self.element.scale_font_size(value)292 self.null_test(self.scale_font_element_name)293 def test_scale_multiple_fonts(self):294 size_val = 26295 self.element.scale_font_size(size_val)296 self.element.scale_font_style_bold_italic()297 self.child_element_test(self.scale_font_element_name, 'font', None,298 {'family': self.default_font_family, 'size': str(int(size_val)), 'style': 'BOLD_ITALIC'})299 def test_scale_change_font_attributes(self):300 value = 'Liberation Serif'301 self.element.scale_font_family(value)302 self.child_element_test(self.scale_font_element_name, 'font', None,303 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})304 value = 'Cantarell'305 self.element.scale_font_family(value)306 self.child_element_test(self.scale_font_element_name, 'font', None,307 {'family': value, 'size': self.default_font_size, 'style': self.default_font_style})308 def test_scale_font_style_regular(self):309 self.element.scale_font_style_regular()310 self.child_element_test(self.scale_font_element_name, 'font', None,311 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'REGULAR'})312 def test_scale_font_style_bold(self):313 self.element.scale_font_style_bold()314 self.child_element_test(self.scale_font_element_name, 'font', None,315 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD'})316 def test_scale_font_style_bold_italic(self):317 self.element.scale_font_style_bold_italic()318 self.child_element_test(self.scale_font_element_name, 'font', None,319 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'BOLD_ITALIC'})320 def test_scale_font_style_italic(self):321 self.element.scale_font_style_italic()322 self.child_element_test(self.scale_font_element_name, 'font', None,323 {'family': self.default_font_family, 'size': self.default_font_size, 'style': 'ITALIC'})324 def test_scale_defaults(self):325 self.element.scale_font_family(self.default_font_family)326 self.child_element_test(self.scale_font_element_name, 'font', None,327 {'family': self.default_font_family, 'size': self.default_font_size, 'style': self.default_font_style})328class TestForegroundColor(GenericTest):329 def test_predefined_foreground_color(self):330 tag_name = 'foreground_color'331 self.element.predefined_foreground_color(self.colors.Background)332 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',333 'blue': '255', 'alpha': '255'})334 def test_foreground_color(self):335 tag_name = 'foreground_color'336 self.element.foreground_color(5, 10, 15)337 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',338 'blue': '15', 'alpha': '255'})339class TestBackgroundColor(GenericTest):340 def test_predefined_background_color(self):341 tag_name = 'background_color'342 self.element.predefined_background_color(self.colors.MINOR)343 self.child_element_test(tag_name, 'color', None, {'name': 'MINOR', 'red': '255', 'green': '128', 'blue': '0', 'alpha': '255'})344 def test_background_color(self):345 tag_name = 'background_color'346 self.element.background_color(5, 10, 15)347 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10', 'blue': '15', 'alpha': '255'})348class TestTransparent(GenericTest):349 def test_transparent(self):350 tag_name = 'transparent'351 value = True352 self.element.transparent(value)353 self.generic_element_test(tag_name, value)354class TestFormat(GenericTest):355 def test_format(self):356 tag_name = 'format'357 value = 'Engineering'358 xml_value = '3'359 self.element.format(value)360 self.generic_element_test(tag_name, xml_value)361class TestPrecision(GenericTest):362 def test_precision(self):363 tag_name = 'precision'364 value = 25.3365 real_value = '25'366 self.element.precision(value)367 self.generic_element_test(tag_name, real_value)368class TestShowUnits(GenericTest):369 def test_show_units(self):370 tag_name = 'show_units'371 value = False372 self.element.show_units(value)373 self.generic_element_test(tag_name, value)374class TestHorizontalAlignment(GenericTest):375 def test_horizontal_alignment(self):376 tag_name = 'horizontal_alignment'377 xml_value = 1378 self.element.horizontal_alignment_center()379 self.generic_element_test(tag_name, xml_value)380 def test_horizontal_alignment_left(self):381 tag_name = 'horizontal_alignment'382 xml_value = 0383 self.element.horizontal_alignment_right()384 self.element.horizontal_alignment_left()385 self.generic_element_test(tag_name, xml_value)386 def test_horizontal_alignment_right(self):387 tag_name = 'horizontal_alignment'388 xml_value = 2389 self.element.horizontal_alignment_right()390 self.generic_element_test(tag_name, xml_value)391class TestVerticalAlignment(GenericTest):392 def test_vertical_alignment_1(self):393 tag_name = 'vertical_alignment'394 xml_value = 1395 self.element.vertical_alignment_middle()396 self.generic_element_test(tag_name, xml_value)397 def test_vertical_alignment_0(self):398 tag_name = 'vertical_alignment'399 xml_value = 0400 self.element.vertical_alignment_top()401 self.generic_element_test(tag_name, xml_value)402 def test_vertical_alignment_2(self):403 tag_name = 'vertical_alignment'404 xml_value = 2405 self.element.vertical_alignment_bottom()406 self.generic_element_test(tag_name, xml_value)407class TestWrapWords(GenericTest):408 def test_wrap_words(self):409 tag_name = 'wrap_words'410 value = False411 self.element.wrap_words(value)412 self.generic_element_test(tag_name, value)413class TestRotationStep(GenericTest):414 def test_rotation_step(self):415 tag_name = 'rotation_step'416 xml_value = 2417 self.element.rotation_step_180()418 self.generic_element_test(tag_name, xml_value)419 def test_rotation_step_0(self):420 tag_name = 'rotation_step'421 xml_value = 0422 self.element.rotation_step_180()423 self.element.rotation_step_0()424 self.generic_element_test(tag_name, xml_value)425 def test_rotation_step_90(self):426 tag_name = 'rotation_step'427 xml_value = 1428 self.element.rotation_step_90()429 self.generic_element_test(tag_name, xml_value)430 def test_rotation_step_minus_90(self):431 tag_name = 'rotation_step'432 xml_value = 3433 self.element.rotation_step_negative_90()434 self.generic_element_test(tag_name, xml_value)435class TestBorder(GenericTest):436 def test_border_width(self):437 tag_name = 'border_width'438 value = 2439 self.element.border_width(value)440 self.generic_element_test(tag_name, value)441 def test_border_color(self):442 tag_name = 'border_color'443 self.element.border_color(5, 10, 15)444 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10', 'blue': '15', 'alpha': '255'})445 def test_predefined_border_color(self):446 tag_name = 'border_color'447 self.element.predefined_border_color(self.colors.Attention)448 self.child_element_test(tag_name, 'color', None, {'name': 'Attention', 'red': '255', 'green': '160',449 'blue': '0', 'alpha': '255'})450class TestMacro(GenericTest):451 def test_macro(self):452 self.element.macro('test', 'mac1')453 self.child_element_test('macros', 'test', 'mac1', {}, True)454 self.element.macro('test2', 'mac2')455 self.child_element_test('macros', 'test', 'mac1', {}, True)456class TestBit(GenericTest):457 tag_name = 'bit'458 def test_bit_with_number(self):459 value = 234460 self.element.bit(value)461 self.generic_element_test(self.tag_name, value)462 def test_default_bit(self):463 self.element.bit()464 self.generic_element_test(self.tag_name, -1)465class TestAutoSize(GenericTest):466 def test_auto_size(self):467 tag_name = 'auto_size'468 val = False469 self.element.auto_size(val)470 self.generic_element_test(tag_name, val)471 def test_auto_size_default(self):472 tag_name = 'auto_size'473 self.element.auto_size()474 self.generic_element_test(tag_name, True)475class TestMultiLine(GenericTest):476 def test_multi_line(self):477 tag_name = 'multi_line'478 val = True479 self.element.multi_line(val)480 self.generic_element_test(tag_name, val)481class TestSquare(GenericTest):482 def test_square(self):483 tag_name = 'square'484 val = True485 self.element.square(val)486 self.generic_element_test(tag_name, val)487class TestLabelsFromPV(GenericTest):488 def test_labels_from_pv(self):489 tag_name = 'labels_from_pv'490 val = True491 self.element.labels_from_pv(val)492 self.generic_element_test(tag_name, val)493class TestAlarmBorder(GenericTest):494 def test_alarm_border(self):495 tag_name = 'border_alarm_sensitive'496 val = True497 self.element.alarm_border(val)498 self.generic_element_test(tag_name, val)499class TestEnabled(GenericTest):500 def test_enabled(self):501 tag_name = 'enabled'502 val = False503 self.element.enabled(val)504 self.generic_element_test(tag_name, val)505class TestLineWidth(GenericTest):506 tag_name = 'line_width'507 def test_line_width(self):508 val = 5509 self.element.line_width(val)510 self.generic_element_test(self.tag_name, val)511 def test_line_width_wrong(self):512 val = 'asdfs'513 self.element.line_width(val)514 self.null_test(self.tag_name)515class TestCorner(GenericTest):516 def test_corner_width(self):517 tag_name = 'corner_width'518 val = 5519 self.element.corner_width(val)520 self.generic_element_test(tag_name, val)521 def test_corner_width_string(self):522 tag_name = 'corner_width'523 val = 'asdjflksdjf'524 self.element.corner_width(val)525 self.null_test(tag_name)526 def test_corner_height(self):527 tag_name = 'corner_height'528 val = 5529 self.element.corner_height(val)530 self.generic_element_test(tag_name, val)531 def test_corner_height_string(self):532 tag_name = 'corner_height'533 val = 'asdjflksdjf'534 self.element.corner_height(val)535 self.null_test(tag_name)536class TestAngle(GenericTest):537 def test_angle_start(self):538 tag_name = 'start_angle'539 val = 32540 self.element.angle_start(val)541 self.generic_element_test(tag_name, val)542 def test_angle_size(self):543 tag_name = 'total_angle'544 val = 92545 self.element.angle_size(val)546 self.generic_element_test(tag_name, val)547class TestConfirmation(GenericTest):548 dialog_tag = 'show_confirmation_dialog'549 message_tag = 'confirm_message'550 password_tag = 'password'551 message = 'Are you sure?'552 def test_confirmation_no_password(self):553 self.element.confirmation_dialog(self.message)554 self.generic_element_test(self.message_tag, self.message)555 self.generic_element_test(self.dialog_tag, True)556 self.null_test(self.password_tag)557 self.null_test(self.password_tag)558 def test_confirmation_with_password(self):559 password = '1234569999'560 self.element.confirmation_dialog(self.message, password)561 self.generic_element_test(self.message_tag, self.message)562 self.generic_element_test(self.dialog_tag, True)563 self.generic_element_test(self.password_tag, password)564 def test_turn_off_confirmation(self):565 password = 235893566 self.element.confirmation_dialog(self.message, password)567 self.generic_element_test(self.message_tag, self.message)568 self.generic_element_test(self.dialog_tag, True)569 self.generic_element_test(self.password_tag, password)570 self.element.confirmation_dialog(self.message, password)571 self.element.disable_confirmation_dialog()572 self.generic_element_test(self.password_tag, password)573 self.generic_element_test(self.message_tag, self.message)574 self.generic_element_test(self.dialog_tag, False)575class TestLineColor(GenericTest):576 def test_predefined_line_color(self):577 tag_name = 'line_color'578 self.element.predefined_line_color(self.colors.Background)579 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',580 'blue': '255', 'alpha': '255'})581 def test_line_color(self):582 tag_name = 'line_color'583 self.element.line_color(5, 10, 15)584 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',585 'blue': '15', 'alpha': '255'})586class TestOffColor(GenericTest):587 def test_predefined_off_color(self):588 tag_name = 'off_color'589 self.element.predefined_off_color(self.colors.Background)590 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',591 'blue': '255', 'alpha': '255'})592 def test_predefined_off_color2(self):593 tag_name = 'off_color'594 self.element.predefined_off_color('Background')595 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',596 'blue': '255', 'alpha': '255'})597 def test_predefined_off_color3(self):598 tag_name = 'off_color'599 self.element.predefined_off_color({'name': 'Background', 'red': '255', 'green': '255',600 'blue': '255', 'alpha': '255'})601 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',602 'blue': '255', 'alpha': '255'})603 def test_off_color(self):604 tag_name = 'off_color'605 self.element.off_color(5, 10, 15)606 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',607 'blue': '15', 'alpha': '255'})608class TestOff(TestOffColor):609 def test_off_label(self):610 tag_name = 'off_label'611 value = 'This is off!'612 self.element.off_label(value)613 self.generic_element_test(tag_name, value)614class TestOnColor(GenericTest):615 def test_predefined_on_color(self):616 tag_name = 'on_color'617 self.element.predefined_on_color(self.colors.Background)618 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',619 'blue': '255', 'alpha': '255'})620 def test_on_color(self):621 tag_name = 'on_color'622 self.element.on_color(5, 10, 15)623 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',624 'blue': '15', 'alpha': '255'})625class TestOn(TestOnColor):626 def test_on_label(self):627 tag_name = 'on_label'628 value = 'This is on!'629 self.element.on_label(value)630 self.generic_element_test(tag_name, value)631class TestStretchToFit(GenericTest):632 def test_stretch_to_fit1(self):633 tag_name = 'stretch_image'634 val = False635 self.element.stretch_to_fit(val)636 self.generic_element_test(tag_name, val)637 def test_stretch_to_fit2(self):638 tag_name = 'stretch_image'639 val = 'false'640 self.element.stretch_to_fit(val)641 self.generic_element_test(tag_name, False)642 def test_stretch_to_fit3(self):643 tag_name = 'stretch_image'644 val = True645 self.element.stretch_to_fit(val)646 self.generic_element_test(tag_name, val)647 def test_stretch_to_fit4(self):648 tag_name = 'stretch_image'649 val = 1650 self.element.stretch_to_fit(val)651 self.generic_element_test(tag_name, True)652class TestFile(GenericTest):653 # file is a constructor param for widgets (similar to x or pv_name)654 # so we don't have to add it here, just test that it made it655 def test_file(self):656 tag_name = 'file'657 self.generic_element_test(tag_name, self.file)658class TestRotation(GenericTest):659 tag_name = 'rotation'660 def test_rotation1(self):661 val = 24662 self.element.rotation(val)663 self.generic_element_test(self.tag_name, val)664 def test_rotation2(self):665 val = -12.2666 self.element.rotation(val)667 self.generic_element_test(self.tag_name, val)668 def test_rotation3(self):669 val = 142.2670 self.element.rotation(val)671 self.generic_element_test(self.tag_name, val)672 def test_rotation4(self):673 val = 'sadfdsf'674 self.element.rotation(val)675 self.null_test(self.tag_name)676class TestResizeBehavior(GenericTest):677 tag_name = 'resize'678 def test_no_resize(self):679 self.element.no_resize()680 self.generic_element_test(self.tag_name, 0)681 def test_size_content_to_fit_widget(self):682 self.element.size_content_to_fit_widget()683 self.generic_element_test(self.tag_name, 1)684 def test_size_widget_to_match_content(self):685 self.element.size_widget_to_match_content()686 self.generic_element_test(self.tag_name, 2)687 def test_stretch_content_to_fit_widget(self):688 self.element.stretch_content_to_fit_widget()689 self.generic_element_test(self.tag_name, 3)690 def test_crop_content(self):691 self.element.crop_content()692 self.generic_element_test(self.tag_name, 4)693class TestGroupName(GenericTest):694 # we should be able to add property multiple times, with only the latest being added to xml695 def test_add_twice(self):696 tag_name = 'group_name'697 val = 'test2'698 self.element.group_name('test')699 self.element.group_name(val)700 self.generic_element_test(tag_name, val)701class TestStyle(GenericTest):702 def test_add_elem_twice(self):703 self.element.style_group_box()704 self.generic_element_test('style', 0)705 def test_title_bar(self):706 self.element.style_title_bar()707 self.generic_element_test('style', 1)708 def test_line(self):709 self.element.style_line()710 self.generic_element_test('style', 2)711 def test_no_style(self):712 self.element.no_style()713 self.generic_element_test('style', 3)714class TestLabel(GenericTest):715 def test_label(self):716 tag_name = 'label'717 self.generic_element_test(tag_name, self.label)718class TestItemsFromPV(GenericTest):719 def test_on(self):720 tag_name = 'items_from_pv'721 self.element.items_from_pv(True)722 self.generic_element_test(tag_name, True)723 def test_off(self):724 tag_name = 'items_from_pv'725 self.element.items_from_pv(False)726 self.generic_element_test(tag_name, False)727class TestItems(GenericTest):728 def test_add_item(self):729 tag_name = 'items'730 val = 'Item Number Uno'731 self.element.item(val)732 self.child_element_test(tag_name, 'item', val, {})733class TestActions(GenericTest):734 def action_test(self, action_type, desc, action_args, macros=None):735 parent_element = self.element.find_element('actions')736 self.assertTrue(len(parent_element) > 0)737 for parent in parent_element:738 if parent.attrib == {'type': action_type}:739 description = parent.find('description')740 self.assertEqual(description.text, desc)741 for key, value in action_args.items():742 elem = parent.find(key)743 self.assertIsNotNone(elem)744 self.assertEqual(elem.text, value)745 if macros is not None:746 macro_parent = parent.find('macros')747 self.assertIsNotNone(macro_parent)748 for k, v in macros.items():749 mac = macro_parent.find(k)750 self.assertIsNotNone(mac)751 self.assertEqual(v, mac.text)752 def test_execute_as_one(self):753 tag_name = 'actions'754 self.element.action_execute_as_one(True)755 file = 'test.bob'756 target = 'TaB'757 self.element.action_open_display(file, target)758 self.child_element_test(tag_name, 'action', None, {'type': 'open_display'})759 def test_open_display(self):760 file = 'test.bob'761 target = 'TaB'762 self.element.action_open_display(file, target)763 self.action_test('open_display', 'Open Display', {'file': file, 'target': 'tab'})764 def test_open_display2(self):765 file = 'test.bob'766 target = 'winDow'767 self.element.action_open_display(file, target)768 self.action_test('open_display', 'Open Display', {'file': file, 'target': 'window'})769 def test_open_display3(self):770 file = 'test.bob'771 target = 'replace'772 self.element.action_open_display(file, target)773 self.action_test('open_display', 'Open Display', {'file': file, 'target': 'replace'})774 def test_open_display_desc(self):775 file = 'test.bob'776 target = 'replace'777 desc = "my description"778 self.element.action_open_display(file, target, desc)779 self.action_test('open_display', desc, {'file': file, 'target': 'replace'})780 def test_open_display_macros(self):781 file = 'test.bob'782 target = 'replace'783 macro_dict = { "TestMac": "1", "MOD": "Mod1"}784 self.element.action_open_display(file, target, macros=macro_dict)785 self.action_test('open_display', 'Open Display', {'file': file, 'target': 'replace'}, macro_dict)786 def test_open_display_macros_and_desc(self):787 file = 'test.bob'788 target = 'replace'789 desc = "test test test"790 self.element.action_open_display(file, target, desc, {"BPM": "BPMA"})791 self.action_test('open_display', desc, {'file': file, 'target': 'replace'}, {"BPM": "BPMA"})792 def test_write_pv(self):793 pv = 'TEST:PV'794 value = 235795 description = 'This is my action'796 self.element.action_write_pv(pv, value, description)797 self.action_test('write_pv', description, {'pv_name': pv, 'value': str(value), 'description': description})798 def test_execute_command(self):799 command = '/bin/bash /home/test.sh'800 description = 'test description'801 self.element.action_execute_command(command, description)802 self.action_test('command', description, {'command': command})803 def test_open_file(self):804 file_name = '/home/my-file.pdf'805 self.element.action_open_file(file_name)806 self.action_test('open_file', 'Open File', {'file': file_name})807 file = 'test.bob'808 target = 'replace'809 self.element.action_open_display(file, target)810 self.action_test('open_display', 'Open Display', {'file': file, 'target': 'replace'})811 def test_open_webpage(self):812 url = 'https://tynanford.com'813 self.element.action_open_webpage(url)814 self.action_test('open_webpage', 'Open Webpage', {'url': url})815class TestHorizontal(GenericTest):816 def test_default(self):817 tag_name = 'horizontal'818 self.element.horizontal(True)819 self.generic_element_test(tag_name, True)820 def test_off(self):821 tag_name = 'horizontal'822 self.element.horizontal(False)823 self.generic_element_test(tag_name, False)824class TestFillColor(GenericTest):825 def test_predefined_fill_color(self):826 tag_name = 'fill_color'827 self.element.predefined_fill_color(self.colors.INVALID)828 self.child_element_test(tag_name, 'color', None, {'name': 'INVALID', 'red': '255', 'green': '0',829 'blue': '255', 'alpha': '255'})830 def test_fill_color(self):831 tag_name = 'fill_color'832 self.element.fill_color(5, 10, 15, 12)833 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',834 'blue': '15', 'alpha': '12'})835class TestLimitsFromPV(GenericTest):836 def test_limits_off(self):837 tag_name = 'limits_from_pv'838 self.element.limits_from_pv(True)839 self.generic_element_test(tag_name, True)840 def test_limits_off2(self):841 tag_name = 'limits_from_pv'842 self.element.limits_from_pv(False)843 self.generic_element_test(tag_name, False)844 def test_limits_off3(self):845 tag_name = 'limits_from_pv'846 self.element.limits_from_pv(False)847 self.element.limits_from_pv(True)848 self.generic_element_test(tag_name, True)849 def test_limits_off4(self):850 tag_name = 'limits_from_pv'851 self.element.limits_from_pv('tsetsst')852 self.null_test(tag_name)853class TestMinMax(GenericTest):854 def test_min_float(self):855 tag_name = 'minimum'856 val = 2.5857 self.element.minimum(val)858 self.generic_element_test(tag_name, val)859 def test_min_string(self):860 tag_name = 'minimum'861 self.element.minimum('asfdsf')862 self.null_test(tag_name)863 def test_max_float(self):864 tag_name = 'maximum'865 val = -24.2866 self.element.maximum(val)867 self.generic_element_test(tag_name, val)868class TestEmptyColor(GenericTest):869 def test_predefined_empty_color(self):870 tag_name = 'empty_color'871 self.element.predefined_empty_color(self.colors.INVALID)872 self.child_element_test(tag_name, 'color', None, {'name': 'INVALID', 'red': '255', 'green': '0',873 'blue': '255', 'alpha': '255'})874 def test_empty_color(self):875 tag_name = 'empty_color'876 self.element.empty_color(5, 10, 15, 12)877 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',878 'blue': '15', 'alpha': '12'})879class TestScaleVisible(GenericTest):880 def test_scale_visible(self):881 tag_name = 'scale_visible'882 self.element.scale_visible('false')883 self.generic_element_test(tag_name, False)884class TestUrl(GenericTest):885 def test_url(self):886 tag_name = 'url'887 self.generic_element_test(tag_name, self.url)888 val = 'https://als.lbl.gov'889 self.element.url(val)890 self.generic_element_test(tag_name, val)891class TestShowToolbar(GenericTest):892 def test_show_toolbar(self):893 tag_name = 'show_toolbar'894 val = False895 self.element.show_toolbar(val)896 self.generic_element_test(tag_name, val)897 def test_show_toolbar_true(self):898 tag_name = 'show_toolbar'899 val = True900 self.element.show_toolbar(val)901 self.generic_element_test(tag_name, val)902 def test_show_toolbar_wrong(self):903 tag_name = 'show_toolbar'904 val = 'slkajfl'905 self.element.show_toolbar(val)906 self.null_test(tag_name)907 def test_show_toolbar_wrong_2(self):908 tag_name = 'show_toolbar'909 val = 'tRue'910 self.element.show_toolbar(val)911 self.generic_element_test(tag_name, True)912class TestButtonsOnLeft(GenericTest):913 def test_buttons_on_left(self):914 tag_name = 'buttons_on_left'915 val = 'fAlse'916 self.element.buttons_on_left(val)917 self.generic_element_test(tag_name, False)918 def test_buttons_on_left_true(self):919 tag_name = 'buttons_on_left'920 val = True921 self.element.buttons_on_left(val)922 self.generic_element_test(tag_name, val)923 def test_buttons_on_left_int(self):924 tag_name = 'buttons_on_left'925 val = 1926 self.element.buttons_on_left(val)927 self.generic_element_test(tag_name, True)928class TestIncrement(GenericTest):929 def test_increment(self):930 tag_name = 'increment'931 val = 12.2932 self.element.increment(val)933 self.generic_element_test(tag_name, val)934 def test_increment2(self):935 tag_name = 'increment'936 val = 2937 self.element.increment(val)938 self.generic_element_test(tag_name, val)939 def test_increment_wrong(self):940 tag_name = 'increment'941 val = 'testjlksj'942 self.element.increment(val)943 self.null_test(tag_name)944class TestFileComponent(GenericTest):945 def test_file_component(self):946 tag_name = 'component'947 self.element.file_component_full_path()948 self.generic_element_test(tag_name, 0)949 def test_component_directory(self):950 tag_name = 'component'951 self.element.file_component_directory()952 self.generic_element_test(tag_name, 1)953 def test_component_name_and_extension(self):954 tag_name = 'component'955 self.element.file_component_name_and_extension()956 self.generic_element_test(tag_name, 2)957 def test_component_base_name(self):958 tag_name = 'component'959 self.element.file_component_base_name()960 self.generic_element_test(tag_name, 3)961 def test_multiple_changes(self):962 tag_name = 'component'963 self.element.file_component_base_name()964 self.generic_element_test(tag_name, 3)965 self.element.file_component_full_path()966 self.generic_element_test(tag_name, 0)967class TestEditable(GenericTest):968 def test_editable_true(self):969 tag_name = 'editable'970 self.element.editable(True)971 self.generic_element_test(tag_name, True)972 def test_editable_false(self):973 tag_name = 'editable'974 self.element.editable('faLse')975 self.generic_element_test(tag_name, False)976class TestSelectedColor(GenericTest):977 def test_selected_color(self):978 tag_name = 'selected_color'979 self.element.predefined_selected_color(self.colors.OK)980 self.child_element_test(tag_name, 'color', None, {'name': 'OK', 'red': '0', 'green': '255',981 'blue': '0', 'alpha': '255'})982 def test_selected_color_2(self):983 tag_name = 'selected_color'984 self.element.selected_color(5, 10, 15, 232)985 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',986 'blue': '15', 'alpha': '232'})987 def test_selected_color_wrong(self):988 self.element.selected_color(-2, 10, 15, 232)989 self.null_test('color')990class TestDeselectedColor(GenericTest):991 def test_deselected_color(self):992 tag_name = 'deselected_color'993 self.element.predefined_deselected_color(self.colors.OK)994 self.child_element_test(tag_name, 'color', None, {'name': 'OK', 'red': '0', 'green': '255',995 'blue': '0', 'alpha': '255'})996 def test_deselected_color_2(self):997 tag_name = 'deselected_color'998 self.element.deselected_color(5, 10, 15, 232)999 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',1000 'blue': '15', 'alpha': '232'})1001 def test_deselected_color_wrong(self):1002 self.element.deselected_color(-2, 10, 15, 232)1003 self.null_test('color')1004class TestMode(GenericTest):1005 def test_toggle(self):1006 self.element.mode_toggle()1007 self.generic_element_test('mode', 0)1008 def test_push(self):1009 self.element.mode_push()1010 self.generic_element_test('mode', 1)1011 def test_push_inverted(self):1012 self.element.mode_push_inverted()1013 self.generic_element_test('mode', 2)1014 def test_twice(self):1015 self.element.mode_push_inverted()1016 self.generic_element_test('mode', 2)1017 self.element.mode_toggle()1018 self.generic_element_test('mode', 0)1019 self.element.mode_toggle()1020 self.element.remove_element('mode')1021 self.null_test('mode')1022class TestOffImage(TestOff):1023 def test_image_file(self):1024 tag_name = 'off_image'1025 val = './test/image.png'1026 self.element.off_image(val)1027 self.generic_element_test(tag_name, val)1028class TestOnImage(TestOn):1029 def test_image_file(self):1030 tag_name = 'on_image'1031 val = './test/image.png'1032 self.element.on_image(val)1033 self.generic_element_test(tag_name, val)1034class TestShowLED(GenericTest):1035 def test_show_led(self):1036 tag_name = 'show_led'1037 self.element.show_led(False)1038 self.generic_element_test(tag_name, False)1039class TestNeedleColor(GenericTest):1040 def test_predefined_needle_color(self):1041 tag_name = 'needle_color'1042 self.element.predefined_needle_color(self.colors.Write_Background)1043 self.child_element_test(tag_name, 'color', None, {'name': 'Write_Background', 'red': '128', 'green': '255',1044 'blue': '255', 'alpha': '255'})1045 def test_needle_color(self):1046 tag_name = 'needle_color'1047 self.element.needle_color(5, 10, 15, 12)1048 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',1049 'blue': '15', 'alpha': '12'})1050class TestKnobColor(GenericTest):1051 def test_predefined_knob_color(self):1052 tag_name = 'knob_color'1053 self.element.predefined_knob_color(self.colors.MINOR)1054 self.child_element_test(tag_name, 'color', None, {'name': 'MINOR', 'red': '255', 'green': '128',1055 'blue': '0', 'alpha': '255'})1056 def test_knob_color(self):1057 tag_name = 'knob_color'1058 self.element.knob_color(5, 0, 255)1059 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '0',1060 'blue': '255', 'alpha': '255'})1061 def test_knob_color_wrong(self):1062 self.element.knob_color('sdfsd', 0, 255)1063 self.null_test('color')1064class TestShowValue(GenericTest):1065 def test_show_value_false(self):1066 tag_name = 'show_value'1067 self.element.show_value(False)1068 self.generic_element_test(tag_name, False)1069class TestShowLimits(GenericTest):1070 def test_show_limits_true(self):1071 tag_name = 'show_limits'1072 self.element.show_limits(True)1073 self.generic_element_test(tag_name, True)1074 def test_show_limits_wrong(self):1075 tag_name = 'show_limits'1076 self.element.show_limits('atsddfj')1077 self.null_test(tag_name)1078class TestShowValueTip(GenericTest):1079 def test_show_value_tip_true(self):1080 tag_name = 'show_value_tip'1081 self.element.show_value_tip(True)1082 self.generic_element_test(tag_name, True)1083 def test_show_value_tip_false(self):1084 tag_name = 'show_value_tip'1085 self.element.show_value_tip(True)1086 self.element.show_value_tip(False)1087 self.generic_element_test(tag_name, False)1088class TestBarLength(GenericTest):1089 def test_bar_length(self):1090 tag_name = 'bar_length'1091 val = 2.51092 self.element.bar_length(val)1093 self.generic_element_test(tag_name, val)1094 def test_bar_length2(self):1095 tag_name = 'bar_length'1096 val = 1.01097 self.element.bar_length(val)1098 self.generic_element_test(tag_name, val)1099class TestSelectionValuePV(GenericTest):1100 def test_selection_value_pv(self):1101 tag_name = 'selection_value_pv'1102 val = '$(P):MY:COOL:PV'1103 self.element.selection_value_pv(val)1104 self.generic_element_test(tag_name, val)1105class TestPoints(GenericTest):1106 def test_points(self):1107 self.element.point(2, 5)1108 self.child_element_test('points', 'point', None, {'x': '2', 'y': '5'})1109 def test_points_wrong(self):1110 self.element.point('2', 5)1111 self.null_test('points')1112 def test_multiple_points(self):1113 self.element.point(2, 5)1114 self.child_element_test('points', 'point', None, {'x': '2', 'y': '5'}, True)1115 self.element.point(8, 9)1116 self.assertEqual(len(self.element.find_element('points').findall('point')), 2)1117class TestArrow(GenericTest):1118 def test_arrow_length(self):1119 tag_name = 'arrow_length'1120 val = 51121 self.element.arrow_length(val)1122 self.generic_element_test(tag_name, val)1123 def test_arrow_length_wrong(self):1124 tag_name = 'arrow_length'1125 val = 'asdfsdf'1126 self.element.arrow_length(val)1127 self.null_test(tag_name)1128 def test_arrows_from(self):1129 tag_name = 'arrows'1130 self.element.arrows_from()1131 self.generic_element_test(tag_name, 1)1132 def test_arrows_to(self):1133 tag_name = 'arrows'1134 self.element.arrows_to()1135 self.generic_element_test(tag_name, 2)1136 def test_arrows_both(self):1137 tag_name = 'arrows'1138 self.element.arrows_both()1139 self.generic_element_test(tag_name, 3)1140 def test_arrows_none(self):1141 tag_name = 'arrows'1142 self.element.arrows_none()1143 self.generic_element_test(tag_name, 0)1144class TestLineStyle(GenericTest):1145 def test_line_style_solid(self):1146 self.element.line_style_solid()1147 self.generic_element_test('line_style', 0)1148 def test_line_style_dashed(self):1149 self.element.line_style_dashed()1150 self.generic_element_test('line_style', 1)1151 def test_line_style_dot(self):1152 self.element.line_style_dot()1153 self.generic_element_test('line_style', 2)1154 def test_line_style_dash_dot(self):1155 self.element.line_style_dash_dot()1156 self.generic_element_test('line_style', 3)1157 def test_line_style_dash_dot_dot(self):1158 self.element.line_style_dash_dot_dot()1159 self.generic_element_test('line_style', 4)1160class TestActiveTab(GenericTest):1161 def test_active_tab(self):1162 tag_name = 'active_tab'1163 val = 41164 self.element.active_tab(val)1165 self.generic_element_test(tag_name, val)1166 def test_tab_wrong(self):1167 tag_name = 'active_tab'1168 val = 'tab1TryString'1169 self.element.active_tab(val)1170 self.null_test(tag_name)1171class TestTabHeight(GenericTest):1172 def test_tab_height(self):1173 tag_name = 'tab_height'1174 val = 231175 self.element.tab_height(val)1176 self.generic_element_test(tag_name, val)1177 def test_tab_wrong(self):1178 tag_name = 'tab_height'1179 val = 'lkasjdfls'1180 self.element.tab_height(val)1181 self.null_test(tag_name)1182class TestDirection(GenericTest):1183 def test_horizontal(self):1184 self.element.tab_direction_horizontal()1185 self.generic_element_test('direction', 0)1186 def test_vertical(self):1187 self.element.tab_direction_vertical()1188 self.generic_element_test('direction', 1)1189 def test_both(self):1190 self.element.tab_direction_vertical()1191 self.generic_element_test('direction', 1)1192 self.element.tab_direction_horizontal()1193 self.generic_element_test('direction', 0)1194class TestStartBit(GenericTest):1195 def test_start_bits(self):1196 tag_name = 'startBit'1197 val = 21198 self.element.start_bit(val)1199 self.generic_element_test(tag_name, val)1200class TestNumBits(GenericTest):1201 def test_num_bits(self):1202 tag_name = 'numBits'1203 val = 321204 self.element.num_bits(val)1205 self.generic_element_test(tag_name, val)1206class TestReverseBits(GenericTest):1207 def test_reverse_bits_default(self):1208 tag_name = 'bitReverse'1209 self.element.reverse_bits()1210 self.generic_element_test(tag_name, True)1211 def test_reverse_bits_false(self):1212 tag_name = 'bitReverse'1213 self.element.reverse_bits(False)1214 self.generic_element_test(tag_name, False)1215 def test_reverse_bits_true(self):1216 tag_name = 'bitReverse'1217 self.element.reverse_bits(True)1218 self.generic_element_test(tag_name, True)1219 def test_reverse_wrong(self):1220 tag_name = 'bitReverse'1221 self.element.reverse_bits('tets')1222 self.null_test(tag_name)1223class TestTabWidth(GenericTest):1224 def test_tab_width(self):1225 tag_name = 'tab_width'1226 val = 235.51227 self.element.tab_width(val)1228 self.generic_element_test(tag_name, int(val))1229 def test_tab_width_wrong(self):1230 tag_name = 'tab_width'1231 val = 'lkasjdfls'1232 self.element.tab_width(val)1233 self.null_test(tag_name)1234class TestTabSpacing(GenericTest):1235 def test_tab_spacing(self):1236 tag_name = 'tab_spacing'1237 val = 2.51238 self.element.tab_spacing(val)1239 self.generic_element_test(tag_name, int(val))1240 def test_tab_spacing_2(self):1241 tag_name = 'tab_spacing'1242 val = 231243 self.element.tab_spacing(val)1244 self.generic_element_test(tag_name, val)1245class TestLabels(GenericTest):1246 def test_label_single_string(self):1247 label_name = "testLabel1"1248 self.element.labels(label_name)1249 self.child_element_test('labels', 'text', label_name, {})1250 def test_label_list(self):1251 label_names = ["testLabel1", "label2", "label5"]1252 self.element.labels(label_names)1253 self.assertEqual(len(self.element.find_element('labels').findall('text')), len(label_names))1254class TestArrayIndex(GenericTest):1255 def test_array_index(self):1256 tag_name = 'array_index'1257 val = 21258 self.element.array_index(val)1259 self.generic_element_test(tag_name, val)1260class TestSymbols(GenericTest):1261 def test_symbols_single_string(self):1262 label_name = "testLabel1"1263 self.element.symbols(label_name)1264 self.child_element_test('symbols', 'symbol', label_name, {})1265 def test_symbols_list(self):1266 label_names = ["testLabel1", "file:/test.png", "label5"]1267 self.element.symbols(label_names)1268 self.assertEqual(len(self.element.find_element('symbols').findall('symbol')), len(label_names))1269class TestInitialIndex(GenericTest):1270 def test_initial_index_index(self):1271 tag_name = 'initial_index'1272 val = 21273 self.element.initial_index(val)1274 self.generic_element_test(tag_name, val)1275class TestShowIndex(GenericTest):1276 def test_show_index_default(self):1277 tag_name = 'show_index'1278 self.element.show_index()1279 self.generic_element_test(tag_name, True)1280 def test_show_index_false(self):1281 tag_name = 'show_index'1282 self.element.show_index(False)1283 self.generic_element_test(tag_name, False)1284 def test_show_index_true(self):1285 tag_name = 'show_index'1286 self.element.show_index(True)1287 self.generic_element_test(tag_name, True)1288 def test_show_index_wrong(self):1289 tag_name = 'show_index'1290 self.element.show_index('tets')1291 self.null_test(tag_name)1292class TestPreserveRatio(GenericTest):1293 def test_preserve_ratio_default(self):1294 tag_name = 'preserve_ratio'1295 self.element.preserve_ratio()1296 self.generic_element_test(tag_name, True)1297 def test_preserve_ratio_false(self):1298 tag_name = 'preserve_ratio'1299 self.element.preserve_ratio(False)1300 self.generic_element_test(tag_name, False)1301 def test_preserve_ratio_true(self):1302 tag_name = 'preserve_ratio'1303 self.element.preserve_ratio(True)1304 self.generic_element_test(tag_name, True)1305 def test_preserve_ratio_wrong(self):1306 tag_name = 'preserve_ratio'1307 self.element.preserve_ratio('tets')1308 self.null_test(tag_name)1309class TestShowScale(GenericTest):1310 def test_show_scale_default(self):1311 tag_name = 'show_scale'1312 self.element.show_scale()1313 self.generic_element_test(tag_name, True)1314 def test_show_scale_false(self):1315 tag_name = 'show_scale'1316 self.element.show_scale(False)1317 self.generic_element_test(tag_name, False)1318 def test_show_scale_true(self):1319 tag_name = 'show_scale'1320 self.element.show_scale(True)1321 self.generic_element_test(tag_name, True)1322class TestShowMinorTicks(GenericTest):1323 def test_show_minor_ticks_default(self):1324 tag_name = 'show_minor_ticks'1325 self.element.show_minor_ticks()1326 self.generic_element_test(tag_name, True)1327 def test_show_minor_ticks_false(self):1328 tag_name = 'show_minor_ticks'1329 self.element.show_minor_ticks(False)1330 self.generic_element_test(tag_name, False)1331 def test_show_minor_ticks_true(self):1332 tag_name = 'show_minor_ticks'1333 self.element.show_minor_ticks(True)1334 self.generic_element_test(tag_name, True)1335class TestMajorTicksPixelDist(GenericTest):1336 def test_major_tick_step_hint(self):1337 tag_name = 'major_tick_step_hint'1338 val = 23521339 self.element.major_ticks_pixel_dist(val)1340 self.generic_element_test(tag_name, val)1341class TestScaleFormat(GenericTest):1342 def test_scale_format(self):1343 tag_name = 'scale_format'1344 val = "# .###"1345 self.element.scale_format(val)1346 self.generic_element_test(tag_name, val)1347class TestLevelsAndShow(GenericTest):1348 def test_level_hihi(self):1349 tag_name = 'level_hihi'1350 val = 200.231351 self.element.level_hihi(val)1352 self.generic_element_test(tag_name, val)1353 def test_level_hihi_int(self):1354 tag_name = 'level_hihi'1355 val = 2001356 self.element.level_hihi(val)1357 self.generic_element_test(tag_name, val)1358 def test_level_high(self):1359 tag_name = 'level_high'1360 val = 2.231361 self.element.level_high(val)1362 self.generic_element_test(tag_name, val)1363 def test_level_low(self):1364 tag_name = 'level_low'1365 val = 500.231366 self.element.level_low(val)1367 self.generic_element_test(tag_name, val)1368 def test_level_low_int(self):1369 tag_name = 'level_low'1370 val = 1001371 self.element.level_low(val)1372 self.generic_element_test(tag_name, val)1373 def test_show_hihi_default(self):1374 tag_name = 'show_hihi'1375 self.element.show_hihi()1376 self.generic_element_test(tag_name, True)1377 def test_show_high_default(self):1378 tag_name = 'show_high'1379 self.element.show_high()1380 self.generic_element_test(tag_name, True)1381 def test_show_low_default(self):1382 tag_name = 'show_low'1383 self.element.show_low()1384 self.generic_element_test(tag_name, True)1385 def test_show_lolo_default(self):1386 tag_name = 'show_lolo'1387 self.element.show_lolo()1388 self.generic_element_test(tag_name, True)1389 def test_show_hihi_true(self):1390 tag_name = 'show_hihi'1391 self.element.show_hihi(True)1392 self.generic_element_test(tag_name, True)1393 def test_show_high_true(self):1394 tag_name = 'show_high'1395 self.element.show_high(True)1396 self.generic_element_test(tag_name, True)1397 def test_show_low_true(self):1398 tag_name = 'show_low'1399 self.element.show_low(True)1400 self.generic_element_test(tag_name, True)1401 def test_show_lolo_true(self):1402 tag_name = 'show_lolo'1403 self.element.show_lolo(True)1404 self.generic_element_test(tag_name, True)1405 def test_show_hihi_false(self):1406 tag_name = 'show_hihi'1407 self.element.show_hihi(False)1408 self.generic_element_test(tag_name, False)1409 def test_show_high_false(self):1410 tag_name = 'show_high'1411 self.element.show_high(False)1412 self.generic_element_test(tag_name, False)1413 def test_show_low_false(self):1414 tag_name = 'show_low'1415 self.element.show_low(False)1416 self.generic_element_test(tag_name, False)1417 def test_show_lolo_false(self):1418 tag_name = 'show_lolo'1419 self.element.show_lolo(False)1420 self.generic_element_test(tag_name, False)1421class TestStates(GenericTest):1422 def test_state(self):1423 self.element.state(1, 'Test', 223, 242, 12)1424 self.element.state_predefined_color(0, 'INVALID STATE', self.colors.INVALID)1425 self.assertEqual(len(self.element.find_element('states').findall('state')), 2)1426class TestFallback(GenericTest):1427 def test_fallback_label(self):1428 tag_name = 'fallback_label'1429 val = 'MyLabel'1430 self.element.fallback_label(val)1431 self.generic_element_test(tag_name, val)1432 def test_predefined_fallback_color(self):1433 tag_name = 'fallback_color'1434 self.element.predefined_fallback_color(self.colors.Background)1435 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',1436 'blue': '255', 'alpha': '255'})1437 def test_fallback_color(self):1438 tag_name = 'fallback_color'1439 self.element.fallback_color(5, 10, 15)1440 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',1441 'blue': '15', 'alpha': '255'})1442class TestSelectRows(GenericTest):1443 def test_select_rows_default(self):1444 tag_name = 'row_selection_mode'1445 self.element.select_rows()1446 self.generic_element_test(tag_name, True)1447 def test_select_rows_false(self):1448 tag_name = 'row_selection_mode'1449 self.element.select_rows(False)1450 self.generic_element_test(tag_name, False)1451 def test_select_rows_true(self):1452 tag_name = 'row_selection_mode'1453 self.element.select_rows(True)1454 self.generic_element_test(tag_name, True)1455class TestSelectionPV(GenericTest):1456 def test_selection_pv(self):1457 tag_name = 'selection_pv'1458 val = "Selection:PV:Test"1459 self.element.selection_pv(val)1460 self.generic_element_test(tag_name, val)1461class TestColumns(GenericTest):1462 # add more testing!1463 def test_columns(self):1464 self.element.column("col1", 123, False, ["opt532", "option35"])1465 self.element.column("col2", 123, True, "optionStr")1466 self.assertEqual(len(self.element.find_element("columns").findall("column")), 2)1467class TestTabs(GenericTest):1468 pass1469class TestNavTabs(GenericTest):1470 def test_nav_tab(self):1471 self.element.tab("TabElement2", "./tab2.bob", "TabGroupName", {"MAC1": "MacV"})1472 self.assertIsNotNone(self.element.root.find("tabs"))1473 self.assertIsNotNone(self.element.root.find("tabs").find("tab"))1474 self.assertEqual(self.element.root.find("tabs").find("tab").find("name").text, "TabElement2")1475 self.assertEqual(self.element.root.find("tabs").find("tab").find("file").text, "./tab2.bob")1476 self.assertEqual(self.element.root.find("tabs").find("tab").find("group_name").text, "TabGroupName")1477 self.assertIsNotNone(self.element.root.find("tabs").find("tab").find("macros"))1478 self.assertEqual(self.element.root.find("tabs").find("tab").find("macros").find("MAC1").text, "MacV")1479 self.element.tab("TabElement", "./tab.bob", "TabGroupName")1480 self.assertEqual(len(self.element.root.find("tabs").findall("tab")), 2)1481class TestTitle(GenericTest):1482 def test_title(self):1483 tag_name = 'title'1484 val = "MyChart Title"1485 self.element.title(val)1486 self.generic_element_test(tag_name, val)1487class TestAutoScale(GenericTest):1488 def test_auto_scale_false(self):1489 tag_name = 'autoscale'1490 self.element.auto_scale(False)1491 self.generic_element_test(tag_name, False)1492 def test_auto_scale_true(self):1493 tag_name = 'autoscale'1494 self.element.auto_scale(True)1495 self.generic_element_test(tag_name, True)1496class TestDataHeightAndWidth(GenericTest):1497 def test_data_height(self):1498 tag_name = 'data_height'1499 val = 231500 self.element.data_height(val)1501 self.generic_element_test(tag_name, val)1502 def test_data_width(self):1503 tag_name = 'data_width'1504 val = 9641505 self.element.data_width(val)1506 self.generic_element_test(tag_name, val)1507class TestLogScale(GenericTest):1508 def test_log_scale_default(self):1509 tag_name = 'log_scale'1510 self.element.log_scale()1511 self.generic_element_test(tag_name, True)1512 def test_log_scale_false(self):1513 tag_name = 'log_scale'1514 self.element.log_scale(False)1515 self.generic_element_test(tag_name, False)1516 def test_log_scale_true(self):1517 tag_name = 'log_scale'1518 self.element.log_scale(True)1519 self.generic_element_test(tag_name, True)1520class TestUnsignedData(GenericTest):1521 def test_unsigned_default(self):1522 tag_name = 'unsigned'1523 self.element.unsigned_data()1524 self.generic_element_test(tag_name, True)1525 def test_unsigned_false(self):1526 tag_name = 'unsigned'1527 self.element.unsigned_data(False)1528 self.generic_element_test(tag_name, False)1529 def test_unsigned_true(self):1530 tag_name = 'unsigned'1531 self.element.unsigned_data(True)1532 self.generic_element_test(tag_name, True)1533class TestShowGrid(GenericTest):1534 def test_show_grid_default(self):1535 tag_name = 'show_grid'1536 self.element.show_grid()1537 self.generic_element_test(tag_name, True)1538 def test_show_grid_false(self):1539 tag_name = 'show_grid'1540 self.element.show_grid(False)1541 self.generic_element_test(tag_name, False)1542 def test_show_grid_true(self):1543 tag_name = 'show_grid'1544 self.element.show_grid(True)1545 self.generic_element_test(tag_name, True)1546class TestShowLegend(GenericTest):1547 def test_show_legend_default(self):1548 tag_name = 'show_legend'1549 self.element.show_legend()1550 self.generic_element_test(tag_name, True)1551 def test_show_legend_false(self):1552 tag_name = 'show_legend'1553 self.element.show_legend(False)1554 self.generic_element_test(tag_name, False)1555 def test_sshow_legend_true(self):1556 tag_name = 'show_legend'1557 self.element.show_legend(True)1558 self.generic_element_test(tag_name, True)1559class TestTimeRange(GenericTest):1560 def test_time_range(self):1561 tag_name = 'time_range'1562 val = "5 minutes"1563 self.element.time_range(val)1564 self.generic_element_test(tag_name, val)1565class TestGridColor(GenericTest):1566 def test_predefined_grid_color(self):1567 tag_name = 'grid_color'1568 self.element.predefined_grid_color(self.colors.Background)1569 self.child_element_test(tag_name, 'color', None, {'name': 'Background', 'red': '255', 'green': '255',1570 'blue': '255', 'alpha': '255'})1571 def test_grid_color(self):1572 tag_name = 'grid_color'1573 self.element.grid_color(5, 10, 15)1574 self.child_element_test(tag_name, 'color', None, {'red': '5', 'green': '10',1575 'blue': '15', 'alpha': '255'})1576class TestCursor(GenericTest):1577 def test_cursor_info_pv(self):1578 tag_name = 'cursor_info_pv'1579 val = "Cursor:INFO:PV:Test"1580 self.element.cursor_info_pv(val)1581 self.generic_element_test(tag_name, val)1582 def test_cursor_x_pv(self):1583 tag_name = 'x_pv'1584 val = "Cursor:X:PV:Test"1585 self.element.cursor_x_pv(val)1586 self.generic_element_test(tag_name, val)1587 def test_cursor_y_pv(self):1588 tag_name = 'y_pv'1589 val = "Cursor:Y:PV:Test"1590 self.element.cursor_y_pv(val)1591 self.generic_element_test(tag_name, val)1592 def test_cursor_crosshair_default(self):1593 tag_name = 'cursor_crosshair'1594 default_val = True1595 self.element.cursor_crosshair()1596 self.generic_element_test(tag_name, default_val)1597 def test_cursor_crosshair_on(self):1598 tag_name = 'cursor_crosshair'1599 val = True1600 self.element.cursor_crosshair(val)1601 self.generic_element_test(tag_name, val)1602 def test_cursor_crosshair_off(self):1603 tag_name = 'cursor_crosshair'1604 val = False1605 self.element.cursor_crosshair(val)1606 self.generic_element_test(tag_name, val)1607class TestInterpolation(GenericTest):1608 def test_interpolation_none(self):1609 self.element.interpolation_none()1610 self.generic_element_test('interpolation', 0)1611 def test_interpolation_interpolate(self):1612 self.element.interpolation_interpolate()1613 self.generic_element_test('interpolation', 1)1614 def test_interpolation_automatic(self):1615 self.element.interpolation_automatic()1616 self.generic_element_test('interpolation', 2)1617 def test_interpolation_twice(self):1618 self.element.interpolation_none()1619 self.generic_element_test('interpolation', 0)1620 self.element.interpolation_interpolate()1621 self.generic_element_test('interpolation', 1)1622 self.element.interpolation_automatic()1623 self.element.remove_element('interpolation')...
TestDOMMethods.py
Source:TestDOMMethods.py
1import unittest2from DOM import XmlMaker3class TestXmlMakerMethods(unittest.TestCase):4 attribute_regex = r"(\s\w+=\".*\")"5 def test_renderSingleTag(self):6 tag_name = "table"7 xml = XmlMaker(tag_name)8 expected_xml = r"<{tag_name}></{tag_name}>".format(tag_name=tag_name)9 self.assertEqual(xml.__str__(), expected_xml);10 def test_renderTagWithSingleAttributes(self):11 tag_name = "element"12 attribute = "id"13 value = "test"14 xml = XmlMaker(tag_name).addAttribute(attribute, value)15 expected_xml = r'<{tag_name} {attribute}="{value}"></{tag_name}>'.format(tag_name=tag_name,16 attribute=attribute,17 value=value)18 self.assertEqual(xml.__str__(), expected_xml)19 def test_renderTagWithMultipleAttributes(self):20 tag_name = "element"21 attributes = {"id" : "test",22 "name": "some_element"}23 xml = XmlMaker(tag_name)24 for attribute, value in attributes.items():25 xml.addAttribute(attribute, value)26 for attribute, value in attributes.items():27 expected_xml = r"<{tag_name}{attribute_regex}* {attribute}=\"{value}\"{attribute_regex}*></{tag_name}>".format(tag_name=tag_name,28 attribute=attribute,29 value=value,30 attribute_regex=self.attribute_regex)31 self.assertRegex(xml.__str__(), expected_xml)32 def test_renderTagWithSingleAttributeAssignedMultipleTimes(self):33 tag_name = "form"34 attribute = "class"35 values = ["class_name", "default_class"]36 xml = XmlMaker(tag_name)37 for value in values:38 xml.addAttribute(attribute, value)39 for value in values:40 expected_xml = r'<{tag_name} {attribute}="(\w+ )?{value}( \w+)?"></{tag_name}>'.format(tag_name=tag_name,41 attribute=attribute,42 value=value)43 self.assertRegex(xml.__str__(), expected_xml)44 def test_overwritingAnAttribute(self):45 tag_name = "book"46 attribute = "genre"47 initial_value = "fantasy"48 overwrite_value = "sci-fi"49 xml = XmlMaker(tag_name).addAttribute(attribute, initial_value).setAttribute(attribute, overwrite_value)50 expected_xml = r'<{tag_name} {attribute}="{value}"></{tag_name}>'.format(tag_name=tag_name,51 attribute=attribute,52 value=overwrite_value)53 self.assertEqual(xml.__str__(), expected_xml)54 def test_renderTagWithChildren(self):55 parent_tag = "table"56 child_tag = "tr"57 xml = XmlMaker(parent_tag).addChild(XmlMaker(child_tag))58 expected_xml = r"<{parent_tag}><{child_tag}></{child_tag}></{parent_tag}>".format(parent_tag=parent_tag,59 child_tag=child_tag)60 self.assertEqual(xml.__str__(), expected_xml)61 def test_renderTagWithContent(self):62 tag_name = "speech"63 content = "I have a dream"64 xml = XmlMaker(tag_name).addContent(content)65 expected_xml = r"<{tag_name}>{content}</{tag_name}>".format(tag_name=tag_name,66 content=content)67 self.assertEqual(xml.__str__(), expected_xml)68 def test_manualSortOrders(self):69 parent_tag = "books"70 child_tag = "author"71 child_content = "Robert Heinlen"72 content_before_child = "hope"73 content_after_child = "test"74 xml = XmlMaker(parent_tag)75 xml.sort_order_iterator = 100076 xml.addContent(content_after_child)77 xml.addChild(XmlMaker(child_tag).addContent(child_content), 500)78 xml.addContent(content_before_child, 250)79 expected_xml = r"<{parent_tag}>{first_content}<{child_tag}>{child_content}</{child_tag}>{second_content}</{parent_tag}>".format(parent_tag=parent_tag,80 child_tag=child_tag,81 child_content=child_content,82 first_content=content_before_child,83 second_content=content_after_child)84 self.assertEqual(xml.__str__(), expected_xml)85if __name__ == "__main__":...
test_sanitizer.py
Source:test_sanitizer.py
1from __future__ import absolute_import, division, unicode_literals2try:3 import json4except ImportError:5 import simplejson as json6from html5lib import html5parser, sanitizer, constants, treebuilders7def toxmlFactory():8 tree = treebuilders.getTreeBuilder("etree")9 def toxml(element):10 # encode/decode roundtrip required for Python 2.6 compatibility11 result_bytes = tree.implementation.tostring(element, encoding="utf-8")12 return result_bytes.decode("utf-8")13 return toxml14def runSanitizerTest(name, expected, input, toxml=None):15 if toxml is None:16 toxml = toxmlFactory()17 expected = ''.join([toxml(token) for token in html5parser.HTMLParser().18 parseFragment(expected)])19 expected = json.loads(json.dumps(expected))20 assert expected == sanitize_html(input)21def sanitize_html(stream, toxml=None):22 if toxml is None:23 toxml = toxmlFactory()24 return ''.join([toxml(token) for token in25 html5parser.HTMLParser(tokenizer=sanitizer.HTMLSanitizer).26 parseFragment(stream)])27def test_should_handle_astral_plane_characters():28 assert '<html:p xmlns:html="http://www.w3.org/1999/xhtml">\U0001d4b5 \U0001d538</html:p>' == sanitize_html("<p>𝒵 𝔸</p>")29def test_sanitizer():30 toxml = toxmlFactory()31 for tag_name in sanitizer.HTMLSanitizer.allowed_elements:32 if tag_name in ['caption', 'col', 'colgroup', 'optgroup', 'option', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr']:33 continue # TODO34 if tag_name != tag_name.lower():35 continue # TODO36 if tag_name == 'image':37 yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,38 "<img title=\"1\"/>foo <bad>bar</bad> baz",39 "<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),40 toxml)41 elif tag_name == 'br':42 yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,43 "<br title=\"1\"/>foo <bad>bar</bad> baz<br/>",44 "<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),45 toxml)46 elif tag_name in constants.voidElements:47 yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,48 "<%s title=\"1\"/>foo <bad>bar</bad> baz" % tag_name,49 "<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),50 toxml)51 else:52 yield (runSanitizerTest, "test_should_allow_%s_tag" % tag_name,53 "<%s title=\"1\">foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),54 "<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),55 toxml)56 for tag_name in sanitizer.HTMLSanitizer.allowed_elements:57 tag_name = tag_name.upper()58 yield (runSanitizerTest, "test_should_forbid_%s_tag" % tag_name,59 "<%s title=\"1\">foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),60 "<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name, tag_name),61 toxml)62 for attribute_name in sanitizer.HTMLSanitizer.allowed_attributes:63 if attribute_name != attribute_name.lower():64 continue # TODO65 if attribute_name == 'style':66 continue67 yield (runSanitizerTest, "test_should_allow_%s_attribute" % attribute_name,68 "<p %s=\"foo\">foo <bad>bar</bad> baz</p>" % attribute_name,69 "<p %s='foo'>foo <bad>bar</bad> baz</p>" % attribute_name,70 toxml)71 for attribute_name in sanitizer.HTMLSanitizer.allowed_attributes:72 attribute_name = attribute_name.upper()73 yield (runSanitizerTest, "test_should_forbid_%s_attribute" % attribute_name,74 "<p>foo <bad>bar</bad> baz</p>",75 "<p %s='display: none;'>foo <bad>bar</bad> baz</p>" % attribute_name,76 toxml)77 for protocol in sanitizer.HTMLSanitizer.allowed_protocols:78 yield (runSanitizerTest, "test_should_allow_%s_uris" % protocol,79 "<a href=\"%s\">foo</a>" % protocol,80 """<a href="%s">foo</a>""" % protocol,81 toxml)82 for protocol in sanitizer.HTMLSanitizer.allowed_protocols:83 yield (runSanitizerTest, "test_should_allow_uppercase_%s_uris" % protocol,84 "<a href=\"%s\">foo</a>" % protocol,85 """<a href="%s">foo</a>""" % protocol,...
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!!