def testGetUniquePresetName(self): preset_manager = PresetManager() name = ProjectSettingsDialog._getUniquePresetName(preset_manager) self.assertEqual('New preset', name) preset_manager.addPreset(name, {}) new_preset1 = ProjectSettingsDialog._getUniquePresetName(preset_manager) self.assertEqual('New preset 1', new_preset1) # Intentionally add 'New preset 2' before 'New preset 1'. preset_manager.addPreset('New preset 2', {}) preset_manager.addPreset('New preset 1', {}) new_preset3 = ProjectSettingsDialog._getUniquePresetName(preset_manager) self.assertEqual('New preset 3', new_preset3)
class TestPresetBasics(TestCase): def setUp(self): self.manager = PresetManager() self.user_path = tempfile.mkdtemp() self.manager.user_path = self.user_path # Keep PresetManager happy def tearDown(self): # Delete the user directory we created (but not the default directory) shutil.rmtree(self.user_path) def testConvertPresetNameToSectionName(self): self.presetToSection = self.manager._convertPresetNameToSectionName self.assertEqual("my preset", self.presetToSection('my preset')) self.assertEqual("my preset_", self.presetToSection('my preset_')) self.assertEqual("default_x_", self.presetToSection('default_x_')) # Test that default_* preset names get a _ character at the end. self.assertEqual("Default_", self.presetToSection('Default')) self.assertEqual("defaulT__", self.presetToSection('defaulT_')) def testConvertSectionNameToPresetName(self): self.sectionToPreset = self.manager._convertSectionNameToPresetName self.assertEqual("my preset", self.sectionToPreset('my preset')) self.assertEqual("my preset_", self.sectionToPreset('my preset_')) self.assertEqual("default_x_", self.sectionToPreset('default_x_')) # Test that default_+ section names lose the last character. self.assertEqual("Default", self.sectionToPreset('Default_')) self.assertEqual("defaulT_", self.sectionToPreset('defaulT__')) def testAddPreset(self): self.manager.addPreset('preseT onE', {'name1': '1A'}) self.assertRaises(DuplicatePresetNameException, self.manager.addPreset, 'Preset One', {'name1': '2A'}) def testRenamePreset(self): self.manager.addPreset('preseT onE', {'name1': '1A'}) self.manager.addPreset('Preset Two', {'name1': '2A'}) # Renaming 'preseT onE' to 'Preset One'. self.manager.renamePreset('0', 'Preset One') # Renaming 'Preset One' to 'Preset TWO'. self.assertRaises(DuplicatePresetNameException, self.manager.renamePreset, '0', 'Preset TWO') # Renaming 'Preset One' to 'Preset two'. self.assertRaises(DuplicatePresetNameException, self.manager.renamePreset, '0', 'Preset two')
def setUp(self): self.manager = PresetManager(None, tempfile.mkdtemp(), System()) self.manager._serializePreset = lambda preset: dict(preset.items())
class TestPresetBasics(common.TestCase): def setUp(self): self.manager = PresetManager(None, tempfile.mkdtemp(), System()) self.manager._serializePreset = lambda preset: dict(preset.items()) def tearDown(self): clearPresetManagerPaths(self.manager) def testAddPreset(self): self.manager.createPreset('preseT onE', {'name1': '1A'}) self.manager.createPreset('Preset One', {'name1': '2A'}) self.assertEqual(2, len(self.manager.presets)) def testAddPresetWithNonAsciiName(self): unicode_name = "ソリッド・スネーク" self.manager.createPreset(unicode_name, {}) self.assertTrue(unicode_name in self.manager.getPresetNames()) def testRenamePreset(self): self.manager.createPreset('preseT onE', {'name1': '1A'}) self.manager.createPreset('Preset Two', {'name1': '2A'}) self.assertEqual(2, len(self.manager.presets)) self.manager.restorePreset('preseT onE') self.manager.saveCurrentPreset('Preset One') self.assertEqual(2, len(self.manager.presets)) self.manager.saveCurrentPreset('Preset TWO') self.assertEqual(2, len(self.manager.presets)) self.manager.saveCurrentPreset('Preset two') self.assertEqual(2, len(self.manager.presets)) self.manager.saveCurrentPreset('Preset Two') self.assertEqual(1, len(self.manager.presets)) self.manager.saveCurrentPreset('Preset Two') self.assertEqual(1, len(self.manager.presets)) self.manager.saveCurrentPreset('preseT onE') self.assertEqual(1, len(self.manager.presets)) def testLoadHandlesMissingDirectory(self): self.manager.default_path = '/pitivi/non/existing/directory/1' self.manager.user_path = '/pitivi/non/existing/directory/2' self.manager.loadAll() def testGetUniquePresetName(self): name = self.manager.getNewPresetName() self.assertEqual('New preset', name) self.manager.createPreset(name, {}) new_preset1 = self.manager.getNewPresetName() self.assertEqual('New preset 1', new_preset1) # Intentionally add 'New preset 2' before 'New preset 1'. self.manager.createPreset('New preset 2', {}) self.manager.createPreset('New preset 1', {}) new_preset3 = self.manager.getNewPresetName() self.assertEqual('New preset 3', new_preset3)
def __init__(self, default_path): PresetManager.__init__(self, default_path, tempfile.mkdtemp())
def setUp(self): self.manager = PresetManager() self.user_path = tempfile.mkdtemp() self.manager.user_path = self.user_path # Keep PresetManager happy
class TestPresetBasics(common.TestCase): def setUp(self): self.manager = PresetManager(None, tempfile.mkdtemp(), System()) self.manager._serialize_preset = lambda preset: dict(preset.items()) def tearDown(self): clear_preset_manager_paths(self.manager) def test_add_preset(self): self.manager.create_preset('preseT onE', {'name1': '1A'}) self.manager.create_preset('Preset One', {'name1': '2A'}) self.assertEqual(2, len(self.manager.presets)) def test_add_preset_with_non_ascii_name(self): unicode_name = "ソリッド・スネーク" self.manager.create_preset(unicode_name, {}) self.assertTrue(unicode_name in self.manager.get_preset_names()) def test_rename_preset(self): self.manager.create_preset('preseT onE', {'name1': '1A'}) self.manager.create_preset('Preset Two', {'name1': '2A'}) self.assertEqual(2, len(self.manager.presets)) self.manager.restore_preset('preseT onE') self.manager.save_current_preset('Preset One') self.assertEqual(2, len(self.manager.presets)) self.manager.save_current_preset('Preset TWO') self.assertEqual(2, len(self.manager.presets)) self.manager.save_current_preset('Preset two') self.assertEqual(2, len(self.manager.presets)) self.manager.save_current_preset('Preset Two') self.assertEqual(1, len(self.manager.presets)) self.manager.save_current_preset('Preset Two') self.assertEqual(1, len(self.manager.presets)) self.manager.save_current_preset('preseT onE') self.assertEqual(1, len(self.manager.presets)) def test_load_handles_missing_directory(self): self.manager.default_path = '/pitivi/non/existing/directory/1' self.manager.user_path = '/pitivi/non/existing/directory/2' self.manager.load_all() def test_get_unique_preset_name(self): name = self.manager.get_new_preset_name() self.assertEqual('New preset', name) self.manager.create_preset(name, {}) new_preset1 = self.manager.get_new_preset_name() self.assertEqual('New preset 1', new_preset1) # Intentionally add 'New preset 2' before 'New preset 1'. self.manager.create_preset('New preset 2', {}) self.manager.create_preset('New preset 1', {}) new_preset3 = self.manager.get_new_preset_name() self.assertEqual('New preset 3', new_preset3)