mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2025-12-18 12:00:28 +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 os
|
||||
import sys
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
|
||||
|
||||
WRAPPER_KEY = 'wrapper'
|
||||
|
||||
|
||||
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)}
|
||||
from fs_uae_wrapper import utils
|
||||
from fs_uae_wrapper import WRAPPER_KEY
|
||||
|
||||
|
||||
def parse_option(string):
|
||||
@@ -101,7 +84,7 @@ def run():
|
||||
' for usage\n')
|
||||
sys.exit(1)
|
||||
|
||||
configuration = get_config_options(config_file)
|
||||
configuration = utils.get_config_options(config_file)
|
||||
|
||||
if configuration is None:
|
||||
sys.stderr.write('Error: Configuration file have syntax issues\n')
|
||||
|
||||
@@ -28,50 +28,6 @@ class TestWrapper(TestCase):
|
||||
os.unlink(self.fname)
|
||||
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')
|
||||
def test_run(self, mock_plain_run):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user