mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2025-12-19 04:20:23 +01:00
Moved constant to the module init
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
WRAPPER_KEY = 'wrapper'
|
||||||
|
|||||||
@@ -6,26 +6,9 @@ emulator, if appropriate option is enabled.
|
|||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
try:
|
|
||||||
import configparser
|
|
||||||
except ImportError:
|
|
||||||
import ConfigParser as configparser
|
|
||||||
|
|
||||||
|
from fs_uae_wrapper import utils
|
||||||
WRAPPER_KEY = 'wrapper'
|
from fs_uae_wrapper import WRAPPER_KEY
|
||||||
|
|
||||||
|
|
||||||
def get_config_options(conf):
|
|
||||||
"""Read config file and return options as a dict"""
|
|
||||||
parser = configparser.SafeConfigParser()
|
|
||||||
try:
|
|
||||||
parser.read(conf)
|
|
||||||
except configparser.ParsingError:
|
|
||||||
# Configuration syntax is wrong
|
|
||||||
return None
|
|
||||||
|
|
||||||
return {key: val for section in parser.sections()
|
|
||||||
for key, val in parser.items(section)}
|
|
||||||
|
|
||||||
|
|
||||||
def parse_option(string):
|
def parse_option(string):
|
||||||
@@ -101,7 +84,7 @@ def run():
|
|||||||
' for usage\n')
|
' for usage\n')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
configuration = get_config_options(config_file)
|
configuration = utils.get_config_options(config_file)
|
||||||
|
|
||||||
if configuration is None:
|
if configuration is None:
|
||||||
sys.stderr.write('Error: Configuration file have syntax issues\n')
|
sys.stderr.write('Error: Configuration file have syntax issues\n')
|
||||||
|
|||||||
@@ -28,50 +28,6 @@ class TestWrapper(TestCase):
|
|||||||
os.unlink(self.fname)
|
os.unlink(self.fname)
|
||||||
sys.argv = self._argv[:]
|
sys.argv = self._argv[:]
|
||||||
|
|
||||||
def test_get_config_options(self):
|
|
||||||
|
|
||||||
configs = ["[conf]\nwrapper=foo\n",
|
|
||||||
"[conf]\n wrapper =foo\n",
|
|
||||||
"[conf]\n wrapper = foo\n",
|
|
||||||
"[conf]\nwrapper = foo \n"]
|
|
||||||
|
|
||||||
for cfg in configs:
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write(cfg)
|
|
||||||
|
|
||||||
val = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(val, {'wrapper': 'foo'})
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nwraper=foo\n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(conf, {'wraper': 'foo'})
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nwrapper\n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertIsNone(conf)
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nfullscreen = 1\n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(conf, {'fullscreen': '1'})
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nwrapper= = = something went wrong\n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(conf, {'wrapper': '= = something went wrong'})
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nwrapper = = \n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(conf, {'wrapper': '='})
|
|
||||||
|
|
||||||
with open(self.fname, 'w') as fobj:
|
|
||||||
fobj.write("[conf]\nwrapper = \n")
|
|
||||||
conf = wrapper.get_config_options(self.fname)
|
|
||||||
self.assertDictEqual(conf, {'wrapper': ''})
|
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.plain.run')
|
@mock.patch('fs_uae_wrapper.plain.run')
|
||||||
def test_run(self, mock_plain_run):
|
def test_run(self, mock_plain_run):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user