def test_width(self): style = Style() assert style.width() == Style.DEFAULT_STYLE["width"] style.set_width(10.1) assert style.width() == 10.1 assert_raises(ValueError, style.set_width, -1) assert_raises(ValueError, style.set_width, 0)
def test_shadow(self): style = Style() assert style.shadow() == Style.DEFAULT_STYLE['shadow'] style.set_shadow('off') assert style.shadow() == 'off' style.set_shadow('on') assert style.shadow() == 'on'
def test_target_type(self): style = Style() assert style.target_type() == '' style.set_target_type('line') assert style.target_type() == 'line' style.set_target_type('fill') assert style.target_type() == 'fill'
def test_merge(self): style1 = Style(option_list=['red', 'no-shadow', 3]) style2 = Style(option_list=['blue', 'dotted']) style1.merge(style2) assert style1.color() == [Style.COLORS['blue']] assert style1.fill_type() == 'dotted' assert style1.shadow() == 'off' assert style1.width() == 3
def test_color(self): style = Style() assert style.color() == Style.DEFAULT_STYLE["color"] style.add_color((0.1, 0.2, 0.3)) assert style.color() == [(0.1, 0.2, 0.3)] style = Style() style.add_color((0.1, 0.2, 0.3, 0.4)) assert style.color() == [(0.1, 0.2, 0.3, 0.4)] assert_raises(ValueError, style.add_color, (0.1, 0.2))
def test_target_type(self): style = Style() assert style.target_type() == "" style.set_target_type("line") assert style.target_type() == "line" style.set_target_type("fill") assert style.target_type() == "fill"
def test_shadow(self): style = Style() assert style.shadow() == Style.DEFAULT_STYLE["shadow"] style.set_shadow("off") assert style.shadow() == "off" style.set_shadow("on") assert style.shadow() == "on"
def test_cmp(self): style1 = Style('abc', 'line', ['red', 'no-shadow', 3]) style2 = Style('', '', []) assert style1 != style2 style2.set_name_pattern('abc') assert style1 != style2 style2.set_target_type('line') assert style1 != style2 style2.set_options(['red', 'no-shadow', 3]) assert style1 == style2 assert style1 != 1
def test_merge(self): style1 = Style(option_list=["red", "no-shadow", 3]) style2 = Style(option_list=["blue", "dotted"]) style1.merge(style2) assert style1.color() == [Style.COLORS["blue"]] assert style1.fill_type() == "dotted" assert style1.shadow() == "off" assert style1.width() == 3
def test_width(self): style = Style() assert style.width() == Style.DEFAULT_STYLE['width'] style.set_width(10.1) assert style.width() == 10.1 assert_raises(ValueError, style.set_width, -1) assert_raises(ValueError, style.set_width, 0)
def test_cmp(self): style1 = Style("abc", "line", ["red", "no-shadow", 3]) style2 = Style("", "", []) assert style1 != style2 style2.set_name_pattern("abc") assert style1 != style2 style2.set_target_type("line") assert style1 != style2 style2.set_options(["red", "no-shadow", 3]) assert style1 == style2 assert style1 != 1
def test_repr(self): assert str( Style('abc', 'fill', ['red', 'no-shadow', 3]) ) == "(name_pattern: abc, target_type:fill, options:{'color': [[1, 0, 0]], 'width': 3, 'shadow': 'off'}, prio:-1)", Style( 'abc', 'fill', ['red', 'no-shadow', 3])
def test_name_pattern(self): style = Style(name_pattern="(abc)|(def)") assert style.name_pattern() == "(abc)|(def)"
def test_init(self): style = Style() assert style != None style = Style(option_list=["red", "no-shadow", 3]) assert style.color() == [Style.COLORS["red"]] assert style.shadow() == "off" assert style.width() == 3 style = Style(option_list=["shadow", 3.2]) assert style.shadow() == "on" assert style.width() == 3.2 style = Style(option_list=["solid"]) assert style.fill_type() == "solid" style = Style(option_list=["dashed"]) assert style.fill_type() == "dashed" style = Style(option_list=["dash-dotted"]) assert style.fill_type() == "dash-dotted" style = Style(option_list=["dotted"]) assert style.fill_type() == "dotted"
def test_color(self): style = Style() assert style.color() == Style.DEFAULT_STYLE['color'] style.add_color((0.1, 0.2, 0.3)) assert style.color() == [(0.1, 0.2, 0.3)] style = Style() style.add_color((0.1, 0.2, 0.3, 0.4)) assert style.color() == [(0.1, 0.2, 0.3, 0.4)] assert_raises(ValueError, style.add_color, (0.1, 0.2))
def test_init(self): style = Style() assert style != None style = Style(option_list=['red', 'no-shadow', 3]) assert style.color() == [Style.COLORS['red']] assert style.shadow() == 'off' assert style.width() == 3 style = Style(option_list=['shadow', 3.2]) assert style.shadow() == 'on' assert style.width() == 3.2 style = Style(option_list=['solid']) assert style.fill_type() == 'solid' style = Style(option_list=['dashed']) assert style.fill_type() == 'dashed' style = Style(option_list=['dash-dotted']) assert style.fill_type() == 'dash-dotted' style = Style(option_list=['dotted']) assert style.fill_type() == 'dotted'
def test_run(self): parser = StyleParser() arrow_style = Style('_arrow_', 'fill', ['red'], 1) fill_style = Style('.*', 'fill', ['blue'], 0) line_style = Style('_line_', 'fill', ['green'], 2) frame_style = Style('.*', 'frame', [[0.1, 0.2, 0.3]], 0) custom_fill_style = Style('(abc)|(def)', 'fill', [[0.3, 0.2, 0.3]], 3) custom_line_style = Style('line', 'fill', [[0.4, 0.3, 0.3]], 3) custom_frame_style = Style('(abc)|(def)', 'frame', [[0.5, 0.2, 0.3]], 3) polygon1 = Polygon([Node(0, 0)]) opengraph1 = OpenGraph() opengraph2 = OpenGraph() opengraph2.add_name('line') arrow = Arrow() background = Background() polygon2 = Polygon([Node(0, 0)]) polygon2.add_name('abc') polygon3 = Polygon([Node(0, 0)]) polygon3.add_name('def') objects = [ arrow_style, fill_style, line_style, frame_style, custom_fill_style, custom_line_style, custom_frame_style, polygon1, polygon2, polygon3, opengraph1, opengraph2, arrow, background ] parser.run([], objects) assert arrow.style().color() == arrow_style.color(), str( arrow.style().color()) + " != " + str(arrow_style.color()) assert polygon1.style().color() == fill_style.color(), str( polygon1.style().color()) + " != " + str(fill_style.color()) assert polygon1.frame().style().color() == frame_style.color() assert opengraph1.style().color() == line_style.color() assert opengraph2.style().color() == custom_line_style.color() assert polygon2.style().color() == custom_fill_style.color() assert polygon3.style().color() == custom_fill_style.color() assert polygon2.frame().style().color() == custom_frame_style.color() assert polygon3.frame().style().color() == custom_frame_style.color()
def test_style(self): drawable = Drawable() style = Style(['abc', 'def', 'geh'], 'line', ['dotted', 'shadow']) drawable.set_style(style) assert drawable.style().options() == style.options()
def test_run(self): parser = StyleParser() arrow_style = Style('_arrow_', 'fill', ['red'], 1) fill_style = Style('.*', 'fill', ['blue'], 0) line_style = Style('_line_', 'fill', ['green'], 2) frame_style = Style('.*', 'frame', [[0.1, 0.2, 0.3]], 0) custom_fill_style = Style('(abc)|(def)', 'fill', [[0.3, 0.2, 0.3]], 3) custom_line_style = Style('line', 'fill', [[0.4, 0.3, 0.3]], 3) custom_frame_style = Style('(abc)|(def)', 'frame', [[0.5, 0.2, 0.3]], 3) polygon1 = Polygon([Node(0, 0)]) opengraph1 = OpenGraph() opengraph2 = OpenGraph() opengraph2.add_name('line') arrow = Arrow() background = Background() polygon2 = Polygon([Node(0, 0)]) polygon2.add_name('abc') polygon3 = Polygon([Node(0, 0)]) polygon3.add_name('def') objects = [arrow_style, fill_style, line_style, frame_style, custom_fill_style, custom_line_style, custom_frame_style, polygon1, polygon2, polygon3, opengraph1, opengraph2, arrow, background] parser.run([], objects) assert arrow.style().color() == arrow_style.color(), str(arrow.style().color()) + " != " + str(arrow_style.color()) assert polygon1.style().color() == fill_style.color(), str(polygon1.style().color()) + " != " + str(fill_style.color()) assert polygon1.frame().style().color() == frame_style.color() assert opengraph1.style().color() == line_style.color() assert opengraph2.style().color() == custom_line_style.color() assert polygon2.style().color() == custom_fill_style.color() assert polygon3.style().color() == custom_fill_style.color() assert polygon2.frame().style().color() == custom_frame_style.color() assert polygon3.frame().style().color() == custom_frame_style.color()