def test_fixup_script_no_shebang(self): """Verify if there is no shebang nothing is altered""" script = ( """%s/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'console_scripts' import sys if __name__ == '__main__': print('Testing VirtualEnv-Clone!') sys.exit()""" % venv_path ) # want to do this manually, # so going to call clone before the file exists # run virtualenv-clone sys.argv = ["virtualenv-clone", venv_path, clone_path] clonevirtualenv.main() root = os.path.join(clone_path, "bin") new_ = os.path.join(clone_path, "bin", "clonetest") # write the file straight to the cloned with open(new_, "w") as f: f.write(script) # run fixup clonevirtualenv.fixup_script_(root, "clonetest", venv_path, clone_path, "2.7") with open(new_, "r") as f: data = f.read() assert venv_path in data assert clone_path not in data assert clone_path + "/bin/python2.7" not in data
def test_clone_syspath(self): """ Verify syspath for cloned virtualenvs This really is a test for fixup_syspath as well """ for version in start_version_test(): # run virtualenv-clone sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() sys_path = clonevirtualenv._virtualenv_sys(clone_path)[1] assert isinstance(sys_path, list), "Path information needs to be a list" 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()
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()
def test_fixup_script_no_shebang(self): '''Verify if there is no shebang nothing is altered''' script = '''%s/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'console_scripts' import sys if __name__ == '__main__': print('Testing VirtualEnv-Clone!') sys.exit()''' % venv_path # want to do this manually, # so going to call clone before the file exists # run virtualenv-clone sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() root = os.path.join(clone_path, 'bin') new_ = os.path.join(clone_path, 'bin', 'clonetest') # write the file straight to the cloned with open(new_, 'w') as f: f.write(script) # run fixup clonevirtualenv.fixup_script_(root, 'clonetest', venv_path, clone_path, '2.7') with open(new_, 'r') as f: data = f.read() assert venv_path in data assert clone_path not in data assert clone_path + '/bin/python2.7' not in data
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()
def test_fixup_script_version(self): '''Verify if version is updated''' script = '''#!%s/bin/python2.7 # EASY-INSTALL-ENTRY-SCRIPT: 'console_scripts' import sys if __name__ == '__main__': print('Testing VirtualEnv-Clone!') sys.exit()''' % venv_path # want to do this manually, # so going to call clone before the file exists # run virtualenv-clone sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() root = os.path.join(clone_path, 'bin') new_ = os.path.join(clone_path, 'bin', 'clonetest') # write the file straight to the cloned with open(new_, 'w') as f: f.write(script) # run fixup clonevirtualenv.fixup_script_(root, 'clonetest', venv_path, clone_path, '2.7') with open(new_, 'r') as f: data = f.read() assert venv_path not in data assert clone_path in data assert clone_path + '/bin/python2.7' in data
def test_clone_exists(self): """Verify a cloned virtualenv exists""" # run virtualenv-clone sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() # verify cloned venv exists at the path specified assert os.path.exists(clone_path), 'Cloned Virtualenv does not exists'
def test_clone_with_bad_src(self): sys.argv = [ 'virtualenv-clone', os.path.join('this', 'venv', 'does', 'not', 'exist'), clone_path ] with raises(SystemExit): clonevirtualenv.main()
def test_clone_version(self): """Verify version for cloned virtualenvs""" for version in start_version_test(): # 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_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_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_contents(self): """Walk the virtualenv and verify clonedenv contents""" sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() version = clonevirtualenv._virtualenv_sys(venv_path)[0] for root, dirs, files in os.walk(venv_path): clone_root = root.replace(venv_path,clone_path) for dir_ in dirs: dir_in_clone = os.path.join(clone_root,dir_) assert os.path.exists(dir_in_clone),\ 'Directory %s is missing from cloned virtualenv' % dir_ for file_ in files: if file_.endswith('.pyc') or\ file_.endswith('.exe') or\ file_.endswith('.egg') or\ file_ in ['python', 'python%s' % version]: # binarys fail reading and # compiled will be recompiled continue file_in_clone = os.path.join(clone_root,file_) assert os.path.exists(file_in_clone),\ 'File %s is missing from cloned virtualenv' % file_ if os.path.islink(file_in_clone): target = os.readlink(file_in_clone) assert venv_path != target assert venv_path not in target assert os.path.basename(venv_path) not in target continue with open(file_in_clone, 'rb') as f: lines = f.read().decode('utf-8') assert venv_path not in lines,\ 'Found source path in cloned file %s' % file_in_clone
def test_clone_contents(self): """Walk the virtualenv and verify clonedenv contents""" sys.argv = ['virtualenv-clone', venv_path, clone_path] clonevirtualenv.main() version = clonevirtualenv._virtualenv_sys(venv_path)[0] for root, dirs, files in os.walk(venv_path): clone_root = root.replace(venv_path, clone_path) for dir_ in dirs: dir_in_clone = os.path.join(clone_root, dir_) assert os.path.exists(dir_in_clone),\ 'Directory %s is missing from cloned virtualenv' % dir_ for file_ in files: if file_.endswith('.pyc') or\ file_.endswith('.exe') or\ file_.endswith('.egg') or\ file_ in ['python', 'python%s' % version]: # binarys fail reading and # compiled will be recompiled continue file_in_clone = os.path.join(clone_root, file_) assert os.path.exists(file_in_clone),\ 'File %s is missing from cloned virtualenv' % file_ if os.path.islink(file_in_clone): target = os.readlink(file_in_clone) assert venv_path != target assert venv_path not in target assert os.path.basename(venv_path) not in target continue with open(file_in_clone, 'rb') as f: lines = f.read().decode('utf-8') assert venv_path not in lines,\ 'Found source path in cloned file %s' % file_in_clone
def test_clone_contents(self): """Walk the virtualenv and verify clonedenv contents""" sys.argv = ["virtualenv-clone", venv_path, clone_path] clonevirtualenv.main() version = clonevirtualenv._virtualenv_sys(venv_path)[0] for root, dirs, files in os.walk(venv_path): clone_root = root.replace(venv_path, clone_path) for dir_ in dirs: dir_in_clone = os.path.join(clone_root, dir_) assert os.path.exists(dir_in_clone), "Directory %s is missing from cloned virtualenv" % dir_ for file_ in files: if ( file_.endswith(".pyc") or file_.endswith(".exe") or file_.endswith(".egg") or file_ in ["python", "python%s" % version] ): # binarys fail reading and # compiled will be recompiled continue file_in_clone = os.path.join(clone_root, file_) assert os.path.exists(file_in_clone), "File %s is missing from cloned virtualenv" % file_ if os.path.islink(file_in_clone): target = os.readlink(file_in_clone) assert venv_path != target assert venv_path not in target assert os.path.basename(venv_path) not in target continue with open(file_in_clone, "rb") as f: lines = f.read().decode("utf-8") assert venv_path not in lines, "Found source path in cloned file %s" % file_in_clone
def test_clone_with_bad_src(self): sys.argv = ["virtualenv-clone", os.path.join("this", "venv", "does", "not", "exist"), clone_path] with raises(SystemExit): clonevirtualenv.main()
def test_clone_with_1_arg(self): sys.argv = ['virtualenv-clone', venv_path] with raises(SystemExit): clonevirtualenv.main()
def test_clone_with_bad_src(self): sys.argv = ['virtualenv-clone', os.path.join('this','venv','does','not','exist'), clone_path] with raises(SystemExit): clonevirtualenv.main()
def test_clone_with_no_args(self): sys.argv = ['virtualenv-clone'] with raises(SystemExit): clonevirtualenv.main()