From 7bb4a1a5f31341250a5242187db1d5f935dce62f Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Wed, 27 Jul 2022 09:30:31 -0600 Subject: [PATCH] keyboard: restructure unit test for async --- .../server/controllers/tests/test_keyboard.py | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/subiquity/server/controllers/tests/test_keyboard.py b/subiquity/server/controllers/tests/test_keyboard.py index 3bf56763..820ce2fb 100644 --- a/subiquity/server/controllers/tests/test_keyboard.py +++ b/subiquity/server/controllers/tests/test_keyboard.py @@ -13,10 +13,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import asyncio import os -import tempfile -import unittest + +from subiquitycore.tests import SubiTestCase from subiquity.models.keyboard import ( KeyboardModel, @@ -31,26 +30,17 @@ class opts: dry_run = True -class TestSubiquityModel(unittest.TestCase): +class TestSubiquityModel(SubiTestCase): - def test_write_config(self): - loop = asyncio.new_event_loop() - policy = asyncio.get_event_loop_policy() - watcher = asyncio.SafeChildWatcher() - watcher.attach_loop(loop) - policy.set_child_watcher(watcher) - - async def t(): - os.environ['SUBIQUITY_REPLAY_TIMESCALE'] = '100' - with tempfile.TemporaryDirectory() as tmpdir: - new_setting = KeyboardSetting('fr', 'azerty') - model = KeyboardModel(tmpdir) - model.setting = new_setting - c = object.__new__(KeyboardController) - c.opts = opts - c.model = model - await c.set_keyboard() - read_setting = KeyboardModel(tmpdir).setting - self.assertEqual(new_setting, read_setting) - loop.run_until_complete(t()) - loop.close() + async def test_write_config(self): + os.environ['SUBIQUITY_REPLAY_TIMESCALE'] = '100' + new_setting = KeyboardSetting('fr', 'azerty') + tmpdir = self.tmp_dir() + model = KeyboardModel(tmpdir) + model.setting = new_setting + c = object.__new__(KeyboardController) + c.opts = opts + c.model = model + await c.set_keyboard() + read_setting = KeyboardModel(tmpdir).setting + self.assertEqual(new_setting, read_setting)