File: test_scope_parser_intermediate_representations.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (60 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from globus_sdk.scopes._graph_parser import ScopeGraph


def test_graph_str_single_node():
    g = ScopeGraph.parse("foo")
    clean_str = _blank_lines_removed(str(g))
    assert (
        clean_str
        == """\
digraph scopes {
  rankdir="LR";
  foo
}"""
    )


def test_graph_str_single_optional_node():
    g = ScopeGraph.parse("*foo")
    clean_str = _blank_lines_removed(str(g))
    assert (
        clean_str
        == """\
digraph scopes {
  rankdir="LR";
  *foo
}"""
    )


def test_graph_str_single_dependency():
    g = ScopeGraph.parse("foo[bar]")
    clean_str = _blank_lines_removed(str(g))
    assert (
        clean_str
        == """\
digraph scopes {
  rankdir="LR";
  foo
  foo -> bar;
}"""
    )


def test_graph_str_optional_dependency():
    g = ScopeGraph.parse("foo[bar[*baz]]")
    clean_str = _blank_lines_removed(str(g))
    assert (
        clean_str
        == """\
digraph scopes {
  rankdir="LR";
  foo
  foo -> bar;
  bar -> baz [ label = "optional" ];
}"""
    )


def _blank_lines_removed(s: str) -> str:
    return "\n".join(line for line in s.split("\n") if line.strip() != "")