From 8a6ddda7c89d22845675a1aac50f382c9f20616f Mon Sep 17 00:00:00 2001 From: gryf Date: Sun, 8 Jan 2017 11:21:43 +0100 Subject: [PATCH] Make plain wrapper module use base.Base class --- fs_uae_wrapper/plain.py | 34 +++++++++++++++++----------------- tests/test_plain.py | 12 ++++++++---- tests/test_wrapper.py | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fs_uae_wrapper/plain.py b/fs_uae_wrapper/plain.py index b1aa737..3f34b83 100644 --- a/fs_uae_wrapper/plain.py +++ b/fs_uae_wrapper/plain.py @@ -4,24 +4,24 @@ Simple class for executing fs-uae with specified parameters. This is a failsafe class for running fs-uae. """ -import subprocess -import sys +from fs_uae_wrapper import base +from fs_uae_wrapper import utils -def run_plain(conf_file, fs_uae_options): - """ - Run the emulation. - conf_file is a path to the configuration, - fs_uae_options is an dict-like object which contains commandline options to - be passed to fs-uae - """ - try: - subprocess.call(['fs-uae'] + [conf_file] + fs_uae_options.list()) - except subprocess.CalledProcessError: - sys.stderr.write('Warning: fs-uae returned non 0 exit code\n') - return True +class Wrapper(base.Base): + """Simple class for running fs-uae""" + def run(self): + """ + Main function which run FS-UAE + """ + self._run_emulator() -def run(config_file, fs_uae_options, _): - """Run fs-uae with provided config file and options""" - return run_plain(config_file, fs_uae_options) + def _run_emulator(self): + """execute fs-uae""" + utils.run_command(['fs-uae'] + [self.conf_file] + + self.fsuae_options.list()) + + def clean(self): + """Do the cleanup. Here - just do nothing""" + return diff --git a/tests/test_plain.py b/tests/test_plain.py index a3ce542..c582557 100644 --- a/tests/test_plain.py +++ b/tests/test_plain.py @@ -11,8 +11,12 @@ from fs_uae_wrapper import utils class TestPlainModule(TestCase): - @mock.patch('subprocess.call') - def test_show(self, subprocess_call): + @mock.patch('fs_uae_wrapper.utils.run_command') + def test_run(self, run_command): + wrapper = plain.Wrapper('some.conf', utils.CmdOption(), {}) + wrapper.run() + run_command.assert_called_once_with(['fs-uae', 'some.conf']) - plain.run('some.conf', utils.CmdOption(), None) - subprocess_call.assert_called_once() + def test_clean(self): + wrapper = plain.Wrapper('some.conf', utils.CmdOption(), {}) + self.assertIsNone(wrapper.clean()) diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 42b099e..9929754 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -28,7 +28,7 @@ class TestWrapper(TestCase): os.unlink(self.fname) sys.argv = self._argv[:] - @mock.patch('fs_uae_wrapper.plain.run') + @mock.patch('fs_uae_wrapper.plain.Wrapper.run') def test_run(self, mock_plain_run): sys.argv.append('--help')