def test_create_if_doesnt_exists(self): settings_file = six.StringIO() settings_path_mock = Mock( is_file=Mock(return_value=False), open=Mock(return_value=Mock( __exit__=lambda *args: None, __enter__=lambda *args: settings_file))) user_dir_mock = Mock(joinpath=Mock(return_value=settings_path_mock)) conf.initialize_settings_file(user_dir_mock) settings_file_contents = settings_file.getvalue() assert settings_path_mock.is_file.call_count == 1 assert settings_path_mock.open.call_count == 1 assert conf.SETTINGS_HEADER in settings_file_contents for setting in conf.DEFAULT_SETTINGS.items(): assert '# {} = {}\n'.format(*setting) in settings_file_contents settings_file.close()
def test_create_if_doesnt_exists(self): settings_file = six.StringIO() settings_path_mock = Mock( is_file=Mock(return_value=False), open=Mock( return_value=Mock(__exit__=lambda *args: None, __enter__=lambda *args: settings_file))) user_dir_mock = Mock(joinpath=Mock(return_value=settings_path_mock)) conf.initialize_settings_file(user_dir_mock) settings_file_contents = settings_file.getvalue() assert settings_path_mock.is_file.call_count == 1 assert settings_path_mock.open.call_count == 1 assert conf.SETTINGS_HEADER in settings_file_contents for setting in conf.DEFAULT_SETTINGS.items(): assert '# {} = {}\n'.format(*setting) in settings_file_contents settings_file.close()
def test_ignore_if_exists(self): settings_path_mock = Mock(is_file=Mock(return_value=True), open=Mock()) user_dir_mock = Mock(joinpath=Mock(return_value=settings_path_mock)) conf.initialize_settings_file(user_dir_mock) assert settings_path_mock.is_file.call_count == 1 assert not settings_path_mock.open.called