<s> import os <EOL> import sys <EOL> from subprocess import check_call , CalledProcessError <EOL> from pathlib import Path <EOL> from shutil import rmtree <EOL> from tempfile import gettempdir <EOL> import pytest <EOL> from pew . _utils import temp_environ , invoke_pew as invoke <EOL> from utils import skip_windows <EOL> @ pytest . yield_fixture ( scope = '<STR_LIT>' ) <EOL> def project_home ( ) : <EOL> tmpdir = os . environ . get ( '<STR_LIT>' , gettempdir ( ) ) <EOL> project = Path ( tmpdir ) / '<STR_LIT>' <EOL> os . environ [ '<STR_LIT>' ] = str ( project ) <EOL> rmtree ( str ( project ) , ignore_errors = True ) <EOL> project . mkdir ( parents = True ) <EOL> yield project <EOL> rmtree ( str ( project ) ) <EOL> @ pytest . yield_fixture ( ) <EOL> def project ( workon_home , project_home ) : <EOL> projname = '<STR_LIT>' <EOL> invoke ( '<STR_LIT>' , projname , '<STR_LIT>' ) <EOL> yield projname <EOL> invoke ( '<STR_LIT>' , projname ) <EOL> rmtree ( str ( project_home / projname ) ) <EOL> def test_create_directories ( workon_home , project_home , project ) : <EOL> assert ( workon_home / project ) . exists ( ) <EOL> assert ( project_home / project ) . exists ( ) <EOL> check_env = [ sys . executable , '<STR_LIT:-c>' , "<STR_LIT>" ] <EOL> def test_create_virtualenv ( project_home , project ) : <EOL> env = Path ( invoke ( '<STR_LIT>' , project , * check_env ) . out ) <EOL> assert project == env . name <EOL> with ( env / '<STR_LIT>' ) . open ( ) as f : <EOL> assert str ( project_home . absolute ( ) / project ) == f . read ( ) . strip ( ) <EOL> def test_no_project_home ( project_home ) : <EOL> with temp_environ ( ) : <EOL> os . environ [ '<STR_LIT>' ] += '<STR_LIT>' <EOL> with pytest . raises ( CalledProcessError ) : <EOL> check_call ( '<STR_LIT>' . split ( ) ) <EOL> def test_project_exists ( project ) : <EOL> with pytest . raises ( CalledProcessError ) : <EOL> check_call ( '<STR_LIT>' . format ( project ) . split ( ) ) <EOL> def test_same_workon_and_project_home ( workon_home , project_home ) : <EOL> with temp_environ ( ) : <EOL> os . environ [ '<STR_LIT>' ] = str ( workon_home ) <EOL> envname = '<STR_LIT>' <EOL> with pytest . raises ( CalledProcessError ) : <EOL> check_call ( '<STR_LIT>' . format ( envname ) . split ( ) ) <EOL> assert ( workon_home / envname ) . exists ( ) <EOL> assert not ( project_home / envname ) . exists ( ) <EOL> def test_list_templates ( testtemplate ) : <EOL> assert '<STR_LIT:test>' in invoke ( '<STR_LIT>' , '<STR_LIT>' ) . out <EOL> @ skip_windows ( reason = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_apply_template ( project_home , testtemplate ) : <EOL> projname = '<STR_LIT>' <EOL> invoke ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' , projname , '<STR_LIT>' ) <EOL> testfile = project_home / projname / '<STR_LIT>' <EOL> assert testfile . exists ( ) <EOL> with testfile . open ( ) as f : <EOL> assert projname in f . read ( ) <EOL> invoke ( '<STR_LIT>' , projname ) <EOL> rmtree ( str ( project_home / projname ) ) </s>
