@@ -21,7 +21,7 @@ def test_apply_demag_integration():
2121 # Test that different equivalent susceptibility inputs give same result
2222 dm1 = apply_demag (mesh , susceptibility = 4 )
2323 dm2 = apply_demag (mesh , susceptibility = (4 , 4 , 4 ))
24-
24+
2525 zone .susceptibility = 4
2626 mesh_with_attr = mesh_Cuboid (zone , (2 , 2 , 2 ))
2727 dm3 = apply_demag (mesh_with_attr )
@@ -39,41 +39,41 @@ def test_apply_demag_integration():
3939 "source_scalar" ,
4040 [(2.5 ,), (3.0 ,)],
4141 np .array ([2.5 , 3.0 , 2.5 , 3.0 , 2.5 , 3.0 ]),
42- id = "source_scalar"
42+ id = "source_scalar" ,
4343 ),
4444 pytest .param (
45- "source_vector" ,
45+ "source_vector" ,
4646 [(1.0 , 2.0 , 3.0 ), (4.0 , 5.0 , 6.0 )],
4747 np .array ([1.0 , 4.0 , 2.0 , 5.0 , 3.0 , 6.0 ]),
48- id = "source_vector"
48+ id = "source_vector" ,
4949 ),
5050 pytest .param (
5151 "function_scalar" ,
5252 1.5 ,
5353 np .array ([1.5 , 1.5 , 1.5 , 1.5 , 1.5 , 1.5 ]),
54- id = "function_scalar"
54+ id = "function_scalar" ,
5555 ),
5656 pytest .param (
5757 "function_vector" ,
5858 (2.0 , 3.0 , 4.0 ),
5959 np .array ([2.0 , 2.0 , 3.0 , 3.0 , 4.0 , 4.0 ]),
60- id = "function_vector"
60+ id = "function_vector" ,
6161 ),
6262 pytest .param (
6363 "function_list" ,
6464 [1.5 , 2.5 ],
6565 np .array ([1.5 , 2.5 , 1.5 , 2.5 , 1.5 , 2.5 ]),
66- id = "function_list"
66+ id = "function_list" ,
6767 ),
68- ]
68+ ],
6969)
7070def test_get_susceptibilities_basic (test_case , susceptibility_input , expected_output ):
7171 """Test basic get_susceptibilities functionality with source attributes and function inputs"""
7272 sources = []
7373 for _ in range (2 ):
7474 zone = magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
7575 sources .append (zone )
76-
76+
7777 if test_case .startswith ("source" ):
7878 # Set susceptibility on sources
7979 for i , sus_val in enumerate (susceptibility_input ):
@@ -85,7 +85,7 @@ def test_get_susceptibilities_basic(test_case, susceptibility_input, expected_ou
8585 else :
8686 # Use function input
8787 result = get_susceptibilities (sources , susceptibility = susceptibility_input )
88-
88+
8989 np .testing .assert_allclose (result , expected_output )
9090
9191
@@ -94,20 +94,20 @@ def test_get_susceptibilities_hierarchy():
9494 # Create collection with susceptibility
9595 collection = magpy .Collection ()
9696 collection .susceptibility = 2.0
97-
97+
9898 # Source with its own susceptibility
9999 zone_own = magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
100100 zone_own .susceptibility = 5.0
101-
101+
102102 # Source inheriting from parent
103103 zone_inherit = magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
104104 collection .add (zone_inherit )
105-
105+
106106 # Test mixed sources (critical edge case)
107107 result = get_susceptibilities ([zone_own , zone_inherit ])
108108 expected = np .array ([5.0 , 2.0 , 5.0 , 2.0 , 5.0 , 2.0 ])
109109 np .testing .assert_allclose (result , expected )
110-
110+
111111 # Test single inheritance
112112 result_single = get_susceptibilities ([zone_inherit ])
113113 expected_single = np .array ([2.0 , 2.0 , 2.0 ])
@@ -121,32 +121,38 @@ def test_get_susceptibilities_hierarchy():
121121 "no_susceptibility" ,
122122 lambda : [magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))],
123123 "No susceptibility defined in any parent collection" ,
124- id = "no_susceptibility"
124+ id = "no_susceptibility" ,
125125 ),
126126 pytest .param (
127127 "invalid_format" ,
128128 lambda : [_create_zone_with_bad_susceptibility ()],
129129 "susceptibility is not scalar or array of length 3" ,
130- id = "invalid_format"
130+ id = "invalid_format" ,
131131 ),
132132 pytest .param (
133133 "wrong_length" ,
134- lambda : [magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 )) for _ in range (4 )],
134+ lambda : [
135+ magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
136+ for _ in range (4 )
137+ ],
135138 "Apply_demag input susceptibility must be scalar, 3-vector, or same length as input Collection" ,
136- id = "wrong_length"
139+ id = "wrong_length" ,
137140 ),
138141 pytest .param (
139142 "ambiguous_input" ,
140- lambda : [magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 )) for _ in range (3 )],
143+ lambda : [
144+ magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
145+ for _ in range (3 )
146+ ],
141147 "Apply_demag input susceptibility is ambiguous" ,
142- id = "ambiguous_input"
148+ id = "ambiguous_input" ,
143149 ),
144- ]
150+ ],
145151)
146152def test_get_susceptibilities_errors (error_case , setup_func , error_message ):
147153 """Test error cases for get_susceptibilities function"""
148154 sources = setup_func ()
149-
155+
150156 if error_case == "wrong_length" :
151157 with pytest .raises (ValueError , match = error_message ):
152158 get_susceptibilities (sources , susceptibility = [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ])
@@ -170,7 +176,7 @@ def test_get_susceptibilities_edge_cases():
170176 # Empty sources
171177 result = get_susceptibilities ([])
172178 assert len (result ) == 0
173-
179+
174180 # Single source
175181 zone = magpy .magnet .Cuboid (dimension = (1 , 1 , 1 ), polarization = (0 , 0 , 1 ))
176182 zone .susceptibility = 3.0
0 commit comments