keyboard: restructure unit test for async
This commit is contained in:
parent
57fb6b8072
commit
7bb4a1a5f3
|
@ -13,10 +13,9 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
import unittest
|
from subiquitycore.tests import SubiTestCase
|
||||||
|
|
||||||
from subiquity.models.keyboard import (
|
from subiquity.models.keyboard import (
|
||||||
KeyboardModel,
|
KeyboardModel,
|
||||||
|
@ -31,26 +30,17 @@ class opts:
|
||||||
dry_run = True
|
dry_run = True
|
||||||
|
|
||||||
|
|
||||||
class TestSubiquityModel(unittest.TestCase):
|
class TestSubiquityModel(SubiTestCase):
|
||||||
|
|
||||||
def test_write_config(self):
|
async def test_write_config(self):
|
||||||
loop = asyncio.new_event_loop()
|
os.environ['SUBIQUITY_REPLAY_TIMESCALE'] = '100'
|
||||||
policy = asyncio.get_event_loop_policy()
|
new_setting = KeyboardSetting('fr', 'azerty')
|
||||||
watcher = asyncio.SafeChildWatcher()
|
tmpdir = self.tmp_dir()
|
||||||
watcher.attach_loop(loop)
|
model = KeyboardModel(tmpdir)
|
||||||
policy.set_child_watcher(watcher)
|
model.setting = new_setting
|
||||||
|
c = object.__new__(KeyboardController)
|
||||||
async def t():
|
c.opts = opts
|
||||||
os.environ['SUBIQUITY_REPLAY_TIMESCALE'] = '100'
|
c.model = model
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
await c.set_keyboard()
|
||||||
new_setting = KeyboardSetting('fr', 'azerty')
|
read_setting = KeyboardModel(tmpdir).setting
|
||||||
model = KeyboardModel(tmpdir)
|
self.assertEqual(new_setting, read_setting)
|
||||||
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()
|
|
||||||
|
|
Loading…
Reference in New Issue