File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,8 @@ def clone(self) -> "Asset":
127
127
Returns:
128
128
Asset: The clone of this asset.
129
129
"""
130
- return Asset (
130
+ cls = self .__class__
131
+ return cls (
131
132
href = self .href ,
132
133
title = self .title ,
133
134
description = self .description ,
@@ -139,8 +140,8 @@ def clone(self) -> "Asset":
139
140
def __repr__ (self ) -> str :
140
141
return "<Asset href={}>" .format (self .href )
141
142
142
- @staticmethod
143
- def from_dict (d : Dict [str , Any ]) -> "Asset" :
143
+ @classmethod
144
+ def from_dict (cls , d : Dict [str , Any ]) -> "Asset" :
144
145
"""Constructs an Asset from a dict.
145
146
146
147
Returns:
@@ -156,7 +157,7 @@ def from_dict(d: Dict[str, Any]) -> "Asset":
156
157
if any (d ):
157
158
properties = d
158
159
159
- return Asset (
160
+ return cls (
160
161
href = href ,
161
162
media_type = media_type ,
162
163
title = title ,
Original file line number Diff line number Diff line change @@ -742,3 +742,26 @@ def test_from_file_returns_subclass(self) -> None:
742
742
custom_item = self .BasicCustomItem .from_file (self .SAMPLE_ITEM )
743
743
744
744
self .assertIsInstance (custom_item , self .BasicCustomItem )
745
+
746
+
747
+ class AssetSubClassTest (unittest .TestCase ):
748
+ class CustomAsset (Asset ):
749
+ pass
750
+
751
+ def setUp (self ) -> None :
752
+ self .maxDiff = None
753
+ with open (TestCases .get_path ("data-files/item/sample-item.json" )) as src :
754
+ item_dict = json .load (src )
755
+
756
+ self .asset_dict = item_dict ["assets" ]["analytic" ]
757
+
758
+ def test_from_dict (self ) -> None :
759
+ asset = self .CustomAsset .from_dict (self .asset_dict )
760
+
761
+ self .assertIsInstance (asset , self .CustomAsset )
762
+
763
+ def test_clone (self ) -> None :
764
+ asset = self .CustomAsset .from_dict (self .asset_dict )
765
+ cloned_asset = asset .clone ()
766
+
767
+ self .assertIsInstance (cloned_asset , self .CustomAsset )
You can’t perform that action at this time.
0 commit comments