test delete_preset

This commit is contained in:
sezanzeb 2020-11-16 14:08:42 +01:00
parent c7abc1a19c
commit db880bbc03
2 changed files with 32 additions and 2 deletions

View File

@ -75,7 +75,6 @@ def find_newest_preset(device=None):
device : string device : string
If set, will return the newest preset for the device or None 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 # sort the oldest files to the front in order to use pop to get the newest
if device is None: if device is None:
paths = sorted( paths = sorted(

View File

@ -24,7 +24,8 @@ import unittest
import shutil import shutil
import time 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.X import create_preset
from keymapper.paths import USERS_SYMBOLS from keymapper.paths import USERS_SYMBOLS
@ -37,7 +38,9 @@ class TestCreatePreset(unittest.TestCase):
shutil.rmtree(tmp) shutil.rmtree(tmp)
def test_create_preset_1(self): def test_create_preset_1(self):
self.assertEqual(get_any_preset(), ('device 1', None))
create_preset('device 1') 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')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset'))
def test_create_preset_2(self): 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')) self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/new_preset_2'))
def test_create_preset_3(self): def test_create_preset_3(self):
create_preset('device 1', 'pre set')
create_preset('device 1', 'pre set') 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'))
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_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): class TestRenamePreset(unittest.TestCase):
def setUp(self):
if os.path.exists(tmp):
shutil.rmtree(tmp)
def test_rename_preset(self): def test_rename_preset(self):
create_preset('device 1', 'preset 1') create_preset('device 1', 'preset 1')
create_preset('device 1', 'preset 2')
create_preset('device 1', 'foobar') create_preset('device 1', 'foobar')
rename_preset('device 1', 'preset 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.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'))
self.assertTrue(os.path.exists(f'{USERS_SYMBOLS}/device_1/foobar_2')) 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): class TestFindPresets(unittest.TestCase):