diff mbox series

[v3,5/8] iotests: Let skip_if_unsupported() accept a method

Message ID 20190819201851.24418-6-mreitz@redhat.com
State New
Headers show
Series iotests: Selfish patches | expand

Commit Message

Max Reitz Aug. 19, 2019, 8:18 p.m. UTC
This lets tests use skip_if_unsupported() with a potentially variable
list of required formats.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/iotests.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

John Snow Aug. 20, 2019, 9:31 p.m. UTC | #1
On 8/19/19 4:18 PM, Max Reitz wrote:
> This lets tests use skip_if_unsupported() with a potentially variable
> list of required formats.
> 
> Suggested-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 726f904f50..8f315538e9 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -893,8 +893,12 @@ def skip_if_unsupported(required_formats=[], read_only=False):
>         Runs the test if all the required formats are whitelisted'''
>      def skip_test_decorator(func):
>          def func_wrapper(*args, **kwargs):
> -            usf_list = list(set(required_formats) -
> -                            set(supported_formats(read_only)))
> +            if callable(required_formats):
> +                fmts = required_formats(args[0])
> +            else:
> +                fmts = required_formats
> +
> +            usf_list = list(set(fmts) - set(supported_formats(read_only)))
>              if usf_list:
>                  args[0].case_skip('{}: formats {} are not whitelisted'.format(
>                      args[0], usf_list))
> 

I am required to inform you that this is in direct violation of the
pythonista treaty of 2007; which mandates that you try to call and fail
instead of attempting to gracefully check ahead of time.

Luckily, I am not fond of such rules.

Reviewed-by: John Snow <jsnow@redhat.com>
Max Reitz Aug. 21, 2019, 10:54 a.m. UTC | #2
On 20.08.19 23:31, John Snow wrote:
> 
> 
> On 8/19/19 4:18 PM, Max Reitz wrote:
>> This lets tests use skip_if_unsupported() with a potentially variable
>> list of required formats.
>>
>> Suggested-by: Kevin Wolf <kwolf@redhat.com>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  tests/qemu-iotests/iotests.py | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
>> index 726f904f50..8f315538e9 100644
>> --- a/tests/qemu-iotests/iotests.py
>> +++ b/tests/qemu-iotests/iotests.py
>> @@ -893,8 +893,12 @@ def skip_if_unsupported(required_formats=[], read_only=False):
>>         Runs the test if all the required formats are whitelisted'''
>>      def skip_test_decorator(func):
>>          def func_wrapper(*args, **kwargs):
>> -            usf_list = list(set(required_formats) -
>> -                            set(supported_formats(read_only)))
>> +            if callable(required_formats):
>> +                fmts = required_formats(args[0])
>> +            else:
>> +                fmts = required_formats
>> +
>> +            usf_list = list(set(fmts) - set(supported_formats(read_only)))
>>              if usf_list:
>>                  args[0].case_skip('{}: formats {} are not whitelisted'.format(
>>                      args[0], usf_list))
>>
> 
> I am required to inform you that this is in direct violation of the
> pythonista treaty of 2007; which mandates that you try to call and fail
> instead of attempting to gracefully check ahead of time.
> 
> Luckily, I am not fond of such rules.

:-)

I blame Kevin’s proposal.  (We should always have someone on PTO to
blame for everything.)


Thanks for reviewing.

Max
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 726f904f50..8f315538e9 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -893,8 +893,12 @@  def skip_if_unsupported(required_formats=[], read_only=False):
        Runs the test if all the required formats are whitelisted'''
     def skip_test_decorator(func):
         def func_wrapper(*args, **kwargs):
-            usf_list = list(set(required_formats) -
-                            set(supported_formats(read_only)))
+            if callable(required_formats):
+                fmts = required_formats(args[0])
+            else:
+                fmts = required_formats
+
+            usf_list = list(set(fmts) - set(supported_formats(read_only)))
             if usf_list:
                 args[0].case_skip('{}: formats {} are not whitelisted'.format(
                     args[0], usf_list))