<commit_before>import unittest
from robotide.controller.chiefcontroller import Backup


class BackupTestCase(unittest.TestCase):

    def setUp(self):
        self._backupper = _MyBackup()

    def test_backup_is_restored_when_save_raises_exception(self):
        try:
            with self._backupper:
                raise AssertionError('expected')
            self.fail('should not get here')
        except AssertionError:
            self.assertTrue(self._backupper.restored)
        self.assertEqual(None, self._backupper._backup)

    def test_backup_is_not_restored_when_save_passes(self):
        with self._backupper:
            pass
        self.assertFalse(self._backupper.restored)
        self.assertEqual(None, self._backupper._backup)


class _MyBackup(Backup):

    def __init__(self):
        self._path = object()
        self._backup = object()
        self.restored = False

    def _make_backup(self):
        self._backup = object()

    def _restore_backup(self):
        if not self._backup:
            raise AssertionError('No backup')
        self.restored = True<commit_msg>Improve test<commit_after>import unittest
from robotide.controller.chiefcontroller import Backup


class BackupTestCase(unittest.TestCase):

    def setUp(self):
        self._backupper = _MyBackup()

    def test_backup_is_restored_when_save_raises_exception(self):
        try:
            with self._backupper:
                raise _SaveFailed('expected')
            self.fail('should not get here')
        except _SaveFailed:
            self.assertTrue(self._backupper.restored)
        self.assertEqual(None, self._backupper._backup)

    def test_backup_is_not_restored_when_save_passes(self):
        with self._backupper:
            pass
        self.assertFalse(self._backupper.restored)
        self.assertEqual(None, self._backupper._backup)


class _SaveFailed(Exception):
    pass


class _MyBackup(Backup):

    def __init__(self):
        self._path = object()
        self._backup = object()
        self.restored = False

    def _make_backup(self):
        self._backup = object()

    def _restore_backup(self):
        if not self._backup:
            raise AssertionError('No backup')
        self.restored = True
{'fraction_non_alphanumeric': 0.08422459893048129, 'fraction_numerical': 0.0, 'mean_word_length': 2.626817447495961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103301', 'n_tokens_mistral': 645, 'n_tokens_neox': 630, 'n_words': 123}