Skip to content

Commit 1b6cf9c

Browse files
jktjktclaude
andcommitted
tests: pass ly_yang_module_dir() explicitly where needed
Upstream libyang now unconditionally needs ietf-yang-semver and its deps, and they are not available as builtins in the library, one has to load them via the usual lookups from disk instead. Let's adapt our tests for this. Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 69548ed commit 1b6cf9c

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎cffi/cdefs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum {
4040
LY_ERR ly_ctx_new(const char *, uint16_t, struct ly_ctx **);
4141
void ly_ctx_destroy(struct ly_ctx *);
4242
int ly_ctx_set_searchdir(struct ly_ctx *, const char *);
43+
const char *ly_yang_module_dir(void);
4344

4445
typedef enum
4546
{

‎tests/test_context.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,34 @@
44
import os
55
import unittest
66

7+
from _libyang import lib
78
from libyang import Context, LibyangError, Module, SContainer, SLeaf, SLeafList
89
from libyang.util import c2str
910

1011

1112
YANG_DIR = os.path.join(os.path.dirname(__file__), "yang")
1213

14+
# Since libyang 6.3.0, ly_ctx_new() loads several core modules
15+
# (ietf-yang-semver and friends) that are no longer embedded in the
16+
# library - they must be resolvable via the normal search-dir
17+
# mechanism, same as any import. Tests below that deliberately point
18+
# Context() at a missing/empty/no search path still need this one
19+
# added explicitly, or context creation itself fails before the test
20+
# gets to exercise what it actually wants to test.
21+
CORE_MODULE_DIR = c2str(lib.ly_yang_module_dir())
22+
1323

1424
# -------------------------------------------------------------------------------------
1525

1626

1727
class ContextTest(unittest.TestCase):
1828
def test_ctx_no_dir(self):
19-
with Context() as ctx:
29+
with Context(CORE_MODULE_DIR) as ctx:
2030
self.assertIsNot(ctx, None)
2131

2232
def test_ctx_yanglib(self):
2333
ctx = Context(
24-
YANG_DIR,
34+
":".join([YANG_DIR, CORE_MODULE_DIR]),
2535
yanglib_path=YANG_DIR + "/yang-library.json",
2636
compile_obsolete=True,
2737
)
@@ -42,11 +52,11 @@ def test_ctx_duplicate_searchpath(self):
4252
self.fail("Context.__init__ should not raise LibyangError")
4353

4454
def test_ctx_invalid_dir(self):
45-
with Context("/does/not/exist") as ctx:
55+
with Context(":".join(["/does/not/exist", CORE_MODULE_DIR])) as ctx:
4656
self.assertIsNot(ctx, None)
4757

4858
def test_ctx_missing_dir(self):
49-
with Context(os.path.join(YANG_DIR, "yolo")) as ctx:
59+
with Context(":".join([os.path.join(YANG_DIR, "yolo"), CORE_MODULE_DIR])) as ctx:
5060
self.assertIsNot(ctx, None)
5161
with self.assertRaises(LibyangError):
5262
ctx.load_module("yolo-system")
@@ -56,7 +66,9 @@ def test_ctx_env_search_dir(self):
5666
os.environ["YANGPATH"] = ":".join(
5767
[os.path.join(YANG_DIR, "omg"), os.path.join(YANG_DIR, "wtf")]
5868
)
59-
with Context(os.path.join(YANG_DIR, "yolo")) as ctx:
69+
with Context(
70+
":".join([os.path.join(YANG_DIR, "yolo"), CORE_MODULE_DIR])
71+
) as ctx:
6072
mod = ctx.load_module("yolo-system")
6173
self.assertIsInstance(mod, Module)
6274
finally:

‎tests/test_diff.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import unittest
66

7+
from _libyang import lib
78
from libyang import (
89
BaseTypeAdded,
910
BaseTypeRemoved,
@@ -21,11 +22,17 @@
2122
StatusRemoved,
2223
schema_diff,
2324
)
25+
from libyang.util import c2str
2426

2527

2628
OLD_YANG_DIR = os.path.join(os.path.dirname(__file__), "yang-old")
2729
NEW_YANG_DIR = os.path.join(os.path.dirname(__file__), "yang")
2830

31+
# yang-old/ doesn't carry its own copy of the core modules that
32+
# ly_ctx_new() now loads unconditionally (see test_context.py's
33+
# CORE_MODULE_DIR) - add libyang's install-tree copy explicitly.
34+
CORE_MODULE_DIR = c2str(lib.ly_yang_module_dir())
35+
2936

3037
# -------------------------------------------------------------------------------------
3138
class DiffTest(unittest.TestCase):
@@ -97,9 +104,9 @@ class DiffTest(unittest.TestCase):
97104
)
98105

99106
def test_diff(self):
100-
with Context(OLD_YANG_DIR, compile_obsolete=True) as ctx_old, Context(
101-
NEW_YANG_DIR, compile_obsolete=True
102-
) as ctx_new:
107+
with Context(
108+
":".join([OLD_YANG_DIR, CORE_MODULE_DIR]), compile_obsolete=True
109+
) as ctx_old, Context(NEW_YANG_DIR, compile_obsolete=True) as ctx_new:
103110
mod = ctx_old.load_module("yolo-system")
104111
mod.feature_enable_all()
105112
mod = ctx_new.load_module("yolo-system")

0 commit comments

Comments
 (0)