Exemple #1
0
    def setUp(self):
        self.mock_dionysus_settings = {'user_default_chart_save_folder': r'some\path'}

        self.test_load_chart_save_folder_return = Path(self.mock_dionysus_settings['user_default_chart_save_folder'])

        # Create file such that mocking it does not fail.
        if not Path.exists(APP_SETTINGS_FILE):
            self.created_app_settings = True
            create_app_settings_file()
        else:
            self.created_app_settings = False
Exemple #2
0
    def setUp(self):
        self.mock_APP_SETTINGS_FILE = Path(r'rome\camelot\king_of_britons_castle')
        self.mock_dionysus_settings = {'user_default_chart_save_folder': r'some\path'}

        self.test_new_settings = {'my_new_setting': 'some setting'}
        self.new_dionysus_settings_write = {**self.mock_dionysus_settings, **self.test_new_settings}

        # Create file such that mocking it does not fail.
        if not Path.exists(APP_SETTINGS_FILE):
            self.created_app_settings = True
            create_app_settings_file()
        else:
            self.created_app_settings = False
Exemple #3
0
    def test_create_app_settings_file_with_settings_dict(self,
                                                         mocked_create_app_data__init__,
                                                         mocked_write_settings_to_file
                                                         ):
        assert create_app_settings_file(self.test_settings_dict) is None

        mocked_create_app_data__init__.assert_called_once_with()
        mocked_write_settings_to_file.assert_called_once_with(self.test_settings_dict)
Exemple #4
0
    def test_create_app_settings_file_no_settings_dict(self,
                                                       mocked_create_app_data__init__,
                                                       mocked_write_settings_to_file
                                                       ):
        assert create_app_settings_file() is None

        mocked_create_app_data__init__.assert_called_once_with()
        mocked_write_settings_to_file.assert_called_once_with(self.default_blank_settings_dict)

        # Check default settings argument passed to write_settings_to_file is a dict:
        # call_args_list[first call][positional args][first positional arg]
        assert isinstance(mocked_write_settings_to_file.call_args_list[0][0][0], dict)
    def test_create_app_settings_file(self, monkeypatch, new_settings_dict,
                                      dict_to_write):
        create_app_data__init__mock, write_settings_to_file_mock = {
            'called': False
        }, {
            'called': False
        }

        def mocked_create_app_data__init__():
            create_app_data__init__mock['called'] = True

        def mocked_write_settings_to_file(settings_dict):
            assert settings_dict == dict_to_write
            write_settings_to_file_mock['called'] = True

        monkeypatch.setattr(settings_functions, 'write_settings_to_file',
                            mocked_write_settings_to_file)
        monkeypatch.setattr(settings_functions, 'create_app_data__init__',
                            mocked_create_app_data__init__)

        assert create_app_settings_file(new_settings_dict) is None

        assert create_app_data__init__mock[
            'called'] and write_settings_to_file_mock['called']