You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@libcloud.apache.org by "Tomaz Muraus (JIRA)" <ji...@apache.org> on 2013/04/24 21:51:16 UTC

[dev] [jira] [Comment Edited] (LIBCLOUD-321) libcloud.test.compute.test_deployment.DeploymentTests.test_script_file_deployment() fails with Python 3.3

    [ https://issues.apache.org/jira/browse/LIBCLOUD-321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13640802#comment-13640802 ] 

Tomaz Muraus edited comment on LIBCLOUD-321 at 4/24/13 7:49 PM:
----------------------------------------------------------------

Doesn't work here because there is an issue with how we do string type detection in libcloud.compute.deployment and what we set basestring to in libcloud.utils.py3.

if not isinstance(argument_value, basestring) and \
           not hasattr(argument_value, 'read'):

{code}
svn diff
Index: libcloud/compute/deployment.py
===================================================================
--- libcloud/compute/deployment.py	(revision 1471588)
+++ libcloud/compute/deployment.py	(working copy)
@@ -104,7 +104,7 @@
         """
         perms = int(oct(os.stat(self.source).st_mode)[4:], 8)
 
-        with open(self.source, 'rb') as fp:
+        with open(self.source, 'r') as fp:
             content = fp.read()
 
         client.put(path=self.target, chmod=perms,
Index: libcloud/test/compute/test_deployment.py
===================================================================
--- libcloud/test/compute/test_deployment.py	(revision 1471588)
+++ libcloud/test/compute/test_deployment.py	(working copy)
@@ -115,12 +115,8 @@
                         client=MockClient(hostname='localhost')))
 
     def test_script_file_deployment(self):
-        # TODO: Fix 3.2 compatibility
-        if PY32:
-            return
-
         file_path = os.path.abspath(__file__)
-        with open(file_path, 'rb') as fp:
+        with open(file_path, 'r') as fp:
             content = fp.read()
 
         sfd1 = ScriptFileDeployment(script_file=file_path)
{code}

{code}
tox -e py3

======================================================================
ERROR: test_script_file_deployment (libcloud.test.compute.test_deployment.DeploymentTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/w/lc/t1/libcloud/test/compute/test_deployment.py", line 122, in test_script_file_deployment
    sfd1 = ScriptFileDeployment(script_file=file_path)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 193, in __init__
    delete=delete)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 133, in __init__
    argument_value=script)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 52, in _get_string_value
    'object' % (argument_name))
TypeError: script argument must be a string or a file-like object

----------------------------------------------------------------------
Ran 2696 tests in 8.717s

FAILED (errors=1)
[TOX] ERROR: InvocationError: '.tox/py32/bin/python setup.py test'
{code}
                
      was (Author: kami):
    Doesn't work here because there is an issue with how we do string type detection in libcloud.compute.deployment and what we set basestring to in libcloud.utils.py3.

if not isinstance(argument_value, basestring) and \
           not hasattr(argument_value, 'read'):

{quote}
svn diff
Index: libcloud/compute/deployment.py
===================================================================
--- libcloud/compute/deployment.py	(revision 1471588)
+++ libcloud/compute/deployment.py	(working copy)
@@ -104,7 +104,7 @@
         """
         perms = int(oct(os.stat(self.source).st_mode)[4:], 8)
 
-        with open(self.source, 'rb') as fp:
+        with open(self.source, 'r') as fp:
             content = fp.read()
 
         client.put(path=self.target, chmod=perms,
Index: libcloud/test/compute/test_deployment.py
===================================================================
--- libcloud/test/compute/test_deployment.py	(revision 1471588)
+++ libcloud/test/compute/test_deployment.py	(working copy)
@@ -115,12 +115,8 @@
                         client=MockClient(hostname='localhost')))
 
     def test_script_file_deployment(self):
-        # TODO: Fix 3.2 compatibility
-        if PY32:
-            return
-
         file_path = os.path.abspath(__file__)
-        with open(file_path, 'rb') as fp:
+        with open(file_path, 'r') as fp:
             content = fp.read()
 
         sfd1 = ScriptFileDeployment(script_file=file_path)
{quote}

{quote}
tox -e py3

======================================================================
ERROR: test_script_file_deployment (libcloud.test.compute.test_deployment.DeploymentTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/w/lc/t1/libcloud/test/compute/test_deployment.py", line 122, in test_script_file_deployment
    sfd1 = ScriptFileDeployment(script_file=file_path)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 193, in __init__
    delete=delete)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 133, in __init__
    argument_value=script)
  File "/w/lc/t1/libcloud/compute/deployment.py", line 52, in _get_string_value
    'object' % (argument_name))
TypeError: script argument must be a string or a file-like object

----------------------------------------------------------------------
Ran 2696 tests in 8.717s

FAILED (errors=1)
[TOX] ERROR: InvocationError: '.tox/py32/bin/python setup.py test'

{quote}

                  
> libcloud.test.compute.test_deployment.DeploymentTests.test_script_file_deployment() fails with Python 3.3
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: LIBCLOUD-321
>                 URL: https://issues.apache.org/jira/browse/LIBCLOUD-321
>             Project: Libcloud
>          Issue Type: Bug
>            Reporter: Arfrever Frehtes Taifersar Arahesis
>
> Libcloud-0.12.4 introduced libcloud.test.compute.test_deployment.DeploymentTests.test_script_file_deployment(), which fails with Python 3.3.
> {code}
> ======================================================================
> ERROR: test_script_file_deployment (libcloud.test.compute.test_deployment.DeploymentTests)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/tmp/apache-libcloud-0.12.4/libcloud/test/compute/test_deployment.py", line 126, in test_script_file_deployment
>     sfd1 = ScriptFileDeployment(script_file=file_path)
>   File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 193, in __init__
>     delete=delete)
>   File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 133, in __init__
>     argument_value=script)
>   File "/tmp/apache-libcloud-0.12.4/libcloud/compute/deployment.py", line 52, in _get_string_value
>     'object' % (argument_name))
> TypeError: script argument must be a string or a file-like object
> ----------------------------------------------------------------------
> {code}
> libcloud.utils.py3.basestring is defined as str for Python 3.
> Deployment._get_string_value() accepts argument_value, which is libcloud.utils.py3.basestring (i.e. str), but ScriptFileDeployment.\_\_init\_\_() opens a file in binary mode, so the result of reading is bytes, not str.
> Potential fix:
> {code}
> --- libcloud/compute/deployment.py
> +++ libcloud/compute/deployment.py
> @@ -185,7 +185,7 @@
>          @type delete: C{bool}
>          @keyword delete: Whether to delete the script on completion.
>          """
> -        with open(script_file, 'rb') as fp:
> +        with open(script_file, 'r') as fp:
>              content = fp.read()
>  
>          super(ScriptFileDeployment, self).__init__(script=content,
> --- libcloud/test/compute/test_deployment.py
> +++ libcloud/test/compute/test_deployment.py
> @@ -115,12 +115,8 @@
>                          client=MockClient(hostname='localhost')))
>  
>      def test_script_file_deployment(self):
> -        # TODO: Fix 3.2 compatibility
> -        if PY32:
> -            return
> -
>          file_path = os.path.abspath(__file__)
> -        with open(file_path, 'rb') as fp:
> +        with open(file_path, 'r') as fp:
>              content = fp.read()
>  
>          sfd1 = ScriptFileDeployment(script_file=file_path)
> {code}
> Alternative fix would be to open file in binary mode and (only when running with Python 3) to decode content from bytes to str.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira