3838STAT_TYPE_STDDEV = 3
3939STAT_TYPE_SNR = 4
4040
41+ # Names for each statistic identifier defined in this module.
42+ STAT_NAME_MEAN = "mean"
43+ STAT_NAME_MEDIAN = "median"
44+ STAT_NAME_VARIANCE = "variance"
45+ STAT_NAME_STD_DEV = "stddev"
46+ STAT_NAME_SNR = "snr"
47+ STAT_NAME_LIST = [
48+ STAT_NAME_MEAN ,
49+ STAT_NAME_MEDIAN ,
50+ STAT_NAME_VARIANCE ,
51+ STAT_NAME_STD_DEV ,
52+ STAT_NAME_SNR ,
53+ ]
54+
4155
4256# @unittest.skip
4357class TestAnimCurveStatistics (test_tools_utils .ToolsTestCase ):
@@ -56,15 +70,15 @@ def _parse_statistics_result(self, result):
5670 stat_value = result [i + 1 ]
5771
5872 if stat_type == STAT_TYPE_MEAN :
59- stats ["mean" ] = stat_value
73+ stats [STAT_NAME_MEAN ] = stat_value
6074 elif stat_type == STAT_TYPE_MEDIAN :
61- stats ["median" ] = stat_value
75+ stats [STAT_NAME_MEDIAN ] = stat_value
6276 elif stat_type == STAT_TYPE_VARIANCE :
63- stats ["variance" ] = stat_value
77+ stats [STAT_NAME_VARIANCE ] = stat_value
6478 elif stat_type == STAT_TYPE_STDDEV :
65- stats ["stddev" ] = stat_value
79+ stats [STAT_NAME_STD_DEV ] = stat_value
6680 elif stat_type == STAT_TYPE_SNR :
67- stats ["snr" ] = stat_value
81+ stats [STAT_NAME_SNR ] = stat_value
6882
6983 i += 2
7084
@@ -109,18 +123,16 @@ def test_statistics_all_flags(self):
109123 for curve_data in parsed :
110124 stats = curve_data ["stats" ]
111125 # Verify all statistics are present.
112- self .assertIn ("mean" , stats )
113- self .assertIn ("median" , stats )
114- self .assertIn ("variance" , stats )
115- self .assertIn ("stddev" , stats )
116- self .assertIn ("snr" , stats )
126+ for stat_name in STAT_NAME_LIST :
127+ self .assertIn (stat_name , stats )
128+ self .assertEqual (len (stats .keys ()), len (STAT_NAME_LIST ))
117129
118130 # Verify relationships between statistics.
119131 # Standard deviation should be sqrt(variance).
120- expected_stddev = math .sqrt (stats ["variance" ])
121- self .assertAlmostEqual (stats ["stddev" ], expected_stddev , places = 5 )
132+ expected_stddev = math .sqrt (stats [STAT_NAME_VARIANCE ])
133+ self .assertAlmostEqual (stats [STAT_NAME_STD_DEV ], expected_stddev , places = 5 )
122134
123- # All values should be finite
135+ # All values should be finite.
124136 for stat_name , stat_value in stats .items ():
125137 self .assertTrue (
126138 math .isfinite (stat_value ),
@@ -142,21 +154,21 @@ def test_statistics_single_flag(self):
142154 parsed = self ._parse_statistics_result (result )
143155 self .assertEqual (len (parsed ), 1 )
144156 self .assertEqual (len (parsed [0 ]["stats" ]), 1 )
145- self .assertIn ("mean" , parsed [0 ]["stats" ])
157+ self .assertIn (STAT_NAME_MEAN , parsed [0 ]["stats" ])
146158
147159 # Test median only.
148160 result = maya .cmds .mmAnimCurveStatistics (animCurve_tx , median = True )
149161 parsed = self ._parse_statistics_result (result )
150162 self .assertEqual (len (parsed ), 1 )
151163 self .assertEqual (len (parsed [0 ]["stats" ]), 1 )
152- self .assertIn ("median" , parsed [0 ]["stats" ])
164+ self .assertIn (STAT_NAME_MEDIAN , parsed [0 ]["stats" ])
153165
154166 # Test variance only.
155167 result = maya .cmds .mmAnimCurveStatistics (animCurve_tx , variance = True )
156168 parsed = self ._parse_statistics_result (result )
157169 self .assertEqual (len (parsed ), 1 )
158170 self .assertEqual (len (parsed [0 ]["stats" ]), 1 )
159- self .assertIn ("variance" , parsed [0 ]["stats" ])
171+ self .assertIn (STAT_NAME_VARIANCE , parsed [0 ]["stats" ])
160172
161173 def test_statistics_frame_range (self ):
162174 """Test statistics with different frame ranges."""
@@ -182,8 +194,8 @@ def test_statistics_frame_range(self):
182194
183195 # Statistics should be different for different ranges.
184196 self .assertNotAlmostEqual (
185- parsed_full [0 ]["stats" ]["mean" ],
186- parsed_partial [0 ]["stats" ]["mean" ],
197+ parsed_full [0 ]["stats" ][STAT_NAME_MEAN ],
198+ parsed_partial [0 ]["stats" ][STAT_NAME_MEAN ],
187199 places = 2 ,
188200 )
189201
@@ -212,8 +224,8 @@ def test_statistics_multiple_curves(self):
212224 for i , curve_data in enumerate (parsed ):
213225 self .assertEqual (curve_data ["index" ], i )
214226 self .assertEqual (len (curve_data ["stats" ]), 2 )
215- self .assertIn ("mean" , curve_data ["stats" ])
216- self .assertIn ("stddev" , curve_data ["stats" ])
227+ self .assertIn (STAT_NAME_MEAN , curve_data ["stats" ])
228+ self .assertIn (STAT_NAME_STD_DEV , curve_data ["stats" ])
217229
218230 def test_statistics_constant_curve (self ):
219231 """Test statistics on a constant (flat) animation curve."""
@@ -246,17 +258,19 @@ def test_statistics_constant_curve(self):
246258
247259 # For a constant curve mean and median should equal the
248260 # constant value.
249- self .assertAlmostEqual (stats ["mean" ], constant_value , places = 5 )
250- self .assertAlmostEqual (stats ["median" ], constant_value , places = 5 )
261+ self .assertAlmostEqual (stats [STAT_NAME_MEAN ], constant_value , places = 5 )
262+ self .assertAlmostEqual (stats [STAT_NAME_MEDIAN ], constant_value , places = 5 )
251263
252264 # For a constant curve variance and standard deviation should
253265 # be zero.
254- self .assertAlmostEqual (stats ["variance" ], 0.0 , places = 5 )
255- self .assertAlmostEqual (stats ["stddev" ], 0.0 , places = 5 )
266+ self .assertAlmostEqual (stats [STAT_NAME_VARIANCE ], 0.0 , places = 5 )
267+ self .assertAlmostEqual (stats [STAT_NAME_STD_DEV ], 0.0 , places = 5 )
256268
257269 # For a constant curve SNR should be infinity (but might be
258270 # represented as a large value).
259- self .assertTrue (stats ["snr" ] > 1000.0 or math .isinf (stats ["snr" ]))
271+ self .assertTrue (
272+ stats [STAT_NAME_SNR ] > 1000.0 or math .isinf (stats [STAT_NAME_SNR ])
273+ )
260274
261275 def test_statistics_linear_curve (self ):
262276 """Test statistics on a linear animation curve."""
@@ -283,13 +297,13 @@ def test_statistics_linear_curve(self):
283297
284298 # For a linear curve from 0 to 9:
285299 # - Mean should be 4.5.
286- self .assertAlmostEqual (stats ["mean" ], 4.5 , places = 2 )
300+ self .assertAlmostEqual (stats [STAT_NAME_MEAN ], 4.5 , places = 2 )
287301
288302 # - Median should also be 4.5.
289- self .assertAlmostEqual (stats ["median" ], 4.5 , places = 2 )
303+ self .assertAlmostEqual (stats [STAT_NAME_MEDIAN ], 4.5 , places = 2 )
290304
291305 # - Variance should be > 0 (approximately 8.25 for 0-9 range).
292- self .assertGreater (stats ["variance" ], 0 )
306+ self .assertGreater (stats [STAT_NAME_VARIANCE ], 0 )
293307
294308 def test_statistics_error_handling (self ):
295309 """Test error handling for invalid inputs."""
@@ -322,8 +336,8 @@ def test_statistics_combined_flags(self):
322336
323337 # Verify stddev = sqrt(variance).
324338 stats = parsed [0 ]["stats" ]
325- expected_stddev = math .sqrt (stats ["variance" ])
326- self .assertAlmostEqual (stats ["stddev" ], expected_stddev , places = 5 )
339+ expected_stddev = math .sqrt (stats [STAT_NAME_VARIANCE ])
340+ self .assertAlmostEqual (stats [STAT_NAME_STD_DEV ], expected_stddev , places = 5 )
327341
328342 def test_statistics_with_list_input (self ):
329343 """Test statistics with Python list inputs."""
@@ -345,19 +359,17 @@ def test_statistics_with_list_input(self):
345359 self .assertEqual (len (parsed ), 1 )
346360
347361 stats = parsed [0 ]["stats" ]
348- # Verify all statistics are present
349- self .assertIn ("mean" , stats )
350- self .assertIn ("median" , stats )
351- self .assertIn ("variance" , stats )
352- self .assertIn ("stddev" , stats )
353- self .assertIn ("snr" , stats )
362+ # Verify all statistics are present.
363+ for stat_name in STAT_NAME_LIST :
364+ self .assertIn (stat_name , stats )
365+ self .assertEqual (len (stats .keys ()), len (STAT_NAME_LIST ))
354366
355367 # Verify relationships between statistics
356- expected_stddev = math .sqrt (stats ["variance" ])
357- self .assertAlmostEqual (stats ["stddev" ], expected_stddev , places = 5 )
368+ expected_stddev = math .sqrt (stats [STAT_NAME_VARIANCE ])
369+ self .assertAlmostEqual (stats [STAT_NAME_STD_DEV ], expected_stddev , places = 5 )
358370
359371 expected_mean = sum (y_values ) / len (y_values )
360- self .assertAlmostEqual (stats ["mean" ], expected_mean , places = 5 )
372+ self .assertAlmostEqual (stats [STAT_NAME_MEAN ], expected_mean , places = 5 )
361373
362374 def test_statistics_mixed_curves_and_lists_error (self ):
363375 """Test that mixing animation curves and list inputs produces an error."""
0 commit comments