def test_custom_class_ident_style_and_attrs(): assert ( str( Input("text", cl='abclass', ident='123', style="font-size:0.9em;", attrs={"data-test": 'abc'})) == "<input type=\"text\" id=\"123\" class=\"form-control abclass\" style=\"font-size:0.9em;\" data-test=\"abc\"></input>" )
def __init__(self, **kwargs): super().__init__(**kwargs) self.label_text = kwargs.get('label', '') self.initial = kwargs.get('initial', '') self.hidden = kwargs.get('hidden', True) self.input_type = kwargs.get('input_type', 'text') if self.hidden: cl = 'panel hidden' else: cl = 'panel' self.widget = Div(cl=cl, attrs=self.get_data_id_attr()) body = Div(cl='panel-body') grp = Div(cl='input-group') self.label_widget = Span( text=self.label_text, cl='input-group-addon', attrs=self.get_data_id_attr('label'), ) attrs = self.get_data_id_attr('input') attrs['value'] = self.initial self.input_widget = Input( inputtype=self.input_type, attrs=attrs, ) grp.addelement(self.label_widget) grp.addelement(self.input_widget) body.addelement(grp) btngrp = ButtonGroup() self.ok_btn = Button(text='Ok', cl='text-edit-btn', severity='primary', attrs=self.get_data_id_attr('ok')) self.cancel_btn = Button(text='Cancel', cl='text-edit-btn', attrs=self.get_data_id_attr('cancel')) btngrp.addelement(self.ok_btn) btngrp.addelement(self.cancel_btn) body.addelement(btngrp) self.widget.addelement(body) self.bind( label_text=self.on_label_text, initial=self.on_initial, hidden=self.on_hidden, ) self.app.register('load', self.on_app_load)
def test_help_text_with_id(): assert ( str(Input('text', ident='456', helptext="help me")) == "<input type=\"text\" id=\"456\" class=\"form-control\" aria-describedby=\"456-helpblock\"></input><span id=\"456-helpblock\" class=\"help-block\">help me</span>" )
def test_basic_text(): assert (str(Input('text')) == "<input type=\"text\" class=\"form-control\"></input>")
def test_size_small(): assert (str(Input('color', size="small")) == "<input type=\"color\" class=\"form-control input-sm\"></input>")
def test_size_large(): assert (str( Input('password', size="large") ) == "<input type=\"password\" class=\"form-control input-lg\"></input>")
def test_readonly_placeholder(): assert ( str(Input('email', readonly=True, placeholder="abc")) == "<input type=\"email\" class=\"form-control\" placeholder=\"abc\" readonly></input>" )
def test_inputtype_missing(): with pytest.raises(TypeError): Input()
def test_unknown_inputtype(): with pytest.raises(ValueError) as err: Input('abc') assert ('abc' in str(err.value))