File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments