def test_getitem(self): assert Container('x')['foo', 'bar', 'baz'].children == ['foo', 'bar', 'baz'] pytest.raises_str(TypeError, 'argument', lambda: Container['foo']) assert tags.p['foo'].children == ['foo'] assert tags.p[('foo', 'bar')] == tags.p['foo', 'bar'] assert tags.p['x', expr('y'), tags.hr, IO()].children == ['x', expr('y'), tags.hr, IO()] pytest.raises_str('unexpected child element: []', lambda: tags.p[[]])
def test_expr(self): pytest.raises_str('invalid expr: 1', expr, 1) pytest.raises_str("invalid expr: ''", expr, '') assert expr(expr('foo')) == expr('foo') assert str(expr('bar')) == 'bar' assert repr(expr('bar')) == "expr('bar')" assert expr('baz').code == 'baz' assert {expr('foo'): 1} == {expr('foo'): 1}
def test_input_overlap(self): with pytest.raises_str("overlapping inputs: ['j']"): tags.p[ Container('x', inputs=['a'])[ Tag('i', 'a', b={'foo': Tag('j', 'b')}), 'foo' ], Container('y', inputs=['j']) ] with pytest.raises_str("overlapping inputs: ['i']"): tags.p[IO, IO()]
def test_duplicate_attrs(self): pytest.raises_str('duplicate attribute: srcDoc', tags.p, srcDoc='foo', src_doc='foo') pytest.raises_str('duplicate attribute: className', tags.p, class_='foo', className='foo') pytest.raises_str('duplicate attribute: className', tags.p, class_name='foo', className='foo') pytest.raises_str('duplicate attribute: className', tags.p, class_='foo', class_name='foo')
def test_duplicate_styles(self): pytest.raises_str('duplicate style: navUp', tags.p, style={ 'nav-up': 'foo', 'navUp': 'foo' }) pytest.raises_str('duplicate style: navUp', tags.p, style={ 'nav_up': 'foo', 'navUp': 'foo' }) pytest.raises_str('duplicate style: navUp', tags.p, style={ 'nav-up': 'foo', 'nav_up': 'foo' })
def test_invalid_attribute(self): pytest.raises_str('unknown attribute: bar', tags.p, bar='foo') pytest.raises_str('unknown attribute: bar', tags.p['baz'], bar='foo') pytest.raises_str('invalid attribute: href=42', tags.p, href=42)
def test_invalid_style(self): pytest.raises_str('invalid style: []', tags.p, style=[]) pytest.raises_str('unknown style: foo', tags.p, style={'foo': 1}) pytest.raises_str('invalid style: zIndex=[]', tags.p, style={'z-index': []})
def test_allow_children(self): pytest.raises_str('not a container: Tag', lambda: Tag('i', 'a')['foo']) pytest.raises_str('not a container: hr', lambda: tags.hr['foo']) pytest.raises_str('not a container: hr', lambda: tags.hr(href='bar')['foo'])
def test_encode_invalid(self): pytest.raises_str('not JSON serializable', Container(object()).to_json) pytest.raises_str('not JSON serializable', Container(object()).to_dict)