File: test_unicode.py

package info (click to toggle)
python-pygraphviz 1.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: ansic: 5,100; python: 2,669; makefile: 57
file content (41 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pygraphviz as pgv


def test_name_unicode():
    A = pgv.AGraph(name="unicode")
    assert A.name == "unicode"


def test_node_encoding():
    A = pgv.AGraph(encoding="UTF-8")
    hello = "Здравствуйте!"
    A.add_node(hello)
    n = A.get_node(hello)
    assert n.name == hello

    n.attr["goodbye"] = "До свидания"
    assert n.attr["goodbye"] == "До свидания"


def test_edge_encoding():
    A = pgv.AGraph(encoding="UTF-8")
    hello = "שלום"
    A.add_edge(hello, hello, key=1)  # self loop
    e = A.get_edge(hello, hello)
    assert e.name == "1"
    assert e == (hello, hello)

    e.attr["hello"] = hello
    assert e.attr["hello"] == hello


def test_from_string():
    # test unicode in from_string()
    t = "测试"
    G = pgv.AGraph()
    G.add_node(t)
    ug = str(G)
    sg = str(G)
    G1 = pgv.AGraph(ug)
    G2 = pgv.AGraph(sg)
    assert str(G1) == str(G2)