Re: [PATCH 20/20] oeqa.utils.readconfig: Read self-test configuration file

Joshua G Lock
2016-08-09T09:19:52Z

On Mon, 2016-08-08 at 09:23 -0700, Jose Lamego wrote:
> Improve oeqa-selftest capabilities and UX by placing
> test configuration features and variables into a separate
> configuration file.
> This library reads a configuration file located at the
> oeqa/selftest/conf directory with same name as the caller
> file and the conf extension.

This patch to add the oeqa.utils.readconfig module should really be
applied before all of the changes which make use it. It's a relatively
minor niggle, but this should really be 1/20.

>
> [Yocto 9389]
>
> Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com>
> ---
>  meta/lib/oeqa/utils/readconfig.py | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>  create mode 100644 meta/lib/oeqa/utils/readconfig.py
>
> diff --git a/meta/lib/oeqa/utils/readconfig.py
> b/meta/lib/oeqa/utils/readconfig.py
> new file mode 100644
> index 0000000..1534ce7
> --- /dev/null
> +++ b/meta/lib/oeqa/utils/readconfig.py
> @@ -0,0 +1,18 @@
> +import os
> +import re
> +import configparser
> +
> +
> +def conffile(codefile):
> +    # Get test configurations from configuration file
> +    f = re.compile(r'(pyc?$)')
> +    fn = os.path.basename(codefile)
> +    configfile = os.path.join(os.path.dirname(codefile), 'conf',
> +                              f.sub('conf', fn))

This seems like it would be simpler with os.path.splitext()[1] ?

> +    config = configparser.SafeConfigParser()

Since Python 3.2 that's just ConfigParser()[2]. As we require Python
3.4 or newer for BitBake you can just use configparser.ConfigParser()
here.

> +    read_result = config.read(configfile)
> +    if read_result == []:
> +        raise configparser.Error("Failed to get test configuration
> from \
> +\"%s\". Verify that file exists and format is correct."
> +                                 % configfile)
> +    return config
> --
> 1.8.3.1
>

Regards,

Joshua

1. https://docs.python.org/3/library/os.path.html#os.path.splitext
2. https://docs.python.org/3/whatsnew/3.2.html