diff --git a/cflib/localization/param_io.py b/cflib/localization/param_io.py index 7c861675..7d337f46 100644 --- a/cflib/localization/param_io.py +++ b/cflib/localization/param_io.py @@ -19,11 +19,11 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - import yaml from cflib.crazyflie.param import PersistentParamState + class ParamFileManager(): """Reads and writes parameter configurations from file""" TYPE_ID = 'type' @@ -40,7 +40,8 @@ def write(file_name, params={}): for id, param in params.items(): assert isinstance(param, PersistentParamState) if isinstance(param, PersistentParamState): - file_params[id] = {'is_stored': param.is_stored, 'default_value': param.default_value, 'stored_value': param.stored_value} + file_params[id] = {'is_stored': param.is_stored, + 'default_value': param.default_value, 'stored_value': param.stored_value} data = { ParamFileManager.TYPE_ID: ParamFileManager.TYPE, @@ -49,7 +50,7 @@ def write(file_name, params={}): } yaml.dump(data, file) - + @staticmethod def read(file_name): file = open(file_name, 'r') @@ -71,13 +72,14 @@ def read(file_name): if data[ParamFileManager.VERSION_ID] != ParamFileManager.VERSION: raise Exception('Unsupported file version') - + def get_data(input_data): persistent_params = {} for id, param in input_data.items(): - persistent_params[id] = PersistentParamState(param['is_stored'], param['default_value'], param['stored_value']) + persistent_params[id] = PersistentParamState( + param['is_stored'], param['default_value'], param['stored_value']) return persistent_params - + if ParamFileManager.PARAMS_ID in data: return get_data(data[ParamFileManager.PARAMS_ID]) else: diff --git a/test/localization/test_param_io.py b/test/localization/test_param_io.py index 4a8f3826..1154e8a8 100644 --- a/test/localization/test_param_io.py +++ b/test/localization/test_param_io.py @@ -19,7 +19,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - import unittest from unittest.mock import ANY from unittest.mock import mock_open @@ -29,6 +28,7 @@ from cflib.localization import ParamFileManager + class TestParamFileManager(unittest.TestCase): def setUp(self): self.data = { @@ -48,7 +48,7 @@ def test_that_read_open_correct_file(self, mock_yaml_load): # Assert mock_file.assert_called_with(file_name, 'r') - + @patch('yaml.safe_load') def test_that_missing_file_type_raises(self, mock_yaml_load): # Fixture @@ -85,7 +85,7 @@ def test_that_missing_version_raises(self, mock_yaml_load): with self.assertRaises(Exception): with patch('builtins.open', new_callable=mock_open()): ParamFileManager.read('some/name.yaml') - + @patch('yaml.safe_load') def test_that_wrong_version_raises(self, mock_yaml_load): # Fixture @@ -106,10 +106,10 @@ def test_that_no_data_returns_empty_default_data(self, mock_yaml_load): # Test with patch('builtins.open', new_callable=mock_open()): actual_params = ParamFileManager.read('some/name.yaml') - + # Assert self.assertEqual(0, len(actual_params)) - + @patch('yaml.dump') def test_file_end_to_end_write_read(self, mock_yaml_dump): # Fixture @@ -126,7 +126,7 @@ def test_file_end_to_end_write_read(self, mock_yaml_dump): # Assert mock_yaml_dump.assert_called_with(expected, ANY) - + @patch('yaml.dump') def test_file_write_to_correct_file(self, mock_yaml_dump): # Fixture