diff mbox

[KVM-AUTOTEST,06/12] KVM test: minor style changes to kvm_config.py

Message ID 8a2d08b846334a5eb097c2f32348d0c04a6789fb.1249257056.git.mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Aug. 2, 2009, 11:58 p.m. UTC
- Fix indentation of a few lines.
- Limit lines to 80 characters.
- Use list comprehension in config.filter().
- Replace '== None' with 'is None'.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_config.py |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)

Comments

Lucas Meneghel Rodrigues Aug. 7, 2009, 9:47 p.m. UTC | #1
On Sun, Aug 2, 2009 at 8:58 PM, Michael Goldish<mgoldish@redhat.com> wrote:
> - Fix indentation of a few lines.
> - Limit lines to 80 characters.
> - Use list comprehension in config.filter().
> - Replace '== None' with 'is None'.

Good, applied!

> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
>  client/tests/kvm/kvm_config.py |   34 ++++++++++++++++++----------------
>  1 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
> index 7e8b1db..e478a55 100755
> --- a/client/tests/kvm/kvm_config.py
> +++ b/client/tests/kvm/kvm_config.py
> @@ -83,8 +83,8 @@ class config:
>         @param filter: A regular expression that defines the filter.
>         @param dict: Dictionary that will be inspected.
>         """
> -        filter = re.compile("(\\.|^)" + filter + "(\\.|$)")
> -        return filter.search(dict["name"]) != None
> +        filter = re.compile(r"(\.|^)" + filter + r"(\.|$)")
> +        return bool(filter.search(dict["name"]))
>
>
>     def filter(self, filter, list=None):
> @@ -94,13 +94,9 @@ class config:
>         @param filter: A regular expression that will be used as a filter.
>         @param list: A list of dictionaries that will be filtered.
>         """
> -        if list == None:
> +        if list is None:
>             list = self.list
> -        filtered_list = []
> -        for dict in list:
> -            if self.match(filter, dict):
> -                filtered_list.append(dict)
> -        return filtered_list
> +        return [dict for dict in list if self.match(filter, dict)]
>
>
>     # Currently unused, will be removed if it remains unused
> @@ -111,7 +107,7 @@ class config:
>         @param filter: A regular expression that will filter the list.
>         @param list: List which we want to know the indexes that match a filter.
>         """
> -        if list == None:
> +        if list is None:
>             list = self.list
>         block_list = []
>         prev_match = False
> @@ -248,17 +244,22 @@ class config:
>                 temp_list.append(new_dict)
>
>             if subvariants:
> -                # If we're parsing 'subvariants', we need to modify the list first
> -                self.__modify_list_subvariants(temp_list, name, dep_list, add_to_shortname)
> +                # If we're parsing 'subvariants', first modify the list
> +                self.__modify_list_subvariants(temp_list, name, dep_list,
> +                                               add_to_shortname)
>                 temp_list = self.parse(file, temp_list,
>                         restricted=True, prev_indent=indent)
>             else:
> -                # If we're parsing 'variants', we need to parse first and then modify the list
> +                # If we're parsing 'variants', parse before modifying the list
>                 if self.debug:
> -                    self.__debug_print(indented_line, "Entering variant '%s' (variant inherits %d dicts)" % (name, len(list)))
> +                    self.__debug_print(indented_line,
> +                                       "Entering variant '%s' "
> +                                       "(variant inherits %d dicts)" %
> +                                       (name, len(list)))
>                 temp_list = self.parse(file, temp_list,
>                         restricted=False, prev_indent=indent)
> -                self.__modify_list_variants(temp_list, name, dep_list, add_to_shortname)
> +                self.__modify_list_variants(temp_list, name, dep_list,
> +                                            add_to_shortname)
>
>             new_list += temp_list
>
> @@ -401,7 +402,7 @@ class config:
>                     continue
>                 if self.debug and not restricted:
>                     self.__debug_print(indented_line,
> -                                     "Entering file %s" % words[1])
> +                                       "Entering file %s" % words[1])
>                 if self.filename:
>                     filename = os.path.join(os.path.dirname(self.filename),
>                                             words[1])
> @@ -440,7 +441,8 @@ class config:
>                         # Everything inside an exception should be parsed in
>                         # restricted mode
>                         new_list += self.parse(file, list[index:index+1],
> -                                restricted=True, prev_indent=indent)
> +                                               restricted=True,
> +                                               prev_indent=indent)
>                     else:
>                         new_list += list[index:index+1]
>                 list = new_list
> --
> 1.5.4.1
>
> _______________________________________________
> Autotest mailing list
> Autotest@test.kernel.org
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py
index 7e8b1db..e478a55 100755
--- a/client/tests/kvm/kvm_config.py
+++ b/client/tests/kvm/kvm_config.py
@@ -83,8 +83,8 @@  class config:
         @param filter: A regular expression that defines the filter.
         @param dict: Dictionary that will be inspected.
         """
-        filter = re.compile("(\\.|^)" + filter + "(\\.|$)")
-        return filter.search(dict["name"]) != None
+        filter = re.compile(r"(\.|^)" + filter + r"(\.|$)")
+        return bool(filter.search(dict["name"]))
 
 
     def filter(self, filter, list=None):
@@ -94,13 +94,9 @@  class config:
         @param filter: A regular expression that will be used as a filter.
         @param list: A list of dictionaries that will be filtered.
         """
-        if list == None:
+        if list is None:
             list = self.list
-        filtered_list = []
-        for dict in list:
-            if self.match(filter, dict):
-                filtered_list.append(dict)
-        return filtered_list
+        return [dict for dict in list if self.match(filter, dict)]
 
 
     # Currently unused, will be removed if it remains unused
@@ -111,7 +107,7 @@  class config:
         @param filter: A regular expression that will filter the list.
         @param list: List which we want to know the indexes that match a filter.
         """
-        if list == None:
+        if list is None:
             list = self.list
         block_list = []
         prev_match = False
@@ -248,17 +244,22 @@  class config:
                 temp_list.append(new_dict)
 
             if subvariants:
-                # If we're parsing 'subvariants', we need to modify the list first
-                self.__modify_list_subvariants(temp_list, name, dep_list, add_to_shortname)
+                # If we're parsing 'subvariants', first modify the list
+                self.__modify_list_subvariants(temp_list, name, dep_list,
+                                               add_to_shortname)
                 temp_list = self.parse(file, temp_list,
                         restricted=True, prev_indent=indent)
             else:
-                # If we're parsing 'variants', we need to parse first and then modify the list
+                # If we're parsing 'variants', parse before modifying the list
                 if self.debug:
-                    self.__debug_print(indented_line, "Entering variant '%s' (variant inherits %d dicts)" % (name, len(list)))
+                    self.__debug_print(indented_line,
+                                       "Entering variant '%s' "
+                                       "(variant inherits %d dicts)" %
+                                       (name, len(list)))
                 temp_list = self.parse(file, temp_list,
                         restricted=False, prev_indent=indent)
-                self.__modify_list_variants(temp_list, name, dep_list, add_to_shortname)
+                self.__modify_list_variants(temp_list, name, dep_list,
+                                            add_to_shortname)
 
             new_list += temp_list
 
@@ -401,7 +402,7 @@  class config:
                     continue
                 if self.debug and not restricted:
                     self.__debug_print(indented_line,
-                                     "Entering file %s" % words[1])
+                                       "Entering file %s" % words[1])
                 if self.filename:
                     filename = os.path.join(os.path.dirname(self.filename),
                                             words[1])
@@ -440,7 +441,8 @@  class config:
                         # Everything inside an exception should be parsed in
                         # restricted mode
                         new_list += self.parse(file, list[index:index+1],
-                                restricted=True, prev_indent=indent)
+                                               restricted=True,
+                                               prev_indent=indent)
                     else:
                         new_list += list[index:index+1]
                 list = new_list