Пример #1
0
class TestAudioPresetsIO(common.TestCase):
    def setUp(self):
        self.manager = AudioPresetManager(System())
        self.manager.user_path = tempfile.mkdtemp()

    def tearDown(self):
        clearPresetManagerPaths(self.manager)

    def createOtherManager(self):
        other_manager = AudioPresetManager(System())
        other_manager.user_path = self.manager.user_path
        return other_manager

    def testSaveAndLoad(self):
        self.manager.createPreset("Vegeta", {
            "channels": 6000,
            "sample-rate": 44100
        })
        self.manager.saveAll()
        self.assertEqual(1, countUserPresets(self.manager))

        self.manager.createPreset("Nappa", {
            "channels": 4000,
            "sample-rate": 44100
        })
        self.manager.saveAll()
        self.assertEqual(2, countUserPresets(self.manager))

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        total_presets = countDefaultPresets(self.manager) + countUserPresets(
            self.manager)
        self.assertEqual(total_presets, len(other_manager.presets))

    def testNonAsciiFilenamesSaveAndLoad(self):
        non_ascii_preset_name = "Solid Snake (ソリッド・スネーク) \\#!\"'$%?&*"
        self.manager.createPreset(non_ascii_preset_name, {
            "channels": 2,
            "sample-rate": 44100
        })
        snake = self.manager.presets[non_ascii_preset_name]
        self.assertEqual(2, len(snake))
        self.manager.saveAll()

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        self.assertEqual(1 + countDefaultPresets(other_manager),
                         len(other_manager.presets))
        snaaaake = other_manager.presets[non_ascii_preset_name]
        self.assertEqual(snake, snaaaake)

    def testInvalidFilenamesSaveAndLoad(self):
        # This would be an invalid file name as is.
        preset_name = " / % "
        self.manager.createPreset(preset_name, {
            "channels": 2,
            "sample-rate": 44100
        })
        values = self.manager.presets[preset_name]
        self.assertEqual(2, len(values))
        self.manager.saveAll()

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        self.assertEqual(1 + countDefaultPresets(other_manager),
                         len(other_manager.presets))
        other_values = other_manager.presets[preset_name]
        self.assertEqual(values, other_values)

    def testRemovingSystemPresets(self):
        self.manager.loadAll()
        system_presets = list(self.manager.presets.keys())
        for preset_name in system_presets:
            self.manager.restorePreset(preset_name)
            self.manager.removeCurrentPreset()

        # Check that the files have not been deleted or changed.
        other_manager = AudioPresetManager(System())
        other_manager.user_path = "/pitivi/non/existing/directory"
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertTrue(other_manager.hasPreset(preset_name))

        # Check that overwrite files have been created and
        # they mark the system presets as deleted.
        other_manager = self.createOtherManager()
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertFalse(other_manager.hasPreset(preset_name))

    def testRenamingSystemPresets(self):
        self.manager.loadAll()
        system_presets = list(self.manager.presets.keys())
        new_name_template = "%s new"
        for preset_name in system_presets:
            self.manager.restorePreset(preset_name)
            new_name = new_name_template % preset_name
            self.manager.saveCurrentPreset(new_name)

        # Check that the files have not been deleted or changed.
        other_manager = AudioPresetManager(System())
        other_manager.user_path = "/pitivi/non/existing/directory"
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertTrue(other_manager.hasPreset(preset_name), preset_name)

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertFalse(other_manager.hasPreset(preset_name), preset_name)
            new_name = new_name_template % preset_name
            self.assertTrue(other_manager.hasPreset(new_name), new_name)
Пример #2
0
class TestAudioPresetsIO(TestCase):

    def setUp(self):
        self.manager = AudioPresetManager()
        self.manager.user_path = tempfile.mkdtemp()

    def tearDown(self):
        clearPresetManagerPaths(self.manager)

    def createOtherManager(self):
        other_manager = AudioPresetManager()
        other_manager.user_path = self.manager.user_path
        return other_manager

    def testSaveAndLoad(self):
        self.manager.createPreset("Vegeta",
                                  {"channels": 6000,
                                   "sample-rate": 44100})
        self.manager.saveAll()
        self.assertEqual(1, countUserPresets(self.manager))

        self.manager.createPreset("Nappa",
                                  {"channels": 4000,
                                   "sample-rate": 44100})
        self.manager.saveAll()
        self.assertEqual(2, countUserPresets(self.manager))

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        total_presets = countDefaultPresets(
            self.manager) + countUserPresets(self.manager)
        self.assertEqual(total_presets, len(other_manager.presets))

    def testNonAsciiFilenamesSaveAndLoad(self):
        non_ascii_preset_name = "Solid Snake (ソリッド・スネーク) \\#!\"'$%?&*"
        self.manager.createPreset(non_ascii_preset_name,
                                  {"channels": 2,
                                   "sample-rate": 44100})
        snake = self.manager.presets[non_ascii_preset_name]
        self.assertEqual(2, len(snake))
        self.manager.saveAll()

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        self.assertEqual(1 + countDefaultPresets(
            other_manager), len(other_manager.presets))
        snaaaake = other_manager.presets[non_ascii_preset_name]
        self.assertEqual(snake, snaaaake)

    def testInvalidFilenamesSaveAndLoad(self):
        # This would be an invalid file name as is.
        preset_name = " / % "
        self.manager.createPreset(preset_name,
                                  {"channels": 2,
                                   "sample-rate": 44100})
        values = self.manager.presets[preset_name]
        self.assertEqual(2, len(values))
        self.manager.saveAll()

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        self.assertEqual(1 + countDefaultPresets(
            other_manager), len(other_manager.presets))
        other_values = other_manager.presets[preset_name]
        self.assertEqual(values, other_values)

    def testRemovingSystemPresets(self):
        self.manager.loadAll()
        system_presets = list(self.manager.presets.keys())
        for preset_name in system_presets:
            self.manager.restorePreset(preset_name)
            self.manager.removeCurrentPreset()

        # Check that the files have not been deleted or changed.
        other_manager = AudioPresetManager()
        other_manager.user_path = "/pitivi/non/existing/directory"
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertTrue(other_manager.hasPreset(preset_name))

        # Check that overwrite files have been created and
        # they mark the system presets as deleted.
        other_manager = self.createOtherManager()
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertFalse(other_manager.hasPreset(preset_name))

    def testRenamingSystemPresets(self):
        self.manager.loadAll()
        system_presets = list(self.manager.presets.keys())
        new_name_template = "%s new"
        for preset_name in system_presets:
            self.manager.restorePreset(preset_name)
            new_name = new_name_template % preset_name
            self.manager.saveCurrentPreset(new_name)

        # Check that the files have not been deleted or changed.
        other_manager = AudioPresetManager()
        other_manager.user_path = "/pitivi/non/existing/directory"
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertTrue(other_manager.hasPreset(preset_name), preset_name)

        other_manager = self.createOtherManager()
        other_manager.loadAll()
        for preset_name in system_presets:
            self.assertFalse(other_manager.hasPreset(preset_name), preset_name)
            new_name = new_name_template % preset_name
            self.assertTrue(other_manager.hasPreset(new_name), new_name)