11import unittest
22from pathlib import Path
3- from typing import Any , Callable , Dict , List , Optional , Type , TypeVar
3+ from typing import Any
44from unittest .mock import MagicMock , patch
55
66from hydrolib .core .base .file_manager import FileLoadContext
77from hydrolib .core .base .models import (
88 BaseModel ,
99 DiskOnlyFileModel ,
10- ParsableFileModel ,
1110 SerializerConfig ,
1211 _should_execute ,
1312 _should_traverse ,
1413)
15-
16-
17- # Common test model classes to reduce duplication
18- class SimpleTestModel (BaseModel ):
19- """A simple test model with basic properties."""
20-
21- name : str
22- value : int
23-
24-
25- class TestModelWithLinks (BaseModel ):
26- """A test model that overrides link methods."""
27-
28- name : str
29-
30- def is_file_link (self ) -> bool :
31- return True
32-
33- def is_intermediate_link (self ) -> bool :
34- return True
35-
36-
37- class ChildTestModel (TestModelWithLinks ):
38- """A child test model for hierarchy testing."""
39-
40- value : int
41-
42-
43- class ParentTestModel (TestModelWithLinks ):
44- """A parent test model for hierarchy testing."""
45-
46- child : ChildTestModel
47- children : List [ChildTestModel ] = []
48-
49-
50- class TestBaseModelWithFunc (BaseModel ):
51- """A test base model that can track function calls."""
52-
53- def test_func (self ):
54- """Test function that can be used to track calls."""
55- pass
56-
57-
58- class ChildModelWithFunc (TestBaseModelWithFunc , ChildTestModel ):
59- """A child model that includes the test_func method."""
60-
61- pass
62-
63-
64- class ParentModelWithFunc (TestBaseModelWithFunc , ParentTestModel ):
65- """A parent model that includes the test_func method."""
66-
67- pass
14+ from tests .base .data import (
15+ BaseModelWithFunc ,
16+ ChildModelWithFunc ,
17+ ChildTestModel ,
18+ ModelWithLinks ,
19+ ParentModelWithFunc ,
20+ ParentTestModel ,
21+ ParsableModelWithMocks ,
22+ SaveModelBase ,
23+ SimpleTestModel ,
24+ )
6825
6926
7027class TestBaseModel (unittest .TestCase ):
@@ -88,7 +45,7 @@ def test_is_file_link(self):
8845 self .assertFalse (model .is_file_link ())
8946
9047 # Test overridden implementation
91- model_with_links = TestModelWithLinks (name = "test" )
48+ model_with_links = ModelWithLinks (name = "test" )
9249 self .assertTrue (model_with_links .is_file_link ())
9350
9451 def test_is_intermediate_link (self ):
@@ -98,7 +55,7 @@ def test_is_intermediate_link(self):
9855 self .assertFalse (model .is_intermediate_link ())
9956
10057 # Test overridden implementation
101- model_with_links = TestModelWithLinks (name = "test" )
58+ model_with_links = ModelWithLinks (name = "test" )
10259 self .assertTrue (model_with_links .is_intermediate_link ())
10360
10461 def test_show_tree (self ):
@@ -123,7 +80,7 @@ def test_func(self):
12380 called_models .append (self )
12481
12582 # Patch the test_func method
126- with patch .object (TestBaseModelWithFunc , "test_func" , test_func ):
83+ with patch .object (BaseModelWithFunc , "test_func" , test_func ):
12784 child1 = ChildModelWithFunc (name = "child1" , value = 1 )
12885 child2 = ChildModelWithFunc (name = "child2" , value = 2 )
12986 child3 = ChildModelWithFunc (name = "child3" , value = 3 )
@@ -148,48 +105,12 @@ def test_get_identifier(self):
148105 self .assertIsNone (model ._get_identifier ({"name" : "test" , "value" : 42 }))
149106
150107
151- # Common test model classes for ParsableFileModel tests
152- class TestParsableModelBase (ParsableFileModel ):
153- """Base class for parsable file model tests."""
154-
155- name : str = "default"
156- value : int = 0
157-
158- @classmethod
159- def _filename (cls ) -> str :
160- return "test"
161-
162- @classmethod
163- def _ext (cls ) -> str :
164- return ".test"
165-
166- @classmethod
167- def _get_serializer (cls ):
168- return MagicMock ()
169-
170- @classmethod
171- def _get_parser (cls ):
172- return MagicMock (return_value = {"name" : "parsed" , "value" : 42 })
173-
174-
175- class TestSaveModelBase (TestParsableModelBase ):
176- """Base class for testing save functionality."""
177-
178- @property
179- def _resolved_filepath (self ):
180- return Path (f"{ self .__class__ .__name__ .lower ()} .test" )
181-
182- def _load (self , filepath : Path ) -> Dict :
183- # Override _load to avoid file not found error
184- return {"name" : self .__class__ .__name__ .lower (), "value" : 100 }
185-
186-
187108class TestParsableFileModel (unittest .TestCase ):
188109 """Test cases for the ParsableFileModel class."""
189110
190111 def setUp (self ):
191112 """Set up test fixtures."""
192- self .TestParsableModel = TestParsableModelBase
113+ self .TestParsableModel = ParsableModelWithMocks
193114
194115 def test_load (self ):
195116 """Test _load method."""
@@ -220,7 +141,7 @@ def test_save(self):
220141 mock_serializer = MagicMock ()
221142
222143 # Create a test model class that uses the mock serializer
223- class TestSaveModel (TestSaveModelBase ):
144+ class TestSaveModel (SaveModelBase ):
224145 @classmethod
225146 def _get_serializer (cls ):
226147 return mock_serializer
@@ -256,7 +177,7 @@ def test_serialize(self):
256177 mock_serializer = MagicMock ()
257178
258179 # Create a test model class that uses the mock serializer
259- class TestSerializeModel (TestSaveModelBase ):
180+ class TestSerializeModel (SaveModelBase ):
260181 @classmethod
261182 def _get_serializer (cls ):
262183 return mock_serializer
0 commit comments