mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2025-12-26 16:32:37 +01:00
Added additional tests for cd32 module
Also, new command was added to utils - run_command which is an generalized subprocess.call function. Requirements is now added with module six, which was needed to detect string-like objects in sane way.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
from tempfile import mkstemp, mkdtemp
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -18,6 +17,7 @@ class TestCD32(TestCase):
|
||||
def setUp(self):
|
||||
fd, self.fname = mkstemp()
|
||||
self.dirname = mkdtemp()
|
||||
self.confdir = mkdtemp()
|
||||
os.close(fd)
|
||||
self._argv = sys.argv[:]
|
||||
sys.argv = ['fs-uae-wrapper']
|
||||
@@ -29,6 +29,10 @@ class TestCD32(TestCase):
|
||||
shutil.rmtree(self.dirname)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
shutil.rmtree(self.confdir)
|
||||
except OSError:
|
||||
pass
|
||||
os.unlink(self.fname)
|
||||
sys.argv = self._argv[:]
|
||||
|
||||
@@ -119,17 +123,62 @@ class TestCD32(TestCase):
|
||||
self.assertFalse(acd32._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, '1', 'arch.7z')
|
||||
|
||||
@mock.patch('subprocess.call')
|
||||
def test_run_game(self, sub_call):
|
||||
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||
def test_run_game(self, run):
|
||||
|
||||
acd32 = cd32.CD32()
|
||||
acd32.dir = self.dirname
|
||||
|
||||
self.assertTrue(acd32._run_game([]))
|
||||
sub_call.assert_called_once_with(['fs-uae'])
|
||||
run.assert_called_once_with(['fs-uae'])
|
||||
|
||||
# Errors from emulator are not fatal to wrappers
|
||||
sub_call.reset_mock()
|
||||
sub_call.side_effect = subprocess.CalledProcessError(2, 'fs-uae')
|
||||
run.reset_mock()
|
||||
run.return_value = False
|
||||
self.assertTrue(acd32._run_game([]))
|
||||
sub_call.assert_called_once_with(['fs-uae'])
|
||||
run.assert_called_once_with(['fs-uae'])
|
||||
|
||||
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||
def test_save_save(self, run):
|
||||
|
||||
acd32 = cd32.CD32()
|
||||
acd32.dir = self.dirname
|
||||
acd32.save_filename = "foobar_save.7z"
|
||||
run.return_value = 0
|
||||
|
||||
self.assertTrue(acd32._save_save())
|
||||
|
||||
os.chdir(self.confdir)
|
||||
with open(acd32.save_filename, 'w') as fobj:
|
||||
fobj.write('asd')
|
||||
|
||||
self.assertTrue(acd32._save_save())
|
||||
|
||||
os.mkdir(os.path.join(self.dirname, 'fs-uae-save'))
|
||||
self.assertTrue(acd32._save_save())
|
||||
|
||||
run.return_value = 1
|
||||
self.assertFalse(acd32._save_save())
|
||||
|
||||
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||
def test_load_save(self, run):
|
||||
|
||||
acd32 = cd32.CD32()
|
||||
acd32.dir = self.dirname
|
||||
acd32.save_filename = "foobar_save.7z"
|
||||
run.return_value = 0
|
||||
|
||||
# fail to load save is not fatal
|
||||
self.assertTrue(acd32._load_save())
|
||||
|
||||
os.chdir(self.confdir)
|
||||
with open(acd32.save_filename, 'w') as fobj:
|
||||
fobj.write('asd')
|
||||
|
||||
self.assertTrue(acd32._load_save())
|
||||
run.assert_called_once_with(['7z', 'x', acd32.save_filename])
|
||||
|
||||
# failure in searching for archiver are also non fatal
|
||||
run.reset_mock()
|
||||
run.return_value = 1
|
||||
self.assertTrue(acd32._save_save())
|
||||
|
||||
Reference in New Issue
Block a user