[PATCH] Remove ResourceWarnings under Py3

Andrew Donnellan andrew.donnellan at au1.ibm.com
Wed Jun 28 17:35:16 AEST 2017


On 28/06/17 16:55, Daniel Axtens wrote:
> This is just a matter of correctly closing files we open.
>
> Signed-off-by: Daniel Axtens <dja at axtens.net>

Reviewed-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>

> ---
>  patchwork/management/commands/parsearchive.py | 1 +
>  patchwork/tests/test_management.py            | 2 ++
>  patchwork/tests/test_series.py                | 9 +++++++++
>  patchwork/tests/utils.py                      | 4 +++-
>  4 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py
> index a3c8360186c8..4e102a988e76 100644
> --- a/patchwork/management/commands/parsearchive.py
> +++ b/patchwork/management/commands/parsearchive.py
> @@ -114,3 +114,4 @@ class Command(BaseCommand):
>                  'errors': errors,
>                  'new': count - duplicates - dropped - errors,
>              })
> +        mbox.close()
> diff --git a/patchwork/tests/test_management.py b/patchwork/tests/test_management.py
> index f9166739986b..f548fce3b8e5 100644
> --- a/patchwork/tests/test_management.py
> +++ b/patchwork/tests/test_management.py
> @@ -52,6 +52,7 @@ class ParsemailTest(TestCase):
>          with self.assertRaises(SystemExit) as exc:
>              call_command('parsemail', infile=None)
>
> +        sys.stdin.close()
>          self.assertEqual(exc.exception.code, 1)
>
>      def test_valid_path(self):
> @@ -78,6 +79,7 @@ class ParsemailTest(TestCase):
>              call_command('parsemail', infile=None,
>                           list_id=project.listid)
>
> +        sys.stdin.close()
>          self.assertEqual(exc.exception.code, 0)
>
>          count = models.Patch.objects.filter(project=project.id).count()
> diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py
> index 181fc6d2ac1c..53b5c63e8fa9 100644
> --- a/patchwork/tests/test_series.py
> +++ b/patchwork/tests/test_series.py
> @@ -54,6 +54,7 @@ class _BaseTestCase(TestCase):
>                  results[1].append(obj)
>              else:
>                  results[2].append(obj)
> +        mbox.close()
>
>          self.assertParsed(results, counts)
>
> @@ -601,6 +602,8 @@ class SeriesNameTestCase(TestCase):
>          self._parse_mail(mbox[2])
>          self.assertEqual(cover.latest_series.name, cover_name)
>
> +        mbox.close()
> +
>      def test_no_cover_letter(self):
>          """Series without a cover letter.
>
> @@ -621,6 +624,8 @@ class SeriesNameTestCase(TestCase):
>          self._parse_mail(mbox[1])
>          self.assertEqual(series.name, patch.name)
>
> +        mbox.close()
> +
>      def test_out_of_order(self):
>          """Series received out of order.
>
> @@ -645,6 +650,8 @@ class SeriesNameTestCase(TestCase):
>          cover = self._parse_mail(mbox[2])
>          self.assertEqual(cover.latest_series.name, self._format_name(cover))
>
> +        mbox.close()
> +
>      def test_custom_name(self):
>          """Series with custom name.
>
> @@ -673,3 +680,5 @@ class SeriesNameTestCase(TestCase):
>
>          self._parse_mail(mbox[2])
>          self.assertEqual(series.name, series_name)
> +
> +        mbox.close()
> diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py
> index 3d0293cab36b..d4005c7729e8 100644
> --- a/patchwork/tests/utils.py
> +++ b/patchwork/tests/utils.py
> @@ -54,7 +54,9 @@ def read_patch(filename, encoding=None):
>      else:
>          f = open(file_path)
>
> -    return f.read()
> +    result = f.read()
> +    f.close()
> +    return result
>
>
>  error_strings = {
>

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com  IBM Australia Limited



More information about the Patchwork mailing list