def as_dict(self): """ A helper function for YAML dumping """ output_dict = dict() output_dict['class'] = self.__class__.__name__ output_dict['value'] = expand_to_dict(self.value) if self.units != '': output_dict['units'] = self.units if self.uncertainty is not None and any([val != 0.0 for val in np.nditer(self.uncertainty)]): logging.info(self.uncertainty) logging.info(type(self.uncertainty)) output_dict['uncertainty'] = expand_to_dict(self.uncertainty) output_dict['uncertainty_type'] = self.uncertainty_type return output_dict
def test_expanding_rmg_objects(self): """ Test that RMGObjects (even when nested) can be expanded using the as_dict method """ self.assertEqual(expand_to_dict(self.highly_nested_object), self.highly_nest_dictionary) self.assertEqual(self.highly_nested_object.as_dict(), self.highly_nest_dictionary)
def test_expanding_np_arrays(self): """ Test that np_arrays are expanded properly """ self.assertEqual(expand_to_dict(self.np_array), self.np_dict)
def test_expanding_objects_in_dictionary(self): """ Test that objects nested inside of dictionaries can be expanded """ self.assertEqual(expand_to_dict(self.dictionary_of_objects), self.objects_dict)
def test_expanding_list_to_dict(self): """ Test that objects nested inside of lists can be expanded """ self.assertEqual(expand_to_dict(self.list_of_objects), self.list_dict)