Skip to content

Commit

Permalink
tests: move create_*_file to SystemTestsMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarek committed Jun 20, 2017
1 parent f56f7d1 commit 984a070
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
11 changes: 11 additions & 0 deletions qubes/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import logging
import os
import pathlib
import shlex
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -962,6 +963,16 @@ def prepare_hvm_system_linux(self, vm, init_script, extra_files=None):
shutil.rmtree(mountpoint)
subprocess.check_call(['sudo', 'losetup', '-d', loopdev])

def create_local_file(self, filename, content, mode='w'):
with open(filename, mode) as file:
file.write(content)
self.addCleanup(os.unlink, filename)

def create_remote_file(self, vm, filename, content):
self.loop.run_until_complete(vm.run_for_stdio(
'cat > {}'.format(shlex.quote(filename)),
user='root', input=content.encode('utf-8')))


def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
# discard any tests from this module, because it hosts base classes
Expand Down
16 changes: 1 addition & 15 deletions qubes/tests/integ/vm_qrexec_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from distutils import spawn

import asyncio
import multiprocessing
import os
import shlex
import subprocess
import time
import unittest
from distutils import spawn

import qubes.config
import qubes.tests
import qubes.vm.appvm
import qubes.vm.templatevm
import re

TEST_DATA = b"0123456789" * 1024

Expand All @@ -59,16 +55,6 @@ def setUp(self):
self.loop.run_until_complete(self.testvm2.create_on_disk())
self.app.save()

def create_local_file(self, filename, content, mode='w'):
with open(filename, mode) as file:
file.write(content)
self.addCleanup(os.unlink, filename)

def create_remote_file(self, vm, filename, content):
self.loop.run_until_complete(vm.run_for_stdio(
'cat > {}'.format(shlex.quote(filename)),
user='root', input=content.encode('utf-8')))

def test_000_start_shutdown(self):
# TODO: wait_for, timeout
self.loop.run_until_complete(self.testvm1.start())
Expand Down
2 changes: 1 addition & 1 deletion tests/pvgrub.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ def load_tests(loader, tests, pattern):
'TC_40_PVGrub_' + template,
(TC_40_PVGrub, qubes.tests.QubesTestCase),
{'template': template})))
return tests
return tests

0 comments on commit 984a070

Please sign in to comment.