def MakeRating(): """ """ position = position_cursor(6, 999) questionText = '\n'.join(get_current_range()) hasRow = questionText.find('<row') != -1 hasCol = questionText.find('<col') != -1 comment1D = "Please select one" comment2D = "Please select one for each row" if hasRow and hasCol: comment = comment2D else: comment = comment1D attrs = dict(type="rating", values="order", averages="cols", adim="rows") output = deciphervimclips.element_factory(get_current_range(), attrs=attrs, elType="radio", comment=comment) set_current_range(output) vim.current.window.cursor = position
def test_label_rgx(self): test_titles = ( 'Q1. SPAM', 'Q2: EGGS', '(Q3) HAM', 'Q3.1 BACON', 'Q4. Q4. Q4.' ) generated_elements = [] for title in test_titles: generated_elements.append(''.join(deciphervimclips.element_factory([title], 'radio', '', {}))) expected_titles = ( ('Q1', 'SPAM'), ('Q2', 'EGGS'), ('Q3', 'HAM'), ('Q3_1', 'BACON'), ('Q4', 'Q4. Q4.') ) mock_xml_strs = [] for label, title in expected_titles: mock_xml_strs.append( ELEMENT_TEMPLATE.format(type='radio', label=label, extra='', title=title, comment='', content='') ) for generated_xml_str, mock_xml_str in zip(generated_elements, mock_xml_strs): self.assertEqual(clean_xml(generated_xml_str), clean_xml(mock_xml_str))
def MakeSelect(): """ """ position = position_cursor(3, 999) questionText = '\n'.join(get_current_range()) hasRow = questionText.find('<row') != -1 hasCol = questionText.find('<col') != -1 comment1D = "Please select one" comment2D = "Please select one for each selection" if hasRow or hasCol: comment = comment2D else: comment = comment1D attrs = dict(optional=0) output = deciphervimclips.element_factory(get_current_range(), attrs=attrs, elType="select", comment=comment) set_current_range(output) vim.current.window.cursor = position
def MakeFloat(): """ """ position = position_cursor(4, 999) attrs = dict(size=3, optional=0) comment = "Please enter a number" output = deciphervimclips.element_factory(get_current_range(), elType="float", attrs=attrs, comment=comment) set_current_range(output) vim.current.window.cursor = position
def MakeTextarea(): """ """ position = position_cursor(3, 999) comment = "Please be as specific as possible" attrs = dict(optional=0) output = deciphervimclips.element_factory(get_current_range(), attrs=attrs, elType="textarea", comment=comment) set_current_range(output) vim.current.window.cursor = position
def MakeCheckbox(): """ """ position = position_cursor(3, 999) comment = "Please select all that apply" attrs = dict(atleast=1) element = deciphervimclips.element_factory(get_current_range(), attrs=attrs, elType="checkbox", comment=comment) element = deciphervimclips.exclusify(element) element = deciphervimclips.openify(element) set_current_range(element) vim.current.window.cursor = position
def test_element_factory(self): test_elements = ( (['Q1 SPAM'], 'radio', 'comment', {}), (['Q2 SPAM'], 'checkbox', '', {}), (['Q3 SPAM'], 'select', '', dict(optional='0')), (['Q1 HAM'], 'checkbox', 'SPAM', {'EGGS': 'MORNING!'}), (['Q2 EGG'], 'BACON', 'SPAM', dict(a=1, b=2, c=3)), (['Q3 Anything without spam?', '<row label="r1">Spam</row>'], 'spam', '', dict(a=1, b=2, c=3)), ) for args in test_elements: mock_element_str = clean_xml(self.create_mock(*args)) mock_element_xml = etree.fromstring('<root>{0}</root>'.format(mock_element_str)) generated_element_str = clean_xml(''.join(deciphervimclips.element_factory(*args))) generated_element_xml = etree.fromstring('<root>{0}</root>'.format(generated_element_str)) self.assertEqual(*map(etree.tostring, (mock_element_xml, generated_element_xml))) badElements = ( (['SPAM'], 'radio', 'EGGS', {}), # No label ) for args in badElements: self.assertRaises(Exception, deciphervimclips.element_factory, args)
def MakeRadio(): """ """ position = position_cursor(2, 999) questionText = '\n'.join(get_current_range()) hasRow = questionText.find('<row') != -1 hasCol = questionText.find('<col') != -1 comment1D = "Please select one" comment2D = "Please select one for each row" if hasRow and hasCol: comment = comment2D else: comment = comment1D element = deciphervimclips.element_factory(get_current_range(), elType="radio", comment=comment) element = deciphervimclips.openify(element) set_current_range(element) vim.current.window.cursor = position