From 0b831e5b106e1e217007b570ec053e29094bc7c5 Mon Sep 17 00:00:00 2001 From: gryf Date: Tue, 3 Jan 2017 18:49:18 +0100 Subject: [PATCH] Setting assets paths in base class --- fs_uae_wrapper/archive.py | 1 - fs_uae_wrapper/base.py | 20 ++++++++++++-------- fs_uae_wrapper/cd32.py | 1 - tests/test_base.py | 13 +++++++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/fs_uae_wrapper/archive.py b/fs_uae_wrapper/archive.py index 3a39496..f15bf72 100644 --- a/fs_uae_wrapper/archive.py +++ b/fs_uae_wrapper/archive.py @@ -40,7 +40,6 @@ class Archive(base.Base): if not super(Archive, self).run(): return False - self._set_assets_paths() if not self._extract(): return False diff --git a/fs_uae_wrapper/base.py b/fs_uae_wrapper/base.py index 8571232..55d4b09 100644 --- a/fs_uae_wrapper/base.py +++ b/fs_uae_wrapper/base.py @@ -47,6 +47,8 @@ class Base(object): self.dir = tempfile.mkdtemp() + self._set_assets_paths() + return True def clean(self): @@ -91,15 +93,17 @@ class Base(object): conf_base = os.path.basename(self.conf_file) conf_base = os.path.splitext(conf_base)[0] - arch = self.all_options['wrapper_archive'] - if os.path.isabs(arch): - self.arch_filepath = arch - else: - self.arch_filepath = os.path.join(conf_abs_dir, arch) + 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['wrapper_archiver']) - self.save_filename = os.path.join(conf_abs_dir, conf_base + '_save' + - arch_ext) + arch_ext = utils.get_arch_ext(self.all_options.get('wrapper_archiver')) + if arch_ext: + self.save_filename = os.path.join(conf_abs_dir, conf_base + + '_save' + arch_ext) def _copy_conf(self): """copy provided configuration as Config.fs-uae""" diff --git a/fs_uae_wrapper/cd32.py b/fs_uae_wrapper/cd32.py index 2a08438..db66841 100644 --- a/fs_uae_wrapper/cd32.py +++ b/fs_uae_wrapper/cd32.py @@ -34,7 +34,6 @@ class CD32(base.Base): if not self._validate_options(): return False - self._set_assets_paths() if not self._extract(): return False diff --git a/tests/test_base.py b/tests/test_base.py index c2d11a8..0cf3d6c 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -146,16 +146,18 @@ class TestBase(TestCase): @mock.patch('fs_uae_wrapper.utils.create_archive') def test_save_save(self, carch, saves_dir): - bobj = base.Base('Config.fs-uae', utils.CmdOption(), {}) + os.chdir(self.confdir) + + bobj = base.Base('myconf.fs-uae', utils.CmdOption(), {}) bobj.dir = self.dirname - bobj.save_filename = 'foobar_save.7z' - saves_dir.bobj.save_filenamereturn_value = None + bobj.save_filename = os.path.join(self.confdir, 'myconf_save.7z') + + saves_dir.return_value = None carch.return_value = True self.assertTrue(bobj._save_save()) saves_dir.return_value = bobj.save_filename - os.chdir(self.confdir) with open(bobj.save_filename, 'w') as fobj: fobj.write('asd') @@ -218,6 +220,9 @@ class TestBase(TestCase): os.mkdir(path) self.assertEqual(bobj._get_saves_dir(), 'saves') + bobj.all_options['save_states_dir'] = '$CONFIG/saves/' + self.assertEqual(bobj._get_saves_dir(), 'saves') + @mock.patch('fs_uae_wrapper.path.which') def test_validate_options(self, which):