mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-02 15:40:19 +00:00
cloning mappings
This commit is contained in:
parent
ed48306f7f
commit
1a16d679cf
@ -160,12 +160,11 @@ class Mapping:
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of the mapping."""
|
||||
# TODO test
|
||||
mapping = Mapping()
|
||||
mapping._mapping = copy.deepcopy(self._mapping)
|
||||
mapping.update_reverse_mapping()
|
||||
mapping.changed = self.changed
|
||||
return Mapping()
|
||||
return mapping
|
||||
|
||||
def save(self, device, preset):
|
||||
"""Dump as JSON into home."""
|
||||
|
@ -23,7 +23,6 @@ import unittest
|
||||
|
||||
from keymapper.mapping import Mapping
|
||||
from keymapper.state import parse_xmodmap
|
||||
from keymapper.paths import get_config_path
|
||||
|
||||
|
||||
class TestMapping(unittest.TestCase):
|
||||
@ -38,6 +37,22 @@ class TestMapping(unittest.TestCase):
|
||||
self.assertEqual(self.mapping.get_keycode('1'), 10)
|
||||
self.assertTrue(self.mapping.get_character(10).startswith('1'))
|
||||
|
||||
def test_clone(self):
|
||||
mapping1 = Mapping()
|
||||
mapping1.change(1, 'a')
|
||||
mapping2 = mapping1.clone()
|
||||
mapping1.change(2, 'b')
|
||||
|
||||
self.assertEqual(mapping1.get_character(1), 'a')
|
||||
self.assertEqual(mapping1.get_keycode('a'), 1)
|
||||
self.assertEqual(mapping1.get_character(2), 'b')
|
||||
self.assertEqual(mapping1.get_keycode('b'), 2)
|
||||
|
||||
self.assertEqual(mapping2.get_character(1), 'a')
|
||||
self.assertEqual(mapping2.get_keycode('a'), 1)
|
||||
self.assertIsNone(mapping2.get_character(2))
|
||||
self.assertIsNone(mapping2.get_keycode('b'))
|
||||
|
||||
def test_save_load(self):
|
||||
self.mapping.change(10, '1')
|
||||
self.mapping.change(11, '2')
|
||||
|
Loading…
Reference in New Issue
Block a user