tests: do not rely on gedit being the default editor

Handle gedit, emacs and vim.
This commit is contained in:
Marek Marczykowski-Górecki 2015-03-30 16:18:09 +02:00
parent 5c59067676
commit cba8c6430c

View File

@ -500,6 +500,37 @@ class TC_20_DispVMMixin(qubes.tests.SystemTestsMixin):
self.assertIsNone(self.qc.get_vm_by_name(dispvm.name), self.assertIsNone(self.qc.get_vm_by_name(dispvm.name),
"DispVM not removed from qubes.xml") "DispVM not removed from qubes.xml")
def _handle_editor(self, winid):
(window_title, _) = subprocess.Popen(
['xdotool', 'getwindowname', winid], stdout=subprocess.PIPE).\
communicate()
window_title = window_title.strip().\
replace('(', '\(').replace(')', '\)')
time.sleep(1)
if "gedit" in window_title:
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'windowactivate', 'type', 'test test 2\n'])
time.sleep(0.5)
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'key', 'ctrl+s', 'ctrl+q'])
elif "emacs" in window_title:
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'windowactivate', 'type', 'test test 2\n'])
time.sleep(0.5)
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'key', 'ctrl+x', 'ctrl+s'])
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'key', 'ctrl+x', 'ctrl+c'])
elif "vim" in window_title:
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'windowactivate', 'key', 'i',
'type', 'test test 2\n'])
subprocess.check_call(
['xdotool', 'search', '--name', window_title,
'key', 'Escape', 'colon', 'w', 'q', 'Return'])
else:
self.fail("Unknown editor window: {}".format(window_title))
@unittest.skipUnless(spawn.find_executable('xdotool'), @unittest.skipUnless(spawn.find_executable('xdotool'),
"xdotool not installed") "xdotool not installed")
def test_030_edit_file(self): def test_030_edit_file(self):
@ -517,30 +548,28 @@ class TC_20_DispVMMixin(qubes.tests.SystemTestsMixin):
passio_popen=True) passio_popen=True)
wait_count = 0 wait_count = 0
# TODO: ensure that gedit is default editor? winid = None
window_title = '(/tmp/%s)' % self.testvm1.name while True:
while subprocess.call(['xdotool', 'search', '--name', window_title], search = subprocess.Popen(['xdotool', 'search',
stdout=open(os.path.devnull, 'w'), '--onlyvisible', '--class', 'disp*'],
stderr=subprocess.STDOUT) > 0: stdout=subprocess.PIPE,
stderr=open(os.path.devnull, 'w'))
retcode = search.wait()
if retcode == 0:
winid = search.stdout.read().strip()
break
wait_count += 1 wait_count += 1
if wait_count > 100: if wait_count > 100:
self.fail("Timeout while waiting for editor window") self.fail("Timeout while waiting for editor window")
time.sleep(0.3) time.sleep(0.3)
time.sleep(0.5) self._handle_editor(winid)
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'windowactivate', 'type', 'test test 2\n'])
time.sleep(0.5)
subprocess.check_call(['xdotool', 'search', '--name', window_title,
'key', 'ctrl+s', 'ctrl+q'])
p.wait() p.wait()
p = self.testvm1.run("cat /home/user/test.txt", p = self.testvm1.run("cat /home/user/test.txt",
passio_popen=True) passio_popen=True)
(test_txt_content, _) = p.communicate() (test_txt_content, _) = p.communicate()
self.assertEqual(test_txt_content, "test test 2\ntest1\n") self.assertEqual(test_txt_content, "test test 2\ntest1\n")
def load_tests(loader, tests, pattern): def load_tests(loader, tests, pattern):
try: try:
qc = qubes.qubes.QubesVmCollection() qc = qubes.qubes.QubesVmCollection()