[Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Paolo Bonzini posted 1 patch 2 weeks ago
Failed in applying to current master (apply log)
tests/test_tags.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

[Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Posted by Paolo Bonzini 2 weeks ago
email.policy was added in 3.6.  Do not use it unless available.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/test_tags.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/test_tags.py b/tests/test_tags.py
index a49a660..9ced996 100755
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -55,7 +55,11 @@ class ImportTest(PatchewTestCase):
         self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
         self.cli_logout()
         mbox = self.client.get('/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox')
-        parser = email.parser.BytesParser(policy=email.policy.SMTP)
+        try:
+            import email.policy
+            parser = email.parser.BytesParser(policy=email.policy.SMTP)
+        except ModuleNotFoundError:
+            parser = email.parser.BytesParser()
         msg = parser.parsebytes(mbox.content)
         payload = decode_payload(msg)
         self.assertIn('SynICState *synic = get_synic(cs);', payload)
-- 
2.19.1

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Posted by Caio Carrara 2 weeks ago
On Tue, Nov 27, 2018 at 01:45:34PM +0100, Paolo Bonzini wrote:
> email.policy was added in 3.6.  Do not use it unless available.

According to Python documentation[1], email.policy is new in version
3.3. Isn't fair enough have compatibility with Python 3.3+?

The documentation indicates that what have changed in 3.6 is the
"default" message factory[2]. That seems not being touched by your
patch.

[1] - https://docs.python.org/3.3/library/email.policy.html
[2] - https://docs.python.org/3.6/library/email.parser.html#email.parser.BytesParser

> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/test_tags.py | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/test_tags.py b/tests/test_tags.py
> index a49a660..9ced996 100755
> --- a/tests/test_tags.py
> +++ b/tests/test_tags.py
> @@ -55,7 +55,11 @@ class ImportTest(PatchewTestCase):
>          self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
>          self.cli_logout()
>          mbox = self.client.get('/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox')
> -        parser = email.parser.BytesParser(policy=email.policy.SMTP)
> +        try:
> +            import email.policy
> +            parser = email.parser.BytesParser(policy=email.policy.SMTP)
> +        except ModuleNotFoundError:
> +            parser = email.parser.BytesParser()
>          msg = parser.parsebytes(mbox.content)
>          payload = decode_payload(msg)
>          self.assertIn('SynICState *synic = get_synic(cs);', payload)
> -- 
> 2.19.1
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

-- 
Caio Carrara
Software Engineer, Virt Team - Red Hat
ccarrara@redhat.com

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Posted by Paolo Bonzini 2 weeks ago
On 27/11/18 14:08, Caio Carrara wrote:
> On Tue, Nov 27, 2018 at 01:45:34PM +0100, Paolo Bonzini wrote:
>> email.policy was added in 3.6.  Do not use it unless available.
> 
> According to Python documentation[1], email.policy is new in version
> 3.3. Isn't fair enough have compatibility with Python 3.3+?
> 
> The documentation indicates that what have changed in 3.6 is the
> "default" message factory[2]. That seems not being touched by your
> patch.

Travis disagrees though: :(

  File "/home/travis/build/patchew-project/patchew/tests/test_tags.py",
line 58, in test_mbox_with_8bit_tags
    parser = email.parser.BytesParser(policy=email.policy.SMTP)
AttributeError: module 'email' has no attribute 'policy'

on all of 3.3, 3.4 and 3.5.

Paolo

> [1] - https://docs.python.org/3.3/library/email.policy.html
> [2] - https://docs.python.org/3.6/library/email.parser.html#email.parser.BytesParser
> 
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  tests/test_tags.py | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/tests/test_tags.py b/tests/test_tags.py
>> index a49a660..9ced996 100755
>> --- a/tests/test_tags.py
>> +++ b/tests/test_tags.py
>> @@ -55,7 +55,11 @@ class ImportTest(PatchewTestCase):
>>          self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
>>          self.cli_logout()
>>          mbox = self.client.get('/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox')
>> -        parser = email.parser.BytesParser(policy=email.policy.SMTP)
>> +        try:
>> +            import email.policy
>> +            parser = email.parser.BytesParser(policy=email.policy.SMTP)
>> +        except ModuleNotFoundError:
>> +            parser = email.parser.BytesParser()
>>          msg = parser.parsebytes(mbox.content)
>>          payload = decode_payload(msg)
>>          self.assertIn('SynICState *synic = get_synic(cs);', payload)
>> -- 
>> 2.19.1
>>
>> _______________________________________________
>> Patchew-devel mailing list
>> Patchew-devel@redhat.com
>> https://www.redhat.com/mailman/listinfo/patchew-devel
> 

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Posted by Caio Carrara 2 weeks ago
On Tue, Nov 27, 2018 at 02:52:53PM +0100, Paolo Bonzini wrote:
> On 27/11/18 14:08, Caio Carrara wrote:
> > On Tue, Nov 27, 2018 at 01:45:34PM +0100, Paolo Bonzini wrote:
> >> email.policy was added in 3.6.  Do not use it unless available.
> > 
> > According to Python documentation[1], email.policy is new in version
> > 3.3. Isn't fair enough have compatibility with Python 3.3+?
> > 
> > The documentation indicates that what have changed in 3.6 is the
> > "default" message factory[2]. That seems not being touched by your
> > patch.
> 
> Travis disagrees though: :(
> 
>   File "/home/travis/build/patchew-project/patchew/tests/test_tags.py",
> line 58, in test_mbox_with_8bit_tags
>     parser = email.parser.BytesParser(policy=email.policy.SMTP)
> AttributeError: module 'email' has no attribute 'policy'
> 
> on all of 3.3, 3.4 and 3.5.

So we need some help from Travis folks. I've built a fresh Python 3.3.7
on my machine and the policy module is there. 

➜  bin git:(master) ./python
Python 3.3.7 (default, Nov 27 2018, 15:10:34)
[GCC 8.2.1 20181105 (Red Hat 8.2.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
... from email import policy
... dir(policy)
['Compat32', 'EmailPolicy', 'HTTP', 'HeaderRegistry', 'Policy', 'SMTP',
'__all__', '__builtins__', '__cached__', '__doc__', '__file__',
'__initializing__', '__loader__', '__name__', '__package__',
'_extend_docstrings', '_has_surrogates', 'compat32', 'default',
'strict']
...

Should we open a ticket? I did a quick search and couldn't find
anything related with that. It's pretty specific.

> 
> Paolo
> 
> > [1] - https://docs.python.org/3.3/library/email.policy.html
> > [2] - https://docs.python.org/3.6/library/email.parser.html#email.parser.BytesParser
> > 
> >>
> >> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> >> ---
> >>  tests/test_tags.py | 6 +++++-
> >>  1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/tests/test_tags.py b/tests/test_tags.py
> >> index a49a660..9ced996 100755
> >> --- a/tests/test_tags.py
> >> +++ b/tests/test_tags.py
> >> @@ -55,7 +55,11 @@ class ImportTest(PatchewTestCase):
> >>          self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
> >>          self.cli_logout()
> >>          mbox = self.client.get('/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox')
> >> -        parser = email.parser.BytesParser(policy=email.policy.SMTP)
> >> +        try:
> >> +            import email.policy
> >> +            parser = email.parser.BytesParser(policy=email.policy.SMTP)
> >> +        except ModuleNotFoundError:
> >> +            parser = email.parser.BytesParser()
> >>          msg = parser.parsebytes(mbox.content)
> >>          payload = decode_payload(msg)
> >>          self.assertIn('SynICState *synic = get_synic(cs);', payload)
> >> -- 
> >> 2.19.1
> >>
> >> _______________________________________________
> >> Patchew-devel mailing list
> >> Patchew-devel@redhat.com
> >> https://www.redhat.com/mailman/listinfo/patchew-devel
> > 
> 

-- 
Caio Carrara
Software Engineer, Virt Team - Red Hat
ccarrara@redhat.com

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] tests: fix test_tags for Python < 3.6

Posted by Paolo Bonzini 2 weeks ago
On 27/11/18 18:19, Caio Carrara wrote:
> So we need some help from Travis folks. I've built a fresh Python 3.3.7
> on my machine and the policy module is there. 
> 
> ➜  bin git:(master) ./python
> Python 3.3.7 (default, Nov 27 2018, 15:10:34)
> [GCC 8.2.1 20181105 (Red Hat 8.2.1-5)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> ... from email import policy
> ... dir(policy)
> ['Compat32', 'EmailPolicy', 'HTTP', 'HeaderRegistry', 'Policy', 'SMTP',
> '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
> '__initializing__', '__loader__', '__name__', '__package__',
> '_extend_docstrings', '_has_surrogates', 'compat32', 'default',
> 'strict']
> ...
> 
> Should we open a ticket? I did a quick search and couldn't find
> anything related with that. It's pretty specific.

I found it, on older Python you must explicitly import email.parser and
email.policy.

Paolo

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel