diff --git a/tests/helper.py b/tests/helper.py index debd2c6..3e943a3 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -20,14 +20,6 @@ def assert_raises(exccls, msg): eq_(str(exc), msg) -def eq_str(value, expected): - """Python 2.x and 3.x compatible string compare.""" - if six.PY2: - eq_(value.decode("utf-8"), expected) - else: - eq_(value, expected) - - def with_setup(setup=None, teardown=None): def decorate(func, setup=setup, teardown=teardown): if setup: diff --git a/tests/test_dictimporter.py b/tests/test_dictimporter.py index 8ed60fe..e8c886c 100644 --- a/tests/test_dictimporter.py +++ b/tests/test_dictimporter.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from copy import deepcopy -from helper import eq_, eq_str +from helper import eq_ from anytree import Node, RenderTree from anytree.exporter import DictExporter @@ -27,20 +27,17 @@ def test_dict_importer(): eq_(data, refdata) eq_(exporter.export(root), data) r = RenderTree(root) - expected = "\n".join( - [ - "AnyNode(id='root')", - "├── AnyNode(id='sub0')", - "│ ├── AnyNode(id='sub0B')", - "│ └── AnyNode(id='sub0A')", - "└── AnyNode(id='sub1')", - " ├── AnyNode(id='sub1A')", - " ├── AnyNode(id='sub1B')", - " └── AnyNode(id='sub1C')", - " └── AnyNode(id='sub1Ca')", - ] - ) - eq_str(str(r), expected) + assert str(r).splitlines() == [ + "AnyNode(id='root')", + "├── AnyNode(id='sub0')", + "│ ├── AnyNode(id='sub0B')", + "│ └── AnyNode(id='sub0A')", + "└── AnyNode(id='sub1')", + " ├── AnyNode(id='sub1A')", + " ├── AnyNode(id='sub1B')", + " └── AnyNode(id='sub1C')", + " └── AnyNode(id='sub1Ca')", + ] def test_dict_importer_node(): @@ -66,17 +63,14 @@ def test_dict_importer_node(): eq_(data, refdata) eq_(exporter.export(root), data) r = RenderTree(root) - expected = "\n".join( - [ - "Node('/root')", - "├── Node('/root/sub0')", - "│ ├── Node('/root/sub0/sub0B')", - "│ └── Node('/root/sub0/sub0A')", - "└── Node('/root/sub1')", - " ├── Node('/root/sub1/sub1A')", - " ├── Node('/root/sub1/sub1B')", - " └── Node('/root/sub1/sub1C')", - " └── Node('/root/sub1/sub1C/sub1Ca')", - ] - ) - eq_str(str(r), expected) + assert str(r).splitlines() == [ + "Node('/root')", + "├── Node('/root/sub0')", + "│ ├── Node('/root/sub0/sub0B')", + "│ └── Node('/root/sub0/sub0A')", + "└── Node('/root/sub1')", + " ├── Node('/root/sub1/sub1A')", + " ├── Node('/root/sub1/sub1B')", + " └── Node('/root/sub1/sub1C')", + " └── Node('/root/sub1/sub1C/sub1Ca')", + ] diff --git a/tests/test_node_sep.py b/tests/test_node_sep.py index 4d71f67..5458587 100644 --- a/tests/test_node_sep.py +++ b/tests/test_node_sep.py @@ -21,19 +21,13 @@ def test_render(): MyNode("sub1", parent=root) r = at.RenderTree(root) - expected = "\n".join( - [ - "MyNode('|root')", - "├── MyNode('|root|sub0')", - "│ ├── MyNode('|root|sub0|sub0B')", - "│ └── MyNode('|root|sub0|sub0A')", - "└── MyNode('|root|sub1')", - ] - ) - if six.PY2: - eq_(str(r).decode("utf-8"), expected) - else: - eq_(str(r), expected) + assert str(r).splitlines() == [ + "MyNode('|root')", + "├── MyNode('|root|sub0')", + "│ ├── MyNode('|root|sub0|sub0B')", + "│ └── MyNode('|root|sub0|sub0A')", + "└── MyNode('|root|sub1')", + ] def test_get(): diff --git a/tests/test_render.py b/tests/test_render.py index 9480d1e..6a43f74 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -1,7 +1,4 @@ # -*- coding: utf-8 -*- -import six -from helper import eq_, eq_str - import anytree @@ -12,29 +9,22 @@ def test_render_str(): anytree.Node("sub0B", parent=s0) anytree.Node("sub0A", parent=s0) anytree.Node("sub1", parent=root) - r = anytree.RenderTree(root) - expected = "\n".join( - [ - "Node('/root')", - "├── Node('/root/sub0')", - "│ ├── Node('/root/sub0/sub0B')", - "│ └── Node('/root/sub0/sub0A')", - "└── Node('/root/sub1')", - ] - ) - eq_str(str(r), expected) + r = anytree.RenderTree(root) + assert str(r).splitlines() == [ + "Node('/root')", + "├── Node('/root/sub0')", + "│ ├── Node('/root/sub0/sub0B')", + "│ └── Node('/root/sub0/sub0A')", + "└── Node('/root/sub1')", + ] r = anytree.RenderTree(root, childiter=lambda nodes: [n for n in nodes if len(n.name) < 5]) - - expected = "\n".join( - [ - "Node('/root')", - "├── Node('/root/sub0')", - "└── Node('/root/sub1')", - ] - ) - eq_str(str(r), expected) + assert str(r).splitlines() == [ + "Node('/root')", + "├── Node('/root/sub0')", + "└── Node('/root/sub1')", + ] def test_render_repr(): @@ -43,11 +33,7 @@ def test_render_repr(): anytree.Node("sub", parent=root) r = anytree.RenderTree(root) - if six.PY2: - expected = "RenderTree(Node('/root'), style=ContStyle(), " "childiter=)" - else: - expected = "RenderTree(Node('/root'), style=ContStyle(), " "childiter=)" - eq_(repr(r), expected) + assert repr(r) == "RenderTree(Node('/root'), style=ContStyle(), " "childiter=)" def test_render(): @@ -60,14 +46,13 @@ def test_render(): r = anytree.RenderTree(root, style=anytree.DoubleStyle) result = [(pre, node) for pre, _, node in r] - expected = [ + assert result == [ ("", root), ("╠══ ", s0), ("║ ╠══ ", s0b), ("║ ╚══ ", s0a), ("╚══ ", s1), ] - eq_(result, expected) def multi(root): for pre, fill, node in anytree.RenderTree(root): @@ -75,8 +60,7 @@ def multi(root): for line in node.lines[1:]: yield "%s%s" % (fill, line), node - result = list(multi(root)) - expected = [ + assert list(multi(root)) == [ ("c0fe", root), ("c0de", root), ("├── ha", s0), @@ -88,7 +72,6 @@ def multi(root): ("│ b", s0a), ("└── Z", s1), ] - eq_(result, expected) def test_maxlevel(): @@ -100,42 +83,39 @@ def test_maxlevel(): r = anytree.RenderTree(root, maxlevel=2) result = [(pre, node) for pre, _, node in r] - expected = [ + assert result == [ ("", root), ("├── ", s0), ("└── ", s1), ] - print(expected) - print(result) - eq_(result, expected) def test_asciistyle(): style = anytree.AsciiStyle() - eq_(style.vertical, "| ") - eq_(style.cont, "|-- ") - eq_(style.end, "+-- ") + assert style.vertical == "| " + assert style.cont == "|-- " + assert style.end == "+-- " def test_contstyle(): style = anytree.ContStyle() - eq_(style.vertical, "\u2502 ") - eq_(style.cont, "\u251c\u2500\u2500 ") - eq_(style.end, "\u2514\u2500\u2500 ") + assert style.vertical == "\u2502 " + assert style.cont == "\u251c\u2500\u2500 " + assert style.end == "\u2514\u2500\u2500 " def test_controundstyle(): style = anytree.ContRoundStyle() - eq_(style.vertical, "\u2502 ") - eq_(style.cont, "\u251c\u2500\u2500 ") - eq_(style.end, "\u2570\u2500\u2500 ") + assert style.vertical == "\u2502 " + assert style.cont == "\u251c\u2500\u2500 " + assert style.end == "\u2570\u2500\u2500 " def test_doublestyle(): style = anytree.DoubleStyle() - eq_(style.vertical, "\u2551 ") - eq_(style.cont, "\u2560\u2550\u2550 ") - eq_(style.end, "\u255a\u2550\u2550 ") + assert style.vertical == "\u2551 " + assert style.cont == "\u2560\u2550\u2550 " + assert style.end == "\u255a\u2550\u2550 " def test_by_attr(): @@ -145,9 +125,27 @@ def test_by_attr(): anytree.Node("sub0B", parent=s0, lines=["sub", "0B"]) anytree.Node("sub0A", parent=s0) anytree.Node("sub1", parent=root, lines=["sub1"]) - eq_(anytree.RenderTree(root).by_attr(), "root\n├── sub0\n│ ├── sub0B\n│ └── sub0A\n└── sub1") - eq_(anytree.RenderTree(root).by_attr("lines"), "root\n├── su\n│ b0\n│ ├── sub\n│ │ 0B\n│ └── \n└── sub1") - eq_( - anytree.RenderTree(root).by_attr(lambda node: ":".join(node.name)), - "r:o:o:t\n├── s:u:b:0\n│ ├── s:u:b:0:B\n│ └── s:u:b:0:A\n└── s:u:b:1", - ) + + assert anytree.RenderTree(root).by_attr().splitlines() == [ + "root", + "├── sub0", + "│ ├── sub0B", + "│ └── sub0A", + "└── sub1", + ] + assert anytree.RenderTree(root).by_attr("lines").splitlines() == [ + "root", + "├── su", + "│ b0", + "│ ├── sub", + "│ │ 0B", + "│ └── ", + "└── sub1", + ] + assert anytree.RenderTree(root).by_attr(lambda node: ":".join(node.name)).splitlines() == [ + "r:o:o:t", + "├── s:u:b:0", + "│ ├── s:u:b:0:B", + "│ └── s:u:b:0:A", + "└── s:u:b:1", + ]