def test_svg_icon_loads_icon(): def read_icon(name): return '<svg id="{}"></svg>'.format(name) result = ext.svg_icon(read_icon, "settings") assert result == Markup('<svg class="svg-icon" id="settings" />')
def test_svg_icon_sets_css_class(): def read_icon(name): return "<svg></svg>" result = ext.svg_icon(read_icon, "icon", css_class="fancy-icon") assert result == Markup('<svg class="svg-icon fancy-icon" />')
def test_svg_icon_sets_css_class(): def read_icon(name): return '<svg></svg>' result = ext.svg_icon(read_icon, 'icon', css_class='fancy-icon') assert result == Markup('<svg class="fancy-icon" />')
def test_svg_icon_sets_css_class(): def read_icon(name): return '<svg></svg>' result = ext.svg_icon(read_icon, 'icon', css_class='fancy-icon') assert result == Markup('<svg class="svg-icon fancy-icon" />')
def test_svg_icon_strips_default_xml_namespace(): def read_icon(name): return '<svg xmlns="http://www.w3.org/2000/svg"></svg>' assert (ext.svg_icon( read_icon, 'icon') == Markup('<svg xmlns="http://www.w3.org/2000/svg" />'))
def test_svg_icon_loads_icon(): def read_icon(name): return '<svg id="{}"></svg>'.format(name) result = ext.svg_icon(read_icon, 'settings') assert result == Markup('<svg id="settings" />')
def test_svg_icon_removes_title(): def read_icon(name): return '<svg xmlns="http://www.w3.org/2000/svg"><title>foo</title></svg>' assert (ext.svg_icon( read_icon, 'icon') == Markup('<svg xmlns="http://www.w3.org/2000/svg" />'))
def test_svg_icon_strips_default_xml_namespace(): def read_icon(name): return '<svg xmlns="http://www.w3.org/2000/svg"></svg>' assert ext.svg_icon(read_icon, "icon") == Markup( '<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" />' )
def test_svg_icon_removes_title(): def read_icon(name): return '<svg xmlns="http://www.w3.org/2000/svg"><title>foo</title></svg>' assert ext.svg_icon(read_icon, "icon") == Markup( '<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" />' )
def test_svg_icon_loads_icon(): def read_icon(name): return '<svg id="{}"></svg>'.format(name) result = ext.svg_icon(read_icon, "settings") # nb. The order of attributes can differ depending on the Python version. # In Python 3.9+ the `id` attribute is first. assert result in [ Markup('<svg class="svg-icon" id="settings" />'), Markup('<svg id="settings" class="svg-icon" />'), ]
def test_it_removes_title(self, icon_file): icon_file.write( '<svg xmlns="http://www.w3.org/2000/svg"><title>foo</title></svg>') assert svg_icon("test_icon_name") == Markup( '<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" />')
def test_it_sets_css_class(self, icon_file, css_class, expected): icon_file.write("<svg></svg>") result = svg_icon("test_icon_name", css_class=css_class) assert result == Markup(f'<svg class="{expected}" />')
def test_it_strips_default_xml_namespace(self, icon_file): icon_file.write('<svg xmlns="http://www.w3.org/2000/svg"></svg>') assert svg_icon("test_icon_name") == Markup( '<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" />')