from __future__ import with_statement

from fabric.api import *
from fabtools import require
import fabtools


@task
def python():
    """
    Check Python package installation
    """
    require.python.virtualenv('/tmp/venv')
    assert fabtools.files.is_dir('/tmp/venv')
    assert fabtools.files.is_file('/tmp/venv/bin/python')

    with fabtools.python.virtualenv('/tmp/venv'):
        require.python.package('fabric')
    assert fabtools.files.is_file('/tmp/venv/bin/fab')

from __future__ import with_statement

from fabric.api import task


@task
def python_virtualenv():
    """
    Test Python virtualenv creation
    """
    from fabtools import require
    import fabtools

    require.python.virtualenv('/tmp/venv')

    assert fabtools.files.is_dir('/tmp/venv')
    assert fabtools.files.is_file('/tmp/venv/bin/python')


@task
def python_package():
    """
    Test Python package installation
    """
    from fabtools import require
    import fabtools

    require.python.virtualenv('/tmp/venv')
    with fabtools.python.virtualenv('/tmp/venv'):
        require.python.package('fabric', download_cache='/var/cache/pip')

    assert fabtools.files.is_file('/tmp/venv/bin/fab')

Speed up Python tests by caching pip downloads
Speed up Python tests by caching pip downloads

  from __future__ import with_statement
  
- from fabric.api import *
+ from fabric.api import task
- from fabtools import require
- import fabtools
  
  
  @task
- def python():
+ def python_virtualenv():
      """
-     Check Python package installation
+     Test Python virtualenv creation
      """
+     from fabtools import require
+     import fabtools
+ 
      require.python.virtualenv('/tmp/venv')
+ 
      assert fabtools.files.is_dir('/tmp/venv')
      assert fabtools.files.is_file('/tmp/venv/bin/python')
  
+ 
+ @task
+ def python_package():
+     """
+     Test Python package installation
+     """
+     from fabtools import require
+     import fabtools
+ 
+     require.python.virtualenv('/tmp/venv')
      with fabtools.python.virtualenv('/tmp/venv'):
-         require.python.package('fabric')
+         require.python.package('fabric', download_cache='/var/cache/pip')
+ 
      assert fabtools.files.is_file('/tmp/venv/bin/fab')
  
Speed up Python tests by caching pip downloads
## Code Before:
from __future__ import with_statement

from fabric.api import *
from fabtools import require
import fabtools


@task
def python():
    """
    Check Python package installation
    """
    require.python.virtualenv('/tmp/venv')
    assert fabtools.files.is_dir('/tmp/venv')
    assert fabtools.files.is_file('/tmp/venv/bin/python')

    with fabtools.python.virtualenv('/tmp/venv'):
        require.python.package('fabric')
    assert fabtools.files.is_file('/tmp/venv/bin/fab')

## Instruction:
Speed up Python tests by caching pip downloads
## Code After:
from __future__ import with_statement

from fabric.api import task


@task
def python_virtualenv():
    """
    Test Python virtualenv creation
    """
    from fabtools import require
    import fabtools

    require.python.virtualenv('/tmp/venv')

    assert fabtools.files.is_dir('/tmp/venv')
    assert fabtools.files.is_file('/tmp/venv/bin/python')


@task
def python_package():
    """
    Test Python package installation
    """
    from fabtools import require
    import fabtools

    require.python.virtualenv('/tmp/venv')
    with fabtools.python.virtualenv('/tmp/venv'):
        require.python.package('fabric', download_cache='/var/cache/pip')

    assert fabtools.files.is_file('/tmp/venv/bin/fab')
