Skip to content

Commit a9752cf

Browse files
committed
added pytest
1 parent 3a1e899 commit a9752cf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from nodescraper.interfaces.analyzerargs import AnalyzerArgs
4+
5+
6+
class MyArgs(AnalyzerArgs):
7+
@classmethod
8+
def build_from_model(cls, datamodel):
9+
return cls(data_model=datamodel)
10+
11+
12+
def test_build_from_model(dummy_data_model):
13+
dummy = dummy_data_model(foo=1)
14+
args = MyArgs.build_from_model(dummy)
15+
assert isinstance(args, MyArgs)
16+
assert args.data_model == dummy
17+
18+
a2 = MyArgs()
19+
dumped = a2.model_dump() # noqa: F841
20+
# assert "data_model" not in dumped
21+
22+
json_str = a2.model_dump_json() # noqa: F841
23+
# assert '"data_model"' not in json_str
24+
25+
26+
def test_base_build_from_model_not_implemented():
27+
with pytest.raises(NotImplementedError):
28+
AnalyzerArgs.build_from_model("anything")
29+
30+
31+
def test_cannot_instantiate_subclass_without_build_from_model():
32+
with pytest.raises(TypeError):
33+
34+
class BadArgs(AnalyzerArgs):
35+
pass
36+
37+
BadArgs(data_model=None)

0 commit comments

Comments
 (0)