diff --git a/tests/testcases/test_config.py b/tests/testcases/test_config.py index ed6985be..704095a8 100644 --- a/tests/testcases/test_config.py +++ b/tests/testcases/test_config.py @@ -44,6 +44,22 @@ class TestConfig(unittest.TestCase): self.assertTrue(os.path.exists(new)) self.assertFalse(os.path.exists(old)) + def test_wont_migrate(self): + old = os.path.join(CONFIG_PATH, 'config') + new = os.path.join(CONFIG_PATH, 'config.json') + + touch(new) + with open(new, 'w') as f: + f.write('{}') + + touch(old) + with open(old, 'w') as f: + f.write('{}') + + GlobalConfig() + self.assertTrue(os.path.exists(new)) + self.assertTrue(os.path.exists(old)) + def test_get_default(self): config._config = {} self.assertEqual(config.get('gamepad.joystick.non_linearity'), 4) diff --git a/tests/testcases/test_presets.py b/tests/testcases/test_presets.py index 5e80afff..75b36b65 100644 --- a/tests/testcases/test_presets.py +++ b/tests/testcases/test_presets.py @@ -27,7 +27,7 @@ import time from keymapper.presets import find_newest_preset, rename_preset, \ get_any_preset, delete_preset, get_available_preset_name, get_presets, \ migrate_path -from keymapper.paths import CONFIG_PATH, get_preset_path, touch +from keymapper.paths import CONFIG_PATH, get_preset_path, touch, mkdir from keymapper.state import custom_mapping from tests.test import tmp @@ -58,6 +58,24 @@ class TestMigrate(unittest.TestCase): self.assertTrue(os.path.exists(os.path.join(tmp, 'presets', 'foo1', 'bar1.json'))) self.assertTrue(os.path.exists(os.path.join(tmp, 'presets', 'foo2', 'bar2.json'))) + def test_doesnt_migrate(self): + if os.path.exists(tmp): + shutil.rmtree(tmp) + + touch(os.path.join(tmp, 'foo1', 'bar1.json')) + touch(os.path.join(tmp, 'foo2', 'bar2.json')) + + # already migrated + mkdir(os.path.join(tmp, 'presets')) + + migrate_path() + + self.assertTrue(os.path.exists(os.path.join(tmp, 'foo1', 'bar1.json'))) + self.assertTrue(os.path.exists(os.path.join(tmp, 'foo2', 'bar2.json'))) + + self.assertFalse(os.path.exists(os.path.join(tmp, 'presets', 'foo1', 'bar1.json'))) + self.assertFalse(os.path.exists(os.path.join(tmp, 'presets', 'foo2', 'bar2.json'))) + class TestCreatePreset(unittest.TestCase): def tearDown(self):