Skip to content
Snippets Groups Projects
Commit d950f558 authored by Ladislav Lhotka's avatar Ladislav Lhotka
Browse files

Add class method DataModel::from_file.

parent 8d6c5a7f
No related branches found
No related tags found
No related merge requests found
......@@ -76,11 +76,8 @@ tree = """+--rw (test:choiA)?
@pytest.fixture
def data_model():
tpath = ["examples/test", "examples/ietf"]
with open("examples/test/yang-library-data.json",
encoding="utf-8") as ylfile:
ylib = ylfile.read()
return DataModel(ylib, tpath)
return DataModel.from_file("examples/test/yang-library-data.json",
["examples/test", "examples/ietf"])
@pytest.fixture
def instance(data_model):
......
......@@ -27,6 +27,13 @@ class DataModel:
raise BadYangLibraryData() from None
Context.from_yang_library(yl, mod_path)
@classmethod
def from_file(cls, name: str, mod_path: List[str] = ["."]) -> "DataModel":
"""Return an instance initialised from a file with YANG library data."""
with open(name, encoding="utf-8") as infile:
yltxt = infile.read()
return cls(yltxt, mod_path)
@staticmethod
def module_set_id():
"""Return numeric id of the current set of modules."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment