import os
import subprocess
from unittest import TestCase
import clonevirtualenv
import sys
from tests import venv_path, clone_path, versions, clean

class TestVirtualenvSys(TestCase):

    def setUp(self):
        """Clean from previous testing"""
        clean()

    def tearDown(self):
        """Clean up our testing"""
        clean()

    def test_virtualenv_versions(self):
        """Verify version for created virtualenvs"""
        for version in versions:
            # create a virtualenv
            assert subprocess.call(['virtualenv', '-p', 'python' + version,
                    venv_path]) == 0, "Error running virtualenv"

            venv_version = clonevirtualenv._virtualenv_sys(venv_path)[0]
            assert version == venv_version, 'Expected version %s' % version

            # clean so next venv can be made
            clean()

    def test_virtualenv_syspath(self):
        """Verify syspath for created virtualenvs"""
        for version in versions:
            # create a virtualenv
            assert subprocess.call(['virtualenv', '-p', 'python' + version,
                    venv_path]) == 0, "Error running virtualenv"

            sys_path = clonevirtualenv._virtualenv_sys(venv_path)[1]

            paths = [path for path in sys_path]
            assert paths, "There should be path information"

            # clean so next venv can be made
            clean()

    def test_clone_version(self):
        """Verify version for cloned virtualenvs"""
        for version in versions:
            # create a virtualenv
            assert subprocess.call(['virtualenv', '-p', 'python' + version,
                    venv_path]) == 0, "Error running virtualenv"

            # run virtualenv-clone
            sys.argv = ['virtualenv-clone', venv_path, clone_path]
            clonevirtualenv.main()

            clone_version = clonevirtualenv._virtualenv_sys(clone_path)[0]
            assert version == clone_version, 'Expected version %s' % version

            # clean so next venv can be made
            clean()

    def test_clone_syspath(self):
        """
        Verify syspath for cloned virtualenvs

        This really is a test for fixup_syspath as well
        """
        for version in versions:
            # create a virtualenv
            assert subprocess.call(['virtualenv', '-p', 'python' + version,
                    venv_path]) == 0, "Error running virtualenv"

            # run virtualenv-clone
            sys.argv = ['virtualenv-clone', venv_path, clone_path]
            clonevirtualenv.main()

            sys_path = clonevirtualenv._virtualenv_sys(clone_path)[1]

            paths = [path for path in sys_path]
            assert paths, "There should be path information"

            assert venv_path not in paths,\
                "There is reference to the source virtualenv"

            for path in paths:
                assert os.path.basename(venv_path) not in path,\
                    "There is reference to the source virtualenv:\n%s" % path

            # clean so next venv can be made
            clean()

@@ -143,16 +143,358 @@
  clean%0A%0A
+%0Adef start_version_test():%0A    ran_once = False%0A    for version in versions:%0A        # create a virtualenv%0A        if subprocess.call(%5B'virtualenv', '-p', 'python' + version,%0A                            venv_path%5D) != 0:%0A            continue%0A%0A        ran_once = True%0A        yield version%0A%0A    assert ran_once, %22All versions were skipped.%22%0A%0A%0A
 class Te
@@ -797,193 +797,29 @@
  in 
-versions:%0A            # create a virtualenv%0A            assert subprocess.call(%5B'virtualenv', '-p', 'python' + version,%0A                    venv_path%5D) == 0, %22Error running virtualenv%22%0A
+start_version_test():
 %0A   
@@ -1150,193 +1150,29 @@
  in 
-versions:%0A            # create a virtualenv%0A            assert subprocess.call(%5B'virtualenv', '-p', 'python' + version,%0A                    venv_path%5D) == 0, %22Error running virtualenv%22%0A
+start_version_test():
 %0A   
@@ -1527,193 +1527,29 @@
  in 
-versions:%0A            # create a virtualenv%0A            assert subprocess.call(%5B'virtualenv', '-p', 'python' + version,%0A                    venv_path%5D) == 0, %22Error running virtualenv%22%0A
+start_version_test():
 %0A   
@@ -2090,193 +2090,29 @@
  in 
-versions:%0A            # create a virtualenv%0A            assert subprocess.call(%5B'virtualenv', '-p', 'python' + version,%0A                    venv_path%5D) == 0, %22Error running virtualenv%22%0A
+start_version_test():
 %0A   

Test only available versions of Python.