mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2026-02-03 06:45:49 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 334b56bad3 | |||
| 6d84fc4b8a | |||
| c5ce27e637 | |||
| ae6e00ea1c | |||
| f1fb43ca64 | |||
| 77cf10cee7 |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
*.pyc
|
||||
*.egg-info
|
||||
.cache
|
||||
.coverage
|
||||
.tox
|
||||
MANIFEST
|
||||
build
|
||||
dist
|
||||
62
README.rst
62
README.rst
@@ -106,6 +106,7 @@ Currently, three wrapper modules are available:
|
||||
- plain
|
||||
- cd32
|
||||
- archive
|
||||
- savestate
|
||||
|
||||
plain
|
||||
-----
|
||||
@@ -139,7 +140,6 @@ Let's see some sample config for a game, which is saved as
|
||||
``ChaosEngine.fs-uae``:
|
||||
|
||||
.. code:: ini
|
||||
:number-lines:
|
||||
|
||||
[config]
|
||||
wrapper = cd32
|
||||
@@ -165,8 +165,7 @@ Next, the invocation of the wrapper would be as follows:
|
||||
|
||||
Now, there several thing will happen:
|
||||
|
||||
- Config file will be read, and wrapper module will be find (because we already
|
||||
put it on line 2)
|
||||
- Config file will be read, and wrapper module will be found
|
||||
- New temporary directory will be created
|
||||
- Archive with game assists will be extracted in that directory
|
||||
- Configuration file will be copied into that directory, and renamed to
|
||||
@@ -204,7 +203,6 @@ Options used:
|
||||
Example configuration:
|
||||
|
||||
.. code:: ini
|
||||
:number-lines:
|
||||
|
||||
[config]
|
||||
wrapper = archive
|
||||
@@ -215,6 +213,13 @@ Example configuration:
|
||||
wrapper_save_state = 1
|
||||
...
|
||||
|
||||
This module is quite useful in two use cases. First is a usual work with
|
||||
Workbench, where there is a need to keep changes of filesystem. Second is the
|
||||
opposite - if there is a need to test some software, but not necessary keep it
|
||||
in a Workbench, than it will act as a temporary copy of the system, so that
|
||||
next time fs-uae will be run, there will be no files of tested software
|
||||
cluttering around.
|
||||
|
||||
And execution is as usual:
|
||||
|
||||
.. code:: shell-session
|
||||
@@ -234,12 +239,49 @@ This module will do several steps (similar as with ``cd32`` wrapper):
|
||||
- optionally create new archive under the same name as the original one and
|
||||
replace it with original one.
|
||||
|
||||
This module is quite useful in two use cases. First is a usual work with
|
||||
Workbench, where there is a need to keep changes of filesystem. Second is the
|
||||
opposite - if there is a need to test some software, but not necessary keep it
|
||||
in a Workbench, than it will act as a temporary copy of the system, so that
|
||||
next time fs-uae will be run, there will be no files of tested software
|
||||
cluttering around.
|
||||
savestate
|
||||
---------
|
||||
|
||||
Options used:
|
||||
|
||||
* ``wrapper`` (required) with ``archive`` as an value
|
||||
* ``wrapper_archiver`` (required) archiver to use for storage save state
|
||||
* ``wrapper_gui_msg`` (optional) if set to "1", will display a graphical
|
||||
message during extracting files
|
||||
|
||||
This module is primarily used to run emulator with read only media attached
|
||||
(like images of floppies or uncompressed CD-ROMs) and its purpose is to
|
||||
preserve save state which will be created as an archive alongside with original
|
||||
configuration file in selected archive format. Note, that there is required to
|
||||
provide ``wrapper_archiver``, since option ``wrapper_save_state`` is implicitly
|
||||
set to value ``1`` in this module.
|
||||
|
||||
Example configuration:
|
||||
|
||||
.. code:: ini
|
||||
:number-lines:
|
||||
|
||||
[config]
|
||||
wrapper = savestate
|
||||
wrapper_archiver = 7z
|
||||
wrapper_gui_msg = 1
|
||||
...
|
||||
|
||||
And execution is as usual:
|
||||
|
||||
.. code:: shell-session
|
||||
|
||||
$ fs-uae-wrapper Sanity-Arte.fs-uae
|
||||
|
||||
The steps would be as follows:
|
||||
|
||||
- create temporary directory
|
||||
- extract save state (if ``wrapper_save_state`` is set to ``1`` and archive
|
||||
with save exists)
|
||||
- copy configuration under name ``Config.fs-uae``
|
||||
- run the fs-uae emulator
|
||||
- optionally create archive with save state (if save state directory place is
|
||||
*not* a global one)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
@@ -6,13 +6,12 @@ the temporary one.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from fs_uae_wrapper import base
|
||||
from fs_uae_wrapper import utils
|
||||
|
||||
|
||||
class Archive(base.Base):
|
||||
class Archive(base.ArchiveBase):
|
||||
"""
|
||||
Class for performing extracting archive, copying emulator files, and
|
||||
cleaning it back again
|
||||
@@ -30,12 +29,6 @@ class Archive(base.Base):
|
||||
- copy configuration
|
||||
- run the emulation
|
||||
- optionally make archive save state
|
||||
|
||||
Params:
|
||||
conf_file: a relative path to provided configuration file
|
||||
fsuae_options: is an CmdOption object created out of command line
|
||||
parameters
|
||||
configuration: is config dictionary created out of config file
|
||||
"""
|
||||
if not super(Archive, self).run():
|
||||
return False
|
||||
@@ -61,17 +54,6 @@ class Archive(base.Base):
|
||||
|
||||
return self._make_archive()
|
||||
|
||||
def _validate_options(self):
|
||||
|
||||
validation_result = super(Archive, self)._validate_options()
|
||||
|
||||
if 'wrapper_archive' not in self.all_options:
|
||||
sys.stderr.write("Configuration lacks of required "
|
||||
"`wrapper_archive' option.\n")
|
||||
validation_result = False
|
||||
|
||||
return validation_result
|
||||
|
||||
def _make_archive(self):
|
||||
"""
|
||||
Produce archive and save it back. Than remove old one.
|
||||
|
||||
@@ -29,7 +29,6 @@ class Base(object):
|
||||
fsuae_options)
|
||||
self.dir = None
|
||||
self.save_filename = None
|
||||
self.arch_filepath = None
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
@@ -46,7 +45,6 @@ class Base(object):
|
||||
return False
|
||||
|
||||
self.dir = tempfile.mkdtemp()
|
||||
|
||||
self._set_assets_paths()
|
||||
|
||||
return True
|
||||
@@ -93,12 +91,6 @@ class Base(object):
|
||||
conf_base = os.path.basename(self.conf_file)
|
||||
conf_base = os.path.splitext(conf_base)[0]
|
||||
|
||||
arch = self.all_options.get('wrapper_archive')
|
||||
if arch:
|
||||
if os.path.isabs(arch):
|
||||
self.arch_filepath = arch
|
||||
else:
|
||||
self.arch_filepath = os.path.join(conf_abs_dir, arch)
|
||||
# set optional save_state
|
||||
arch_ext = utils.get_arch_ext(self.all_options.get('wrapper_archiver'))
|
||||
if arch_ext:
|
||||
@@ -112,16 +104,6 @@ class Base(object):
|
||||
os.path.join(self.dir, 'Config.fs-uae'))
|
||||
return True
|
||||
|
||||
def _extract(self):
|
||||
"""Extract archive to temp dir"""
|
||||
|
||||
title = self._get_title()
|
||||
curdir = os.path.abspath('.')
|
||||
os.chdir(self.dir)
|
||||
result = utils.extract_archive(self.arch_filepath, title)
|
||||
os.chdir(curdir)
|
||||
return result
|
||||
|
||||
def _run_emulator(self, fsuae_options):
|
||||
"""execute fs-uae in provided directory"""
|
||||
curdir = os.path.abspath('.')
|
||||
@@ -232,3 +214,56 @@ class Base(object):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class ArchiveBase(Base):
|
||||
"""
|
||||
Base class for archive based wrapper modules
|
||||
"""
|
||||
def __init__(self, conf_file, fsuae_options, configuration):
|
||||
"""
|
||||
Params:
|
||||
conf_file: a relative path to provided configuration file
|
||||
fsuae_options: is an CmdOption object created out of command line
|
||||
parameters
|
||||
configuration: is config dictionary created out of config file
|
||||
"""
|
||||
super(ArchiveBase, self).__init__(conf_file, fsuae_options,
|
||||
configuration)
|
||||
self.arch_filepath = None
|
||||
|
||||
def _set_assets_paths(self):
|
||||
"""
|
||||
Set full paths for archive file (without extension) and for save state
|
||||
archive file
|
||||
"""
|
||||
super(ArchiveBase, self)._set_assets_paths()
|
||||
|
||||
conf_abs_dir = os.path.dirname(os.path.abspath(self.conf_file))
|
||||
arch = self.all_options.get('wrapper_archive')
|
||||
if arch:
|
||||
if os.path.isabs(arch):
|
||||
self.arch_filepath = arch
|
||||
else:
|
||||
self.arch_filepath = os.path.join(conf_abs_dir, arch)
|
||||
|
||||
def _extract(self):
|
||||
"""Extract archive to temp dir"""
|
||||
|
||||
title = self._get_title()
|
||||
curdir = os.path.abspath('.')
|
||||
os.chdir(self.dir)
|
||||
result = utils.extract_archive(self.arch_filepath, title)
|
||||
os.chdir(curdir)
|
||||
return result
|
||||
|
||||
def _validate_options(self):
|
||||
|
||||
validation_result = super(ArchiveBase, self)._validate_options()
|
||||
|
||||
if 'wrapper_archive' not in self.all_options:
|
||||
sys.stderr.write("Configuration lacks of required "
|
||||
"`wrapper_archive' option.\n")
|
||||
validation_result = False
|
||||
|
||||
return validation_result
|
||||
|
||||
@@ -8,12 +8,10 @@ used as a base for save state (it will append '_save.7z' to the archive file
|
||||
name.
|
||||
|
||||
"""
|
||||
import sys
|
||||
|
||||
from fs_uae_wrapper import base
|
||||
|
||||
|
||||
class CD32(base.Base):
|
||||
class CD32(base.ArchiveBase):
|
||||
"""
|
||||
Class for performing extracting archive, copying emulator files, and
|
||||
cleaning it back again
|
||||
@@ -53,16 +51,6 @@ class CD32(base.Base):
|
||||
|
||||
return True
|
||||
|
||||
def _validate_options(self):
|
||||
validation_result = super(CD32, self)._validate_options()
|
||||
|
||||
if 'wrapper_archive' not in self.all_options:
|
||||
sys.stderr.write("Configuration lacks of required "
|
||||
"`wrapper_archive' option.\n")
|
||||
validation_result = False
|
||||
|
||||
return validation_result
|
||||
|
||||
|
||||
def run(config_file, fsuae_options, configuration):
|
||||
"""Run fs-uae with provided config file and options"""
|
||||
|
||||
@@ -53,6 +53,15 @@ class TarArchive(Archive):
|
||||
EXTRACT = ['xf']
|
||||
ARCH = 'tar'
|
||||
|
||||
def create(self, arch_name, files=None):
|
||||
files = files if files else sorted(os.listdir('.'))
|
||||
result = subprocess.call([self._compess] + self.ADD + [arch_name] +
|
||||
files)
|
||||
if result != 0:
|
||||
sys.stderr.write("Unable to create archive `%s'\n" % arch_name)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class TarGzipArchive(TarArchive):
|
||||
ADD = ['zcf']
|
||||
|
||||
63
fs_uae_wrapper/savestate.py
Normal file
63
fs_uae_wrapper/savestate.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Wrapper module with preserved save state in archive file.
|
||||
"""
|
||||
from fs_uae_wrapper import base
|
||||
|
||||
|
||||
class SaveState(base.Base):
|
||||
"""
|
||||
Preserve save state.
|
||||
"""
|
||||
def __init__(self, conf_file, fsuae_options, configuration):
|
||||
"""
|
||||
Params:
|
||||
conf_file: a relative path to provided configuration file
|
||||
fsuae_options: is an CmdOption object created out of command line
|
||||
parameters
|
||||
configuration: is config dictionary created out of config file
|
||||
"""
|
||||
super(SaveState, self).__init__(conf_file, fsuae_options,
|
||||
configuration)
|
||||
self.arch_filepath = None
|
||||
self.all_options['wrapper_save_state'] = '1'
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Main function which accepts configuration file for FS-UAE
|
||||
It will do as follows:
|
||||
- set needed full path for asset files
|
||||
- copy configuration
|
||||
- optionally extract save state archive
|
||||
- run the emulation
|
||||
- optionally make archive save state
|
||||
"""
|
||||
if not super(SaveState, self).run():
|
||||
return False
|
||||
|
||||
self._load_save()
|
||||
|
||||
if not self._copy_conf():
|
||||
return False
|
||||
|
||||
kick_opts = self._kickstart_option()
|
||||
if kick_opts:
|
||||
self.fsuae_options.update(kick_opts)
|
||||
|
||||
if not self._run_emulator(self.fsuae_options.list()):
|
||||
return False
|
||||
|
||||
if self._get_saves_dir():
|
||||
if not self._save_save():
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def run(config_file, fsuae_options, configuration):
|
||||
"""Run fs-uae with provided config file and options"""
|
||||
|
||||
runner = SaveState(config_file, fsuae_options, configuration)
|
||||
try:
|
||||
return runner.run()
|
||||
finally:
|
||||
runner.clean()
|
||||
4
setup.py
4
setup.py
@@ -2,12 +2,12 @@
|
||||
"""
|
||||
Setup for the fs-uae-wrapper
|
||||
"""
|
||||
from distutils.core import setup
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
setup(name='fs-uae-wrapper',
|
||||
packages=['fs_uae_wrapper'],
|
||||
version='0.5',
|
||||
version='0.7',
|
||||
description='Automate archives and state for fs-uae',
|
||||
author='Roman Dobosz',
|
||||
author_email='gryf73@gmail.com',
|
||||
|
||||
@@ -43,13 +43,13 @@ class TestArchive(TestCase):
|
||||
@mock.patch('tempfile.mkdtemp')
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
@mock.patch('fs_uae_wrapper.archive.Archive._make_archive')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._extract')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._save_save')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._run_emulator')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._kickstart_option')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._copy_conf')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._load_save')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._extract')
|
||||
def test_run(self, extract, load_save, copy_conf, kick_option,
|
||||
run_emulator, get_save_dir, save_state, make_arch, which,
|
||||
mkdtemp):
|
||||
@@ -102,8 +102,8 @@ class TestArchive(TestCase):
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch('shutil.rmtree')
|
||||
@mock.patch('fs_uae_wrapper.utils.create_archive')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._get_title')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_title')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||
def test_make_archive(self, sdir, title, carch, rmt, unlink, rename):
|
||||
|
||||
sdir.return_value = None
|
||||
|
||||
@@ -99,34 +99,6 @@ class TestBase(TestCase):
|
||||
self.assertTrue(os.path.exists(os.path.join(self.dirname,
|
||||
'Config.fs-uae')))
|
||||
|
||||
@mock.patch('fs_uae_wrapper.utils.extract_archive')
|
||||
def test_extract(self, utils_extract):
|
||||
|
||||
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
||||
bobj.arch_filepath = self.fname
|
||||
bobj.dir = self.dirname
|
||||
|
||||
utils_extract.return_value = False
|
||||
|
||||
# message for the gui is taken from title in fs-uae conf or, if there
|
||||
# is no such entry, use archive name, which is mandatory to provide
|
||||
bobj.all_options = {'title': 'foo_game', 'wrapper_gui_msg': '1'}
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, 'foo_game')
|
||||
|
||||
utils_extract.reset_mock()
|
||||
bobj.all_options = {'wrapper_archive': 'arch.tar',
|
||||
'wrapper_gui_msg': '1'}
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, 'arch.tar')
|
||||
|
||||
# lets pretend, the extracting has failed
|
||||
utils_extract.reset_mock()
|
||||
bobj.all_options = {'wrapper_gui_msg': '0'}
|
||||
utils_extract.return_value = False
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, '')
|
||||
|
||||
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||
def test_run_emulator(self, run):
|
||||
|
||||
@@ -247,12 +219,15 @@ class TestBase(TestCase):
|
||||
self.assertTrue(bobj._validate_options())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy',
|
||||
'wrapper_archiver': 'myarchiver'}
|
||||
'wrapper_save_state': '0'}
|
||||
self.assertTrue(bobj._validate_options())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy',
|
||||
'wrapper_save_state': '1',
|
||||
'wrapper_archiver': 'myarchiver'}
|
||||
'wrapper_archiver': 'rar'}
|
||||
self.assertTrue(bobj._validate_options())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy',
|
||||
'wrapper_save_state': '1'}
|
||||
self.assertFalse(bobj._validate_options())
|
||||
|
||||
which.return_value = '7z'
|
||||
@@ -276,9 +251,96 @@ class TestBase(TestCase):
|
||||
self.assertFalse(bobj.run())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy',
|
||||
'wrapper_archiver': 'rar'}
|
||||
'wrapper_archiver': 'rar',
|
||||
'wrapper_archive': 'foo.7z'}
|
||||
try:
|
||||
self.assertTrue(bobj.run())
|
||||
self.assertTrue(os.path.exists(bobj.dir))
|
||||
finally:
|
||||
bobj.clean()
|
||||
|
||||
|
||||
class TestArchiveBase(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']
|
||||
self.curdir = os.path.abspath(os.curdir)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.curdir)
|
||||
try:
|
||||
shutil.rmtree(self.dirname)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
shutil.rmtree(self.confdir)
|
||||
except OSError:
|
||||
pass
|
||||
os.unlink(self.fname)
|
||||
sys.argv = self._argv[:]
|
||||
|
||||
def test_set_assets_paths(self):
|
||||
|
||||
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||
os.chdir(self.dirname)
|
||||
bobj.conf_file = 'Config.fs-uae'
|
||||
bobj.all_options = {'wrapper_archive': 'foo.7z',
|
||||
'wrapper_archiver': '7z'}
|
||||
|
||||
bobj._set_assets_paths()
|
||||
full_path = os.path.join(self.dirname, 'Config_save.7z')
|
||||
self.assertEqual(bobj.save_filename, full_path)
|
||||
|
||||
bobj.all_options = {'wrapper_archive': '/home/user/foo.7z',
|
||||
'wrapper_archiver': '7z'}
|
||||
|
||||
bobj._set_assets_paths()
|
||||
full_path = os.path.join(self.dirname, 'Config_save.7z')
|
||||
self.assertEqual(bobj.save_filename, full_path)
|
||||
|
||||
@mock.patch('fs_uae_wrapper.utils.extract_archive')
|
||||
def test_extract(self, utils_extract):
|
||||
|
||||
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||
bobj.arch_filepath = self.fname
|
||||
bobj.dir = self.dirname
|
||||
|
||||
utils_extract.return_value = False
|
||||
|
||||
# message for the gui is taken from title in fs-uae conf or, if there
|
||||
# is no such entry, use archive name, which is mandatory to provide
|
||||
bobj.all_options = {'title': 'foo_game', 'wrapper_gui_msg': '1'}
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, 'foo_game')
|
||||
|
||||
utils_extract.reset_mock()
|
||||
bobj.all_options = {'wrapper_archive': 'arch.tar',
|
||||
'wrapper_gui_msg': '1'}
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, 'arch.tar')
|
||||
|
||||
# lets pretend, the extracting has failed
|
||||
utils_extract.reset_mock()
|
||||
bobj.all_options = {'wrapper_gui_msg': '0'}
|
||||
utils_extract.return_value = False
|
||||
self.assertFalse(bobj._extract())
|
||||
utils_extract.assert_called_once_with(self.fname, '')
|
||||
|
||||
def test_validate_options(self):
|
||||
|
||||
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||
bobj.all_options = {}
|
||||
|
||||
self.assertFalse(bobj._validate_options())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy'}
|
||||
self.assertFalse(bobj._validate_options())
|
||||
|
||||
bobj.all_options = {'wrapper': 'dummy',
|
||||
'wrapper_archive': 'myarchive.7z'}
|
||||
self.assertTrue(bobj._validate_options())
|
||||
|
||||
@@ -11,29 +11,15 @@ from fs_uae_wrapper import utils
|
||||
|
||||
class TestCD32(TestCase):
|
||||
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
def test_validate_options(self, which):
|
||||
|
||||
which.return_value = 'rar'
|
||||
|
||||
acd32 = cd32.CD32('Config.fs-uae', utils.CmdOption(), {})
|
||||
self.assertFalse(acd32._validate_options())
|
||||
|
||||
acd32.all_options['wrapper'] = 'cd32'
|
||||
self.assertFalse(acd32._validate_options())
|
||||
|
||||
acd32.all_options['wrapper_archive'] = 'fake.tgz'
|
||||
self.assertTrue(acd32._validate_options())
|
||||
|
||||
@mock.patch('tempfile.mkdtemp')
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._extract')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._save_save')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._run_emulator')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._kickstart_option')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._copy_conf')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._load_save')
|
||||
@mock.patch('fs_uae_wrapper.base.ArchiveBase._extract')
|
||||
def test_run(self, extract, load_save, copy_conf, kick_option,
|
||||
run_emulator, get_save_dir, save_state, which, mkdtemp):
|
||||
|
||||
|
||||
@@ -60,61 +60,73 @@ class TestArchive(TestCase):
|
||||
self.assertFalse(arch.extract('foo'))
|
||||
call.assert_called_once_with(['false', 'x', 'foo'])
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
@mock.patch('subprocess.call')
|
||||
def test_tar(self, call, which):
|
||||
def test_tar(self, call, which, exists):
|
||||
with open('foo', 'w') as fobj:
|
||||
fobj.write('\n')
|
||||
|
||||
which.return_value = 'tar'
|
||||
exists.return_value = True
|
||||
|
||||
arch = file_archive.TarArchive()
|
||||
arch.archiver = 'tar'
|
||||
call.return_value = 0
|
||||
|
||||
self.assertTrue(arch.create('foo'))
|
||||
call.assert_called_once_with(['tar', 'cf', 'foo', '.'])
|
||||
self.assertTrue(arch.create('foo.tar'))
|
||||
call.assert_called_once_with(['tar', 'cf', 'foo.tar', 'foo'])
|
||||
|
||||
call.reset_mock()
|
||||
call.return_value = 1
|
||||
self.assertFalse(arch.extract('foo'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo'])
|
||||
self.assertFalse(arch.extract('foo.tar'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo.tar'])
|
||||
|
||||
call.reset_mock()
|
||||
arch = file_archive.TarGzipArchive()
|
||||
arch.archiver = 'tar'
|
||||
call.return_value = 0
|
||||
self.assertTrue(arch.create('foo'))
|
||||
call.assert_called_once_with(['tar', 'zcf', 'foo', '.'])
|
||||
self.assertTrue(arch.create('foo.tgz'))
|
||||
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'foo'])
|
||||
|
||||
call.reset_mock()
|
||||
call.return_value = 1
|
||||
self.assertFalse(arch.extract('foo'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo'])
|
||||
self.assertFalse(arch.extract('foo.tgz'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo.tgz'])
|
||||
|
||||
call.reset_mock()
|
||||
arch = file_archive.TarBzip2Archive()
|
||||
arch.archiver = 'tar'
|
||||
call.return_value = 0
|
||||
self.assertTrue(arch.create('foo'))
|
||||
call.assert_called_once_with(['tar', 'jcf', 'foo', '.'])
|
||||
self.assertTrue(arch.create('foo.tar.bz2'))
|
||||
call.assert_called_once_with(['tar', 'jcf', 'foo.tar.bz2', 'foo'])
|
||||
|
||||
call.reset_mock()
|
||||
call.return_value = 1
|
||||
self.assertFalse(arch.extract('foo'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo'])
|
||||
self.assertFalse(arch.extract('foo.tar.bz2'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo.tar.bz2'])
|
||||
|
||||
call.reset_mock()
|
||||
arch = file_archive.TarXzArchive()
|
||||
arch.archiver = 'tar'
|
||||
call.return_value = 0
|
||||
self.assertTrue(arch.create('foo'))
|
||||
call.assert_called_once_with(['tar', 'Jcf', 'foo', '.'])
|
||||
self.assertTrue(arch.create('foo.tar.xz'))
|
||||
call.assert_called_once_with(['tar', 'Jcf', 'foo.tar.xz', 'foo'])
|
||||
|
||||
call.reset_mock()
|
||||
call.return_value = 1
|
||||
self.assertFalse(arch.extract('foo'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo'])
|
||||
self.assertFalse(arch.extract('foo.tar.xz'))
|
||||
call.assert_called_once_with(['tar', 'xf', 'foo.tar.xz'])
|
||||
|
||||
with open('bar', 'w') as fobj:
|
||||
fobj.write('\n')
|
||||
|
||||
call.reset_mock()
|
||||
arch = file_archive.TarGzipArchive()
|
||||
arch.archiver = 'tar'
|
||||
call.return_value = 0
|
||||
self.assertTrue(arch.create('foo.tgz'))
|
||||
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'bar', 'foo'])
|
||||
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
@mock.patch('subprocess.call')
|
||||
|
||||
85
tests/test_savestate.py
Normal file
85
tests/test_savestate.py
Normal file
@@ -0,0 +1,85 @@
|
||||
import os
|
||||
import shutil
|
||||
from tempfile import mkdtemp
|
||||
from unittest import TestCase
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
except ImportError:
|
||||
import mock
|
||||
|
||||
from fs_uae_wrapper import savestate
|
||||
from fs_uae_wrapper import utils
|
||||
|
||||
|
||||
class TestArchive(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.dirname = mkdtemp()
|
||||
self.curdir = os.path.abspath(os.curdir)
|
||||
os.chdir(self.dirname)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.curdir)
|
||||
try:
|
||||
shutil.rmtree(self.dirname)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
@mock.patch('tempfile.mkdtemp')
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
||||
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
||||
def test_run(self, load_save, copy_conf, kick_option, run_emulator,
|
||||
get_save_dir, save_state, which, mkdtemp):
|
||||
|
||||
copy_conf.return_value = False
|
||||
kick_option.return_value = False
|
||||
run_emulator.return_value = False
|
||||
get_save_dir.return_value = False
|
||||
save_state.return_value = False
|
||||
which.return_value = 'rar'
|
||||
|
||||
arch = savestate.SaveState('Config.fs-uae', utils.CmdOption(), {})
|
||||
self.assertFalse(arch.run())
|
||||
|
||||
arch.all_options = {'wrapper': 'savestate',
|
||||
'wrapper_save_state': '1',
|
||||
'wrapper_archiver': 'rar'}
|
||||
|
||||
self.assertFalse(arch.run())
|
||||
|
||||
self.assertFalse(arch.run())
|
||||
|
||||
copy_conf.return_value = True
|
||||
self.assertFalse(arch.run())
|
||||
|
||||
kick_option.return_value = {'foo': 'bar'}
|
||||
self.assertFalse(arch.run())
|
||||
self.assertDictEqual(arch.fsuae_options, {'foo': 'bar'})
|
||||
|
||||
run_emulator.return_value = True
|
||||
self.assertTrue(arch.run())
|
||||
|
||||
get_save_dir.return_value = True
|
||||
self.assertFalse(arch.run())
|
||||
|
||||
save_state.return_value = True
|
||||
self.assertTrue(arch.run())
|
||||
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
def test_validate_options(self, which):
|
||||
which.return_value = 'unrar'
|
||||
|
||||
arch = savestate.SaveState('Config.fs-uae', utils.CmdOption(), {})
|
||||
self.assertFalse(arch._validate_options())
|
||||
|
||||
arch.all_options['wrapper'] = 'savestate'
|
||||
self.assertFalse(arch._validate_options())
|
||||
|
||||
arch.all_options['wrapper_archiver'] = 'rar'
|
||||
self.assertTrue(arch._validate_options())
|
||||
Reference in New Issue
Block a user