def test_that_wrong_version_raises(self, mock_yaml_load):
        # Fixture
        self.data['version'] = 'wrong version'
        mock_yaml_load.return_value = self.data

        # Test
        # Assert
        with self.assertRaises(Exception):
            with patch('builtins.open', new_callable=mock_open()):
                LighthouseConfigFileManager.read('some/name.yaml')
    def test_file_write_to_correct_file(self, mock_yaml_dump):
        # Fixture
        file_name = 'some/name.yaml'

        # Test
        with patch('builtins.open', new_callable=mock_open()) as mock_file:
            LighthouseConfigFileManager.write(file_name)

            # Assert
            mock_file.assert_called_with(file_name, 'w')
    def test_that_missing_file_type_raises(self, mock_yaml_load):
        # Fixture
        self.data.pop('type')
        mock_yaml_load.return_value = self.data

        # Test
        # Assert
        with self.assertRaises(Exception):
            with patch('builtins.open', new_callable=mock_open()):
                LighthouseConfigFileManager.read('some/name.yaml')
    def test_that_read_open_correct_file(self, mock_yaml_load):
        # Fixture
        mock_yaml_load.return_value = self.data
        file_name = 'some/name.yaml'

        # Test
        with patch('builtins.open', new_callable=mock_open()) as mock_file:
            LighthouseConfigFileManager.read(file_name)

        # Assert
        mock_file.assert_called_with(file_name, 'r')
Exemplo n.º 5
0
    def _save_sys_config(self, geos, calibs):
        names = QFileDialog.getSaveFileName(self, 'Save file',
                                            self._current_folder,
                                            "*.yaml;;*.*")

        if names[0] == '':
            return

        self._current_folder = os.path.dirname(names[0])

        if not names[0].endswith(".yaml") and names[0].find(".") < 0:
            filename = names[0] + ".yaml"
        else:
            filename = names[0]

        LighthouseConfigFileManager.write(filename, geos, calibs)
Exemplo n.º 6
0
    def test_file_end_to_end_write_read(self, mock_yaml_dump):
        # Fixture
        fixture_file = 'test/localization/fixtures/system_config.yaml'

        file = open(fixture_file, 'r')
        expected = yaml.safe_load(file)
        file.close()

        # Test
        geos, calibs = LighthouseConfigFileManager.read(fixture_file)
        with patch('builtins.open', new_callable=mock_open()):
            LighthouseConfigFileManager.write('some/name.yaml',
                                              geos=geos,
                                              calibs=calibs)

            # Assert
            mock_yaml_dump.assert_called_with(expected, ANY)
Exemplo n.º 7
0
    def test_that_no_data_returns_empty_dictionaries(self, mock_yaml_load):
        # Fixture
        mock_yaml_load.return_value = self.data

        # Test
        with patch('builtins.open', new_callable=mock_open()):
            actual_geos, actual_calibs = LighthouseConfigFileManager.read(
                'some/name.yaml')

        # Assert
        self.assertEqual(0, len(actual_geos))
        self.assertEqual(0, len(actual_calibs))
    def test_that_no_data_returns_empty_default_data(self, mock_yaml_load):
        # Fixture
        mock_yaml_load.return_value = self.data

        # Test
        with patch('builtins.open', new_callable=mock_open()):
            actual_geos, actual_calibs, actual_system_type = LighthouseConfigFileManager.read(
                'some/name.yaml')

        # Assert
        self.assertEqual(0, len(actual_geos))
        self.assertEqual(0, len(actual_calibs))
        self.assertEqual(LighthouseConfigFileManager.SYSTEM_TYPE_V2,
                         actual_system_type)