From db880bbc03c2c27525fd6ab3a252aeb091e924bd Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Mon, 16 Nov 2020 14:08:42 +0100 Subject: [PATCH] test delete_preset --- keymapper/presets.py | 1 - tests/testcases/presets.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/keymapper/presets.py b/keymapper/presets.py index 47b2daed..15ca36db 100644 --- a/keymapper/presets.py +++ b/keymapper/presets.py @@ -75,7 +75,6 @@ def find_newest_preset(device=None): device : string If set, will return the newest preset for the device or None """ - print('find_newest_preset') # sort the oldest files to the front in order to use pop to get the newest if device is None: paths = sorted( diff --git a/tests/testcases/presets.py b/tests/testcases/presets.py index 830790a3..4bd1d0d1 100644 --- a/tests/testcases/presets.py +++ b/tests/testcases/presets.py @@ -24,7 +24,8 @@ import unittest import shutil import time -from keymapper.presets import find_newest_preset, rename_preset +from keymapper.presets import find_newest_preset, rename_preset, \ + get_any_preset, delete_preset from keymapper.X import create_preset from keymapper.paths import USERS_SYMBOLS @@ -37,7 +38,9 @@ class TestCreatePreset(unittest.TestCase): shutil.rmtree(tmp) def test_create_preset_1(self): + self.assertEqual(get_any_preset(), ('device 1', None)) create_preset('device 1') + self.assertEqual(get_any_preset(), ('device 1', 'new preset')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset')) def test_create_preset_2(self): @@ -47,20 +50,48 @@ class TestCreatePreset(unittest.TestCase): self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset_2')) def test_create_preset_3(self): + create_preset('device 1', 'pre set') create_preset('device 1', 'pre set') create_preset('device 1', 'pre set') self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/pre_set')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/pre_set_2')) + self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/pre_set_3')) + + +class TestDeletePreset(unittest.TestCase): + def setUp(self): + if os.path.exists(tmp): + shutil.rmtree(tmp) + + def test_delete_preset(self): + create_preset('device 1') + create_preset('device 1') + self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset')) + delete_preset('device 1', 'new preset') + self.assertFalse(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset')) + self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1')) + delete_preset('device 1', 'new preset 2') + self.assertFalse(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset')) + self.assertFalse(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset_2')) + # if no preset in the directory, remove the directory + self.assertFalse(os.path.exists(f'{USERS_SYMBOLS}/device_1')) class TestRenamePreset(unittest.TestCase): + def setUp(self): + if os.path.exists(tmp): + shutil.rmtree(tmp) + def test_rename_preset(self): create_preset('device 1', 'preset 1') + create_preset('device 1', 'preset 2') create_preset('device 1', 'foobar') rename_preset('device 1', 'preset 1', 'foobar') + rename_preset('device 1', 'preset 2', 'foobar') self.assertFalse(os.path.exists(f'{USERS_SYMBOLS}/device_1/preset_1')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/foobar')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/foobar_2')) + self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/foobar_3')) class TestFindPresets(unittest.TestCase):