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

Caio Carrara ccarrara at redhat.com
Tue Nov 27 13:08:06 UTC 2018


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 at 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 at 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 at redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

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




More information about the Patchew-devel mailing list