def setup_class(self): # It's not ideal that we make a virtualenv only once, # but I'd rather do this than use a fake virtualenv # or wait an hour for tests to finish most of the time self.parent = TempDir() self.venv = TempVenv(self.parent.path, "vex_tests", []) self.venv.open()
def test_remove(self): parent = TempDir() home = TempDir() env = { "HOME": home.path, "WORKON_HOME": parent.path.decode("utf-8") } venv = TempVenv(parent.path, "vex_tests", []) venv.open() assert os.path.exists(venv.path) assert os.path.exists(parent.path) run = Run(["--remove", venv.name, "echo", "42"], env=env) vexrc = TempVexrcFile( home.path, ) with home, vexrc, run: run.finish() assert run.out is not None assert b"42" in run.out assert run.command_found assert run.returned == 0 assert not run.err assert not os.path.exists(venv.path) assert os.path.exists(parent.path) venv.close() parent.close()
def setup_class(self): # It's not ideal that we make a virtualenv only once, # but I'd rather do this than use a fake virtualenv # or wait an hour for tests to finish most of the time self.parent = TempDir() self.venv = TempVenv(self.parent.path, 'vex_tests', []) self.venv.open()
def test_remove(self): parent = TempDir() venv = TempVenv(parent.path, 'vex_tests', []) venv.open() assert os.path.exists(venv.path) assert os.path.exists(parent.path) env = {'WORKON_HOME': parent.path.decode('utf-8')} with Run(['--remove', venv.name, 'echo', '42'], env=env) as run: run.finish() assert run.out is not None assert b'42' in run.out assert run.command_found assert run.returned == 0 assert not run.err assert not os.path.exists(venv.path) assert os.path.exists(parent.path) venv.close() parent.close()
def test_find_with_HOME(): """vex venvname echo foo with HOME set to a path containing a .virtualenvs dir containing a directory named venvname, resolve venvname as that directory and run without error. """ # 1. Make a temp directory # 2. Point the HOME variable at that # 3. Make a .virtualenvs directory in it # 4. Make a tempvenv inside that (time-consuming though...) # 5. run vex, passing basename of the tempvenv home = TempDir() workon_home = os.path.join(home.path, b".virtualenvs") assert isinstance(workon_home, path_type) os.mkdir(workon_home) name = "vex_test_find_with_HOME" venv = TempVenv(workon_home, name, []) env = {"HOME": home.path} with home, venv, Run([name, "echo", "foo"], env=env) as run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b"foo\n"
def test_remove(self): parent = TempDir() home = TempDir() env = {"HOME": home.path, "WORKON_HOME": parent.path.decode("utf-8")} venv = TempVenv(parent.path, "vex_tests", []) venv.open() assert os.path.exists(venv.path) assert os.path.exists(parent.path) run = Run(["--remove", venv.name, "echo", "42"], env=env) vexrc = TempVexrcFile(home.path, ) with home, vexrc, run: run.finish() assert run.out is not None assert b"42" in run.out assert run.command_found assert run.returned == 0 assert not run.err assert not os.path.exists(venv.path) assert os.path.exists(parent.path) venv.close() parent.close()
class TestWithVirtualenv(object): def setup_class(self): # It's not ideal that we make a virtualenv only once, # but I'd rather do this than use a fake virtualenv # or wait an hour for tests to finish most of the time self.parent = TempDir() self.venv = TempVenv(self.parent.path, "vex_tests", []) self.venv.open() def teardown_class(self): try: self.venv.close() finally: self.parent.close() def test_virtualenv_created(self): """Spurious test showing the "test fixture" set up """ bin_path = os.path.join(self.venv.path, b"bin") assert isinstance(bin_path, path_type) assert os.path.exists(bin_path) def test_inappropriate_abspath(self): """vex /stupid/absolute/path echo foo This should be rejected with a non-traceback error """ assert self.venv.path != self.venv.name assert len(self.venv.path) > len(self.venv.name) assert os.path.abspath(self.venv.path) == self.venv.path with Run([self.venv.path, "echo", "foo"]) as run: run.finish() assert run.command_found assert run.returned == 1 assert run.out != b"foo\n" assert b"Traceback" not in run.err assert b"AssertionError" not in run.err def test_find_with_vexrc(self): """vex venvname echo foo with $HOME pointing to a directory containing a .vexrc file which contains a virtualenvs= line, resolve first positional argument as virtualenv name under the path given in the .vexrc. """ # 1. Make a temp directory to play the role as HOME # 2. Point the HOME environment variable at that directory # 3. Make a temp vexrc in that directory. # This has a virtualenvs= line which points at # the directory containing the temp virtualenv. # 4. run vex home = TempDir() env = {"HOME": home.path} vexrc = TempVexrcFile(home.path, virtualenvs=self.parent.path.decode("utf-8")) assert isinstance(home.path, path_type) assert isinstance(vexrc.file_path, path_type) assert os.path.exists(vexrc.file_path) run = Run([self.venv.name, "echo", "foo"], env=env) with home, vexrc, run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b"foo\n" def test_find_with_config_option_vexrc(self): """vex --config somefile venvname echo foo with arbitrary path passed as --config, being the location of a .vexrc containing a virtualenvs= line, resolve first positional argument as virtualenv name under the path given in the .vexrc. """ # 1. Make a temp directory to play the role as HOME # 2. Point the HOME environment variable at that directory # 3. Make a temp vexrc in that directory. # This has a virtualenvs= line which points at # the directory containing the temp virtualenv. # 4. run vex home = TempDir() vexrc = TempVexrcFile(home.path, virtualenvs=self.parent.path.decode("utf-8")) assert isinstance(home.path, path_type) assert isinstance(vexrc.file_path, path_type) assert os.path.exists(vexrc.file_path) run = Run(["--config", vexrc.file_path, self.venv.name, "echo", "foo"]) with home, vexrc, run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b"foo\n" def test_find_with_WORKON_HOME(self): """vex venvname echo foo with $WORKON_HOME set and nothing else, resolve first positional argument as virtualenv name under $WORKON_HOME/ """ # This one is easier, we just point WORKON_HOME # at the directory containing our venv env = { "HOME": "ignore", "WORKON_HOME": self.parent.path.decode("utf-8") } with Run([self.venv.name, "echo", "foo"], env=env) as run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b"foo\n" def test_find_with_path_option(self): """vex --path venvpath echo foo no error, echoes foo """ with Run(["--path", self.venv.path, "echo", "foo"]) as run: run.finish() assert os.path.abspath(self.venv.path) == self.venv.path assert not run.err, "unexpected stderr output: %r" % run.err assert run.command_found assert run.returned == 0 assert run.out == b"foo\n" def test_cwd_option(self): """vex --cwd cwdpath venvname pwd prints out the value of cwdpath, no errors """ env = { "HOME": "ignore", "WORKON_HOME": self.parent.path.decode("utf-8") } with EmptyTempDir() as cwd, \ Run(["--cwd", cwd.path, self.venv.name, "pwd"], env=env) as run: run.finish() assert run.command_found assert not run.err.startswith(b"Traceback") assert run.returned == 0 assert cwd.path assert self.venv.path assert cwd.path != self.venv.path assert cwd.path != self.parent.path assert run.out == cwd.path + b"\n" def test_invalid_cwd(self): """vex --cwd nonexistentpath venvname pwd error but no traceback """ env = {"WORKON_HOME": self.parent.path.decode("utf-8")} cwd = os.path.join("tmp", "reallydoesnotexist") assert not os.path.exists(cwd) with Run(["--cwd", cwd, self.venv.name, "pwd"], env=env) as run: run.finish() assert run.command_found assert run.err assert not run.err.startswith(b"Traceback") assert run.returned == 1
class TestWithVirtualenv(object): def setup_class(self): # It's not ideal that we make a virtualenv only once, # but I'd rather do this than use a fake virtualenv # or wait an hour for tests to finish most of the time self.parent = TempDir() self.venv = TempVenv(self.parent.path, 'vex_tests', []) self.venv.open() def teardown_class(self): try: self.venv.close() finally: self.parent.close() def test_virtualenv_created(self): """Spurious test showing the 'test fixture' set up """ bin_path = os.path.join(self.venv.path, b'bin') assert isinstance(bin_path, path_type) assert os.path.exists(bin_path) def test_inappropriate_abspath(self): """vex /stupid/absolute/path echo foo This should be rejected with a non-traceback error """ assert self.venv.path != self.venv.name assert len(self.venv.path) > len(self.venv.name) assert os.path.abspath(self.venv.path) == self.venv.path with Run([self.venv.path, 'echo', 'foo']) as run: run.finish() assert run.command_found assert run.returned == 1 assert run.out != b'foo\n' assert b'Traceback' not in run.err assert b'AssertionError' not in run.err def test_find_with_vexrc(self): """vex venvname echo foo with $HOME pointing to a directory containing a .vexrc file which contains a virtualenvs= line, resolve first positional argument as virtualenv name under the path given in the .vexrc. """ # 1. Make a temp directory to play the role as HOME # 2. Point the HOME environment variable at that directory # 3. Make a temp vexrc in that directory. # This has a virtualenvs= line which points at # the directory containing the temp virtualenv. # 4. run vex home = TempDir() env = {'HOME': home.path} vexrc = TempVexrcFile( home.path, virtualenvs=self.parent.path.decode('utf-8')) assert isinstance(home.path, path_type) assert isinstance(vexrc.file_path, path_type) assert os.path.exists(vexrc.file_path) run = Run([self.venv.name, 'echo', 'foo'], env=env) with home, vexrc, run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b'foo\n' def test_find_with_config_option_vexrc(self): """vex --config somefile venvname echo foo with arbitrary path passed as --config, being the location of a .vexrc containing a virtualenvs= line, resolve first positional argument as virtualenv name under the path given in the .vexrc. """ # 1. Make a temp directory to play the role as HOME # 2. Point the HOME environment variable at that directory # 3. Make a temp vexrc in that directory. # This has a virtualenvs= line which points at # the directory containing the temp virtualenv. # 4. run vex home = TempDir() vexrc = TempVexrcFile( home.path, virtualenvs=self.parent.path.decode('utf-8')) assert isinstance(home.path, path_type) assert isinstance(vexrc.file_path, path_type) assert os.path.exists(vexrc.file_path) run = Run(['--config', vexrc.file_path, self.venv.name, 'echo', 'foo']) with home, vexrc, run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b'foo\n' def test_find_with_WORKON_HOME(self): """vex venvname echo foo with $WORKON_HOME set and nothing else, resolve first positional argument as virtualenv name under $WORKON_HOME/ """ # This one is easier, we just point WORKON_HOME # at the directory containing our venv env = {'HOME': 'ignore', 'WORKON_HOME': self.parent.path.decode('utf-8')} with Run([self.venv.name, 'echo', 'foo'], env=env) as run: run.finish() assert run.command_found assert run.returned == 0 assert run.out == b'foo\n' def test_find_with_path_option(self): """vex --path venvpath echo foo no error, echoes foo """ with Run(["--path", self.venv.path, 'echo', 'foo']) as run: run.finish() assert os.path.abspath(self.venv.path) == self.venv.path assert not run.err, "unexpected stderr output: %r" % run.err assert run.command_found assert run.returned == 0 assert run.out == b'foo\n' def test_cwd_option(self): """vex --cwd cwdpath venvname pwd prints out the value of cwdpath, no errors """ env = {'HOME': 'ignore', 'WORKON_HOME': self.parent.path.decode('utf-8')} with EmptyTempDir() as cwd, \ Run(['--cwd', cwd.path, self.venv.name, 'pwd'], env=env) as run: run.finish() assert run.command_found assert not run.err.startswith(b'Traceback') assert run.returned == 0 assert cwd.path assert self.venv.path assert cwd.path != self.venv.path assert cwd.path != self.parent.path assert run.out == cwd.path + b'\n' def test_invalid_cwd(self): """vex --cwd nonexistentpath venvname pwd error but no traceback """ env = {'WORKON_HOME': self.parent.path.decode('utf-8')} cwd = os.path.join('tmp', 'reallydoesnotexist') assert not os.path.exists(cwd) with Run(['--cwd', cwd, self.venv.name, 'pwd'], env=env) as run: run.finish() assert run.command_found assert run.err assert not run.err.startswith(b'Traceback') assert run.returned == 1