コード例 #1
0
ファイル: test_preset.py プロジェクト: kyotobay/pitivi
    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))
コード例 #2
0
ファイル: test_preset.py プロジェクト: kyotobay/pitivi
    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))