def test_update_with_add(self): attrs = Hattrs('required', klass='class1', other='other1') attrs.add('class', 'class1', 'class2') attrs.add('other', 'other1', 'other2') self.assertEqual( str(attrs), 'class="class1 class2" other="other1 other2" required' )
def test_add_repeated_keys(self): attrs = Hattrs() attrs.add('class', 'class1')\ .add('class', 'class2')\ .add('class', 'class3')\ .add('other', 'other1', 'other2', 'other3') self.assertEquals( str(attrs), 'class="class1 class2 class3" other="other1 other2 other3"' )
def test_add_repeated_values(self): attrs = Hattrs() attrs.add('class', 'class1', 'class2', 'class3')\ .add('class', 'class2', 'class4')\ .add('class', 'class3', 'class4', 'class5')\ .add('class', 'class1','class2','class3','class4','class5') self.assertEqual( str(attrs), 'class="class1 class2 class3 class4 class5"' )
def test_add_simple(self): attrs = Hattrs() attrs\ .add('class', 'container', 'md-2')\ .add('required') self.assertEqual( str(attrs), 'class="container md-2" required' )
def htag(doc, tag, *args, **kwargs): position = len(doc.result) doc._append('') attributes = Hattrs(*args, **kwargs) yield attributes if not attributes._attrs: doc.result[position] = f'<{tag}>' else: doc.result[position] = f'<{tag} {attributes}>' doc._append(f'</{tag}>')
def test_update_with_add_required_overriding(self): attrs = Hattrs('required', klass='class1') attrs.add('required', 'req1') self.assertEqual(str(attrs), 'class="class1" required="req1"')
def test_update_with_add_required(self): attrs = Hattrs('required', klass='class1') attrs.add('required') self.assertEqual(str(attrs), 'class="class1" required')
def test_update_simple(self): attrs = Hattrs('required', klass='class1', other = 'other1') self.assertEqual( str(attrs), 'class="class1" other="other1" required' )