This repository was archived by the owner on Jan 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
Next Release
6
6
------------
7
+ * Fix: Better error on bad ModelItem constructor argument (#50)
7
8
8
9
0.2.1 (2020-11-27)
9
10
------------------
Original file line number Diff line number Diff line change @@ -84,7 +84,17 @@ def __init__(
84
84
** kwargs ,
85
85
):
86
86
"""Initialise a ModelItem instance."""
87
- super ().__init__ (** kwargs )
87
+ if len (kwargs ) > 0 :
88
+ type_name = type (self ).__name__
89
+ args = [f"'{ key } '" for key in kwargs .keys ()]
90
+ if len (args ) == 1 :
91
+ raise TypeError (f"{ type_name } .__init__() got an unexpected "
92
+ f"keyword argument { args [0 ]} " )
93
+ else :
94
+ raise TypeError (f"{ type_name } .__init__() got unexpected "
95
+ f"keyword arguments { ', ' .join (args )} " )
96
+
97
+ super ().__init__ ()
88
98
self .id = id
89
99
self .tags = OrderedSet (tags )
90
100
self .properties = dict (properties )
Original file line number Diff line number Diff line change @@ -45,6 +45,25 @@ def test_model_item_init(attributes):
45
45
assert getattr (model_item , attr ) == expected
46
46
47
47
48
+ def test_handling_of_bogus_init_params ():
49
+ """
50
+ Test for sensible error message if wrong param passed.
51
+
52
+ See https://github.com/Midnighter/structurizr-python/issues/50.
53
+ """
54
+ with pytest .raises (
55
+ TypeError , match = r"ConcreteModelItem.__init__\(\) got an unexpected "
56
+ r"keyword argument 'foo'"
57
+ ):
58
+ ConcreteModelItem (foo = 7 )
59
+ with pytest .raises (
60
+ TypeError ,
61
+ match = r"ConcreteModelItem.__init__\(\) got unexpected keyword "
62
+ r"arguments 'foo', 'bar'" ,
63
+ ):
64
+ ConcreteModelItem (foo = 7 , bar = 17 )
65
+
66
+
48
67
def test_default_element_tags_order (empty_model : Model ):
49
68
"""
50
69
Test that the default tags get added in the right order.
You can’t perform that action at this time.
0 commit comments