prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Unit test recipes (reportlab to begin with)
  The test suite is currently running full integration tests for a bunch of recipes.
  While integration tests are good, we cannot currently use them for all recipes because they run for too long.
  However having unit tests for all recipes should be feasible and may still cover some issues like https://github.com/kivy/python-for-android/pull/1357#issuecomment-423614116.
  Unit tests were recently enabled the following pull request https://github.com/kivy/python-for-android/pull/1379. So the idea is to increase the coverage start from reportlab recipe as a use case.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pythonforandroid/recipes/reportlab/__init__.py`
  Content:
  ```
  1 import os, sh
  2 from pythonforandroid.recipe import CompiledComponentsPythonRecipe
  3 from pythonforandroid.util import (current_directory, ensure_dir)
  4 from pythonforandroid.logger import (info, shprint)
  5 
  6 
  7 class ReportLabRecipe(CompiledComponentsPythonRecipe):
  8     version = 'c088826211ca'
  9     url = 'https://bitbucket.org/rptlab/reportlab/get/{version}.tar.gz'
  10     depends = [('python2', 'python3crystax'), 'freetype']
  11 
  12     def prebuild_arch(self, arch):
  13         if not self.is_patched(arch):
  14             super(ReportLabRecipe, self).prebuild_arch(arch)
  15             self.apply_patch('patches/fix-setup.patch', arch.arch)
  16             recipe_dir = self.get_build_dir(arch.arch)
  17             shprint(sh.touch, os.path.join(recipe_dir, '.patched'))
  18             ft = self.get_recipe('freetype', self.ctx)
  19             ft_dir = ft.get_build_dir(arch.arch)
  20             ft_lib_dir = os.environ.get('_FT_LIB_', os.path.join(ft_dir, 'objs', '.libs'))
  21             ft_inc_dir = os.environ.get('_FT_INC_', os.path.join(ft_dir, 'include'))
  22             tmp_dir = os.path.normpath(os.path.join(recipe_dir, "..", "..", "tmp"))
  23             info('reportlab recipe: recipe_dir={}'.format(recipe_dir))
  24             info('reportlab recipe: tmp_dir={}'.format(tmp_dir))
  25             info('reportlab recipe: ft_dir={}'.format(ft_dir))
  26             info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))
  27             info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))
  28             with current_directory(recipe_dir):
  29                 sh.ls('-lathr')
  30                 ensure_dir(tmp_dir)
  31                 pfbfile = os.path.join(tmp_dir, "pfbfer-20070710.zip")
  32                 if not os.path.isfile(pfbfile):
  33                     sh.wget("http://www.reportlab.com/ftp/pfbfer-20070710.zip", "-O", pfbfile)
  34                 sh.unzip("-u", "-d", os.path.join(recipe_dir, "src", "reportlab", "fonts"), pfbfile)
  35                 if os.path.isfile("setup.py"):
  36                     with open('setup.py', 'rb') as f:
  37                         text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)
  38                     with open('setup.py', 'wb') as f:
  39                         f.write(text)
  40 
  41 
  42 recipe = ReportLabRecipe()
  43
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pythonforandroid/recipes/reportlab/__init__.py b/pythonforandroid/recipes/reportlab/__init__.py
  --- a/pythonforandroid/recipes/reportlab/__init__.py
  +++ b/pythonforandroid/recipes/reportlab/__init__.py
  @@ -26,16 +26,15 @@
               info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))
               info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))
               with current_directory(recipe_dir):
  -                sh.ls('-lathr')
                   ensure_dir(tmp_dir)
                   pfbfile = os.path.join(tmp_dir, "pfbfer-20070710.zip")
                   if not os.path.isfile(pfbfile):
                       sh.wget("http://www.reportlab.com/ftp/pfbfer-20070710.zip", "-O", pfbfile)
                   sh.unzip("-u", "-d", os.path.join(recipe_dir, "src", "reportlab", "fonts"), pfbfile)
                   if os.path.isfile("setup.py"):
  -                    with open('setup.py', 'rb') as f:
  +                    with open('setup.py', 'r') as f:
                           text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)
  -                    with open('setup.py', 'wb') as f:
  +                    with open('setup.py', 'w') as f:
                           f.write(text)
  
verification_info: {"golden_diff": "diff --git a/pythonforandroid/recipes/reportlab/__init__.py b/pythonforandroid/recipes/reportlab/__init__.py\n--- a/pythonforandroid/recipes/reportlab/__init__.py\n+++ b/pythonforandroid/recipes/reportlab/__init__.py\n@@ -26,16 +26,15 @@\n             info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))\n             info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))\n             with current_directory(recipe_dir):\n-                sh.ls('-lathr')\n                 ensure_dir(tmp_dir)\n                 pfbfile = os.path.join(tmp_dir, \"pfbfer-20070710.zip\")\n                 if not os.path.isfile(pfbfile):\n                     sh.wget(\"http://www.reportlab.com/ftp/pfbfer-20070710.zip\", \"-O\", pfbfile)\n                 sh.unzip(\"-u\", \"-d\", os.path.join(recipe_dir, \"src\", \"reportlab\", \"fonts\"), pfbfile)\n                 if os.path.isfile(\"setup.py\"):\n-                    with open('setup.py', 'rb') as f:\n+                    with open('setup.py', 'r') as f:\n                         text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)\n-                    with open('setup.py', 'wb') as f:\n+                    with open('setup.py', 'w') as f:\n                         f.write(text)\n", "issue": "Unit test recipes (reportlab to begin with)\nThe test suite is currently running full integration tests for a bunch of recipes.\r\nWhile integration tests are good, we cannot currently use them for all recipes because they run for too long.\r\nHowever having unit tests for all recipes should be feasible and may still cover some issues like https://github.com/kivy/python-for-android/pull/1357#issuecomment-423614116.\r\nUnit tests were recently enabled the following pull request https://github.com/kivy/python-for-android/pull/1379. So the idea is to increase the coverage start from reportlab recipe as a use case.\n", "before_files": [{"content": "import os, sh\nfrom pythonforandroid.recipe import CompiledComponentsPythonRecipe\nfrom pythonforandroid.util import (current_directory, ensure_dir)\nfrom pythonforandroid.logger import (info, shprint)\n\n\nclass ReportLabRecipe(CompiledComponentsPythonRecipe):\n    version = 'c088826211ca'\n    url = 'https://bitbucket.org/rptlab/reportlab/get/{version}.tar.gz'\n    depends = [('python2', 'python3crystax'), 'freetype']\n\n    def prebuild_arch(self, arch):\n        if not self.is_patched(arch):\n            super(ReportLabRecipe, self).prebuild_arch(arch)\n            self.apply_patch('patches/fix-setup.patch', arch.arch)\n            recipe_dir = self.get_build_dir(arch.arch)\n            shprint(sh.touch, os.path.join(recipe_dir, '.patched'))\n            ft = self.get_recipe('freetype', self.ctx)\n            ft_dir = ft.get_build_dir(arch.arch)\n            ft_lib_dir = os.environ.get('_FT_LIB_', os.path.join(ft_dir, 'objs', '.libs'))\n            ft_inc_dir = os.environ.get('_FT_INC_', os.path.join(ft_dir, 'include'))\n            tmp_dir = os.path.normpath(os.path.join(recipe_dir, \"..\", \"..\", \"tmp\"))\n            info('reportlab recipe: recipe_dir={}'.format(recipe_dir))\n            info('reportlab recipe: tmp_dir={}'.format(tmp_dir))\n            info('reportlab recipe: ft_dir={}'.format(ft_dir))\n            info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))\n            info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))\n            with current_directory(recipe_dir):\n                sh.ls('-lathr')\n                ensure_dir(tmp_dir)\n                pfbfile = os.path.join(tmp_dir, \"pfbfer-20070710.zip\")\n                if not os.path.isfile(pfbfile):\n                    sh.wget(\"http://www.reportlab.com/ftp/pfbfer-20070710.zip\", \"-O\", pfbfile)\n                sh.unzip(\"-u\", \"-d\", os.path.join(recipe_dir, \"src\", \"reportlab\", \"fonts\"), pfbfile)\n                if os.path.isfile(\"setup.py\"):\n                    with open('setup.py', 'rb') as f:\n                        text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)\n                    with open('setup.py', 'wb') as f:\n                        f.write(text)\n\n\nrecipe = ReportLabRecipe()\n", "path": "pythonforandroid/recipes/reportlab/__init__.py"}], "after_files": [{"content": "import os, sh\nfrom pythonforandroid.recipe import CompiledComponentsPythonRecipe\nfrom pythonforandroid.util import (current_directory, ensure_dir)\nfrom pythonforandroid.logger import (info, shprint)\n\n\nclass ReportLabRecipe(CompiledComponentsPythonRecipe):\n    version = 'c088826211ca'\n    url = 'https://bitbucket.org/rptlab/reportlab/get/{version}.tar.gz'\n    depends = [('python2', 'python3crystax'), 'freetype']\n\n    def prebuild_arch(self, arch):\n        if not self.is_patched(arch):\n            super(ReportLabRecipe, self).prebuild_arch(arch)\n            self.apply_patch('patches/fix-setup.patch', arch.arch)\n            recipe_dir = self.get_build_dir(arch.arch)\n            shprint(sh.touch, os.path.join(recipe_dir, '.patched'))\n            ft = self.get_recipe('freetype', self.ctx)\n            ft_dir = ft.get_build_dir(arch.arch)\n            ft_lib_dir = os.environ.get('_FT_LIB_', os.path.join(ft_dir, 'objs', '.libs'))\n            ft_inc_dir = os.environ.get('_FT_INC_', os.path.join(ft_dir, 'include'))\n            tmp_dir = os.path.normpath(os.path.join(recipe_dir, \"..\", \"..\", \"tmp\"))\n            info('reportlab recipe: recipe_dir={}'.format(recipe_dir))\n            info('reportlab recipe: tmp_dir={}'.format(tmp_dir))\n            info('reportlab recipe: ft_dir={}'.format(ft_dir))\n            info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))\n            info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))\n            with current_directory(recipe_dir):\n                ensure_dir(tmp_dir)\n                pfbfile = os.path.join(tmp_dir, \"pfbfer-20070710.zip\")\n                if not os.path.isfile(pfbfile):\n                    sh.wget(\"http://www.reportlab.com/ftp/pfbfer-20070710.zip\", \"-O\", pfbfile)\n                sh.unzip(\"-u\", \"-d\", os.path.join(recipe_dir, \"src\", \"reportlab\", \"fonts\"), pfbfile)\n                if os.path.isfile(\"setup.py\"):\n                    with open('setup.py', 'r') as f:\n                        text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)\n                    with open('setup.py', 'w') as f:\n                        f.write(text)\n\n\nrecipe = ReportLabRecipe()\n", "path": "pythonforandroid/recipes/reportlab/__init__.py"}]}