diff --git a/tests/test_base.py b/tests/test_base.py index 9fbdcf7..cba407c 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -47,9 +47,11 @@ class TestBase(TestCase): bobj.clean() self.assertFalse(os.path.exists(self.dirname)) + @mock.patch('os.path.exists') @mock.patch('fs_uae_wrapper.utils.get_config') - def test_normalize_options(self, get_config): + def test_normalize_options(self, get_config, os_exists): + os_exists.return_value = True bobj = base.Base('Config.fs-uae', utils.CmdOption(), {}) get_config.return_value = {'kickstarts_dir': '/some/path'} @@ -92,6 +94,28 @@ class TestBase(TestCase): bobj._normalize_options() self.assertDictEqual(bobj.fsuae_options, {}) + @mock.patch('os.path.exists') + @mock.patch('fs_uae_wrapper.utils.get_config') + def test_normalize_options_path_not_exists(self, get_config, os_exists): + + os_exists.return_value = False + bobj = base.Base('Config.fs-uae', utils.CmdOption(), {}) + + get_config.return_value = {'kickstarts_dir': '/some/path'} + bobj._normalize_options() + self.assertDictEqual(bobj.fsuae_options, {}) + + os.chdir(self.dirname) + get_config.return_value = {'fmv_rom': 'bar'} + bobj._normalize_options() + self.assertDictEqual(bobj.fsuae_options, {'fmv_rom': 'bar'}) + + get_config.return_value = {'floppies_dir': '../some/path'} + bobj.fsuae_options = utils.CmdOption() + bobj._normalize_options() + self.assertDictEqual(bobj.fsuae_options, + {'floppies_dir': '../some/path'}) + def test_set_assets_paths(self): bobj = base.Base('Config.fs-uae', utils.CmdOption(), {}) diff --git a/tests/test_utils.py b/tests/test_utils.py index 76b8f62..4537047 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -234,11 +234,13 @@ class TestCmdOptions(TestCase): self.assertListEqual(sorted(cmd.list()), ['--fast_memory=4096', '--fullscreen']) + @mock.patch('os.path.exists') @mock.patch('os.getenv') @mock.patch('os.path.expandvars') @mock.patch('distutils.spawn.find_executable') - def test_interpolate_variables(self, find_exe, expandv, getenv): + def test_interpolate_variables(self, find_exe, expandv, getenv, os_exists): + os_exists.return_value = True itrpl = utils.interpolate_variables string = '$CONFIG/../path/to/smth' @@ -264,3 +266,11 @@ class TestCmdOptions(TestCase): '$BASE') self.assertEqual(itrpl(string, '/home/user/Config.fs-uae', 'base'), 'base') + + @mock.patch('os.getenv') + @mock.patch('os.path.expandvars') + def test_interpolate_variables_path_not_exists(self, expandv, getenv): + itrpl = utils.interpolate_variables + + string = '$CONFIG/../path/to/smth' + self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), string)