[Piglit] [PATCH 1/2] framework: move get_config() to core
Dylan Baker
baker.dylan.c at gmail.com
Wed Jul 16 09:49:32 PDT 2014
On Wednesday, July 16, 2014 11:18:57 AM Thomas Wood wrote:
> Move framework.programs.run._get_config() to framework.core.get_config() so
> that it can be used elsewhere.
>
> Signed-off-by: Thomas Wood <thomas.wood at intel.com>
> ---
> framework/core.py | 23 +++++++++++++++++++++++
> framework/programs/run.py | 27 ++-------------------------
> framework/tests/integration_tests.py | 4 ++--
> framework/tests/programs_tests.py | 14 +++++++-------
> 4 files changed, 34 insertions(+), 34 deletions(-)
>
> diff --git a/framework/core.py b/framework/core.py
> index 675b7aa..12bb180 100644
> --- a/framework/core.py
> +++ b/framework/core.py
> @@ -39,6 +39,29 @@ __all__ = ['PIGLIT_CONFIG',
>
> PIGLIT_CONFIG = ConfigParser.SafeConfigParser()
>
> +def get_config(arg):
It's probably worth chaning arg to arg=None, it should save some code
elsewhere, but if you don't want to that's cool too.
> + if arg:
> + PIGLIT_CONFIG.readfp(arg)
> + else:
> + # Load the piglit.conf. First try looking in the current directory,
> + # then trying the XDG_CONFIG_HOME, then $HOME/.config/, finally
> try the + # piglit root dir
> + for d in ['.',
> + os.environ.get('XDG_CONFIG_HOME',
> + os.path.expandvars('$HOME/.config')),
> + os.path.join(os.path.dirname(__file__), '..', '..')]:
> + try:
> + with open(os.path.join(d, 'piglit.conf'), 'r') as f:
> + PIGLIT_CONFIG.readfp(f)
> + break
> + except IOError:
> + pass
> + else:
> + if __debug__:
> + print('Warning: piglit.conf not found!\n'
> + '(searching current dir, $HOME/.config, '
> + '$XDG_CONFIG_HOME, and piglit source dir)',
> + file=sys.stderr)
>
> # Ensure the given directory exists
> def checkDir(dirname, failifexists):
> diff --git a/framework/programs/run.py b/framework/programs/run.py
> index 61444fa..eb67d7f 100644
> --- a/framework/programs/run.py
> +++ b/framework/programs/run.py
> @@ -123,7 +123,7 @@ def run(input_):
> args.concurrency = "none"
>
> # Read the config file
> - _get_config(args.config_file)
> + core.get_config(args.config_file)
>
> # Pass arguments into Options
> opts = core.Options(concurrent=args.concurrency,
> @@ -213,7 +213,7 @@ def resume(input_):
> dmesg=results.options['dmesg'],
> verbose=results.options['verbose'])
>
> - _get_config(args.config_file)
> + core.get_config(args.config_file)
>
> if results.options.get('platform'):
> opts.env['PIGLIT_PLATFORM'] = results.options['platform']
> @@ -245,26 +245,3 @@ def resume(input_):
> "Results have ben wrriten to {0}".format(results_path))
>
>
> -def _get_config(arg):
> - if arg:
> - core.PIGLIT_CONFIG.readfp(arg)
> - else:
> - # Load the piglit.conf. First try looking in the current directory,
> - # then trying the XDG_CONFIG_HOME, then $HOME/.config/, finally
> try the - # piglit root dir
> - for d in ['.',
> - os.environ.get('XDG_CONFIG_HOME',
> - os.path.expandvars('$HOME/.config')),
> - os.path.join(os.path.dirname(__file__), '..', '..')]:
> - try:
> - with open(os.path.join(d, 'piglit.conf'), 'r') as f:
> - core.PIGLIT_CONFIG.readfp(f)
> - break
> - except IOError:
> - pass
> - else:
> - if __debug__:
> - print('Warning: piglit.conf not found!\n'
> - '(searching current dir, $HOME/.config, '
> - '$XDG_CONFIG_HOME, and piglit source dir)',
> - file=sys.stderr)
> diff --git a/framework/tests/integration_tests.py
> b/framework/tests/integration_tests.py index 92d6698..65cbc0a 100644
> --- a/framework/tests/integration_tests.py
> +++ b/framework/tests/integration_tests.py
> @@ -29,10 +29,10 @@ errors and to ensure that the API hasn't changed without
> fixing these modules import importlib
> import ConfigParser
> from nose.plugins.skip import SkipTest
> -from framework.programs.run import _get_config
> +import framework.core
>
>
> -_get_config(None)
> +core.get_config(None)
this should be: framework.core.get_config(None)
>
>
> def _import(name):
> diff --git a/framework/tests/programs_tests.py
> b/framework/tests/programs_tests.py index c563ef0..91ebd78 100644
> --- a/framework/tests/programs_tests.py
> +++ b/framework/tests/programs_tests.py
> @@ -96,7 +96,7 @@ class _TestWithEnvClean(object):
> # Tests
> class TestGetConfigEnv(_TestWithEnvClean):
> def test(self):
> - """ _get_config() finds $XDG_CONFIG_HOME/piglit.conf """
> + """ get_config() finds $XDG_CONFIG_HOME/piglit.conf """
> self.defer(lambda: core.PIGLIT_CONFIG ==
> ConfigParser.SafeConfigParser) self.add_teardown('XDG_CONFIG_HOME')
> if os.path.exists('piglit.conf'):
> @@ -107,7 +107,7 @@ class TestGetConfigEnv(_TestWithEnvClean):
> os.environ['XDG_CONFIG_HOME'] = tdir
> with open(os.path.join(tdir, 'piglit.conf'), 'w') as f:
> f.write(CONF_FILE)
> - run._get_config(None)
> + core.get_config(None)
>
> nt.ok_(core.PIGLIT_CONFIG.has_section('nose-test'),
> msg='$XDG_CONFIG_HOME not found')
> @@ -115,7 +115,7 @@ class TestGetConfigEnv(_TestWithEnvClean):
>
> class TestGetConfigHomeFallback(_TestWithEnvClean):
> def test(self):
> - """ _get_config() finds $HOME/.config/piglit.conf """
> + """ get_config() finds $HOME/.config/piglit.conf """
> self.defer(lambda: core.PIGLIT_CONFIG ==
> ConfigParser.SafeConfigParser) self.add_teardown('HOME')
> self.add_teardown('XDG_CONFIG_HOME')
> @@ -136,7 +136,7 @@ class TestGetConfigHomeFallback(_TestWithEnvClean):
> class TestGetConfigLocal(_TestWithEnvClean):
> # These need to be empty to force '.' to be used
> def test(self):
> - """ _get_config() finds ./piglit.conf """
> + """ get_config() finds ./piglit.conf """
> self.defer(lambda: core.PIGLIT_CONFIG ==
> ConfigParser.SafeConfigParser) self.add_teardown('HOME')
> self.add_teardown('XDG_CONFIG_HOME')
> @@ -151,7 +151,7 @@ class TestGetConfigLocal(_TestWithEnvClean):
> with open(os.path.join(tdir, 'piglit.conf'), 'w') as f:
> f.write(CONF_FILE)
>
> - run._get_config(None)
> + core.get_config(None)
>
> nt.ok_(core.PIGLIT_CONFIG.has_section('nose-test'),
> msg='./piglit.conf not found')
> @@ -159,7 +159,7 @@ class TestGetConfigLocal(_TestWithEnvClean):
>
> class TestGetConfigRoot(_TestWithEnvClean):
> def test(self):
> - """ _get_config() finds "piglit root"/piglit.conf """
> + """ get_config() finds "piglit root"/piglit.conf """
> self.defer(lambda: core.PIGLIT_CONFIG ==
> ConfigParser.SafeConfigParser) self.add_teardown('HOME')
> self.add_teardown('XDG_CONFIG_HOME')
> @@ -174,7 +174,7 @@ class TestGetConfigRoot(_TestWithEnvClean):
> self.defer(os.chdir, os.getcwd())
> os.chdir('..')
>
> - run._get_config(None)
> + core.get_config(None)
>
> nt.ok_(core.PIGLIT_CONFIG.has_section('nose-test'),
> msg='$PIGLIT_ROOT not found')
with the test fixed this is:
Reviewed-by: Dylan Baker <baker.dylan.c at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140716/77c7dd85/attachment.sig>
More information about the Piglit
mailing list