forked from CESNET/libyang-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_diff.py
More file actions
83 lines (75 loc) · 3.49 KB
/
test_diff.py
File metadata and controls
83 lines (75 loc) · 3.49 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (c) 2019 Robin Jarry
# SPDX-License-Identifier: MIT
import os
import unittest
from libyang import (
BaseTypeAdded,
BaseTypeRemoved,
Context,
NodeTypeAdded,
NodeTypeRemoved,
SNodeAdded,
SNodeRemoved,
StatusAdded,
StatusRemoved,
schema_diff,
)
OLD_YANG_DIR = os.path.join(os.path.dirname(__file__), "yang-old")
NEW_YANG_DIR = os.path.join(os.path.dirname(__file__), "yang")
# -------------------------------------------------------------------------------------
class DiffTest(unittest.TestCase):
expected_diffs = frozenset(
(
(BaseTypeAdded, "/yolo-system:conf/yolo-system:speed"),
(BaseTypeAdded, "/yolo-system:state/yolo-system:speed"),
(BaseTypeRemoved, "/yolo-system:conf/yolo-system:speed"),
(BaseTypeRemoved, "/yolo-system:state/yolo-system:speed"),
(NodeTypeAdded, "/yolo-system:conf/yolo-system:number"),
(NodeTypeAdded, "/yolo-system:state/yolo-system:number"),
(NodeTypeRemoved, "/yolo-system:conf/yolo-system:number"),
(NodeTypeRemoved, "/yolo-system:state/yolo-system:number"),
(SNodeAdded, "/yolo-system:conf/yolo-system:hostname-ref"),
(SNodeAdded, "/yolo-system:conf/yolo-system:url/yolo-system:enabled"),
(SNodeAdded, "/yolo-system:conf/yolo-system:url/yolo-system:fetch"),
(
SNodeAdded,
"/yolo-system:conf/yolo-system:url/yolo-system:fetch/yolo-system:input/yolo-system:timeout",
),
(
SNodeAdded,
"/yolo-system:conf/yolo-system:url/yolo-system:fetch/yolo-system:output/yolo-system:result",
),
(SNodeAdded, "/yolo-system:state/yolo-system:hostname-ref"),
(SNodeAdded, "/yolo-system:state/yolo-system:url/yolo-system:enabled"),
(SNodeAdded, "/yolo-system:state/yolo-system:url/yolo-system:fetch"),
(
SNodeAdded,
"/yolo-system:state/yolo-system:url/yolo-system:fetch/yolo-system:input/yolo-system:timeout",
),
(
SNodeAdded,
"/yolo-system:state/yolo-system:url/yolo-system:fetch/yolo-system:output/yolo-system:result",
),
(StatusAdded, "/yolo-system:conf/yolo-system:deprecated-leaf"),
(StatusAdded, "/yolo-system:conf/yolo-system:obsolete-leaf"),
(StatusAdded, "/yolo-system:state/yolo-system:deprecated-leaf"),
(StatusAdded, "/yolo-system:state/yolo-system:obsolete-leaf"),
(StatusRemoved, "/yolo-system:conf/yolo-system:deprecated-leaf"),
(StatusRemoved, "/yolo-system:conf/yolo-system:obsolete-leaf"),
(StatusRemoved, "/yolo-system:state/yolo-system:deprecated-leaf"),
(StatusRemoved, "/yolo-system:state/yolo-system:obsolete-leaf"),
)
)
def test_diff(self):
with Context(OLD_YANG_DIR) as ctx_old, Context(NEW_YANG_DIR) as ctx_new:
mod = ctx_old.load_module("yolo-system")
mod.feature_enable_all()
mod = ctx_new.load_module("yolo-system")
mod.feature_enable_all()
diffs = []
for d in schema_diff(ctx_old, ctx_new):
if isinstance(d, (SNodeAdded, SNodeRemoved)):
diffs.append((d.__class__, d.node.schema_path()))
else:
diffs.append((d.__class__, d.new.schema_path()))
self.assertEqual(frozenset(diffs), self.expected_diffs)