Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
    def testEsotericFilenames(self):
        self.manager.addPreset("Default",
            {"channels": 2,
            "depth": -9000,
            "sample-rate": 44100,
            "filepath": os.path.join(self.user_path, "Default.json")})
        self.manager.saveAll()

        self.manager.addPreset('Solid Snake (ソリッド・スネーク) \#!"/$%?&*',
            {"name": "デイビッド",
            "channels": 2,
            "depth": 16,
            "sample-rate": 44100,
            "filepath": os.path.join(self.user_path,
                'Solid Snake (ソリッド・スネーク) \#!"/$%?&*' + ".json")})
        snake = self.manager.presets['Solid Snake (ソリッド・スネーク) \#!"/$%?&*']
        self.assertEqual(5, len(snake))
        # The slash ("/") in the filename is supposed to make it choke
        #self.assertRaises(IOError, self.manager.saveAll)
        # Let's be slightly more gentle
        snake["filepath"] = os.path.join(self.user_path,
                'Solid Snake (ソリッド・スネーク)' + ".json")
        self.manager.saveAll()

        # Create a second concurrent instance with the same paths,
        # to check that it can read and write from the first instance's data
        other_manager = AudioPresetManager()
        other_manager.default_path = self.default_path
        other_manager.user_path = self.user_path
        other_manager.loadAll()

        snaaaake = other_manager.presets['Solid Snake (ソリッド・スネーク)']
        self.assertEqual(2, snaaaake["channels"])

        foo = other_manager.presets['Default']
        self.assertEqual(4, len(foo))
        self.assertEqual(-9000, foo["depth"])

        self.assertEquals(2, len(other_manager.presets))
Beispiel #6
0
 def createOtherManager(self):
     other_manager = AudioPresetManager(System())
     other_manager.user_path = self.manager.user_path
     return other_manager
Beispiel #7
0
 def createOtherManager(self):
     other_manager = AudioPresetManager()
     other_manager.default_path = self.manager.default_path
     other_manager.user_path = self.manager.user_path
     return other_manager
Beispiel #8
0
 def createOtherManager(self):
     other_manager = AudioPresetManager()
     other_manager.default_path = self.manager.default_path
     other_manager.user_path = self.manager.user_path
     return other_manager
Beispiel #9
0
    def testSaveAndLoad(self):

        def countDefaultPresets():
            foo = 0
            for file in os.listdir(self.default_path):
                # This is needed to avoid a miscount with makefiles and such
                if file.endswith(".json"):
                    foo += 1
            return foo

        def countUserPresets():
            return len(os.listdir(self.user_path))

        self.manager.addPreset("Vegeta",
            {"channels": 6000,
            "depth": 16,
            "sample-rate": 44100,
            "filepath": os.path.join(self.user_path, "vegeta.json")})
        self.manager.cur_preset = "Vegeta"
        self.manager.savePreset()
        self.assertEqual(1, countUserPresets())

        self.manager.addPreset("Nappa",
            {"channels": 4000,
            "depth": 16,
            "sample-rate": 44100,
            "filepath": os.path.join(self.user_path, "nappa.json")})

        self.assertEqual(1, countUserPresets())
        self.manager.saveAll()
        self.assertEqual(2, countUserPresets())
        self.assertIn("vegeta.json", os.listdir(self.user_path))
        self.assertIn("nappa.json", os.listdir(self.user_path))

        other_manager = AudioPresetManager()
        other_manager.default_path = self.default_path
        other_manager.user_path = self.user_path
        other_manager.loadAll()

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

        # Test invalid filenames/filepaths

        # Testing with an invalid filepath:
        self.manager.addPreset("Sangoku",
            {"channels": 8001,
            "depth": 32,
            "sample-rate": 44100,
            "filepath": "INVALID FILENAME?!"})
        self.assertEqual(2 + countDefaultPresets(), len(other_manager.presets))
        self.manager.saveAll()
        # The filepath was invalid. It was not actually a path.
        self.assertEqual(2, len(os.listdir(self.user_path)))

        # Testing with an invalid filename:
        self.manager.presets["Sangoku"]["filepath"] = os.path.join(self.user_path,
            "INVALID FILENAME?!")
        self.manager.saveAll()
        # The filepath did not have a ".json" file extension
        # While such a file would be written to disk, it would not be loaded
        self.assertEqual(3, len(os.listdir(self.user_path)))

        # Trying to load all presets multiple times will create duplicates...
        self.assertRaises(DuplicatePresetNameException, other_manager.loadAll)
        # So let's reset it to a clean state:
        other_manager = AudioPresetManager()
        other_manager.default_path = self.default_path
        other_manager.user_path = self.user_path
        other_manager.loadAll()
        # We only expect two valid, loaded presets: nappa and vegeta
        self.assertEqual(2 + countDefaultPresets(), len(other_manager.presets))
Beispiel #10
0
 def createOtherManager(self):
     other_manager = AudioPresetManager(System())
     other_manager.user_path = self.manager.user_path
     return other_manager