def test_get_ve_base_not_in_vexrc_no_values(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] assert 'virtualenvs' not in root with FakeEnviron(WORKON_HOME='tempting', HOME='nonsense'), \ PatchedModule(os.path, expanduser=lambda p: ''): environ = {'WORKON_HOME': '', 'HOME': ''} assert vexrc.get_ve_base(environ) == ''
def test_get_ve_base_not_in_vexrc_no_values(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] assert "virtualenvs" not in root with FakeEnviron(WORKON_HOME="tempting", HOME="nonsense"), \ PatchedModule(os.path, expanduser=lambda p: ""): environ = {"WORKON_HOME": "", "HOME": ""} assert vexrc.get_ve_base(environ) == ""
def test_get_ve_base_in_vexrc_file(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] fake_exists = make_fake_exists(['/specific/override']) root['virtualenvs'] = '/specific/override' with FakeEnviron(WORKON_HOME='tempting', HOME='nonsense'), \ PatchedModule(os.path, exists=fake_exists): environ = {'WORKON_HOME': '/bad1', 'HOME': '/bad2'} assert vexrc.get_ve_base(environ) == '/specific/override'
def test_get_ve_base_not_in_vexrc_file_rather_home(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] assert 'virtualenvs' not in root fake_exists = make_fake_exists(['/home/user', '/home/user/.virtualenvs']) with FakeEnviron(WORKON_HOME='tempting', HOME='nonsense'), \ PatchedModule(os.path, exists=fake_exists): environ = {'HOME': '/home/user'} assert vexrc.get_ve_base(environ) == '/home/user/.virtualenvs'
def test_get_ve_base_in_vexrc_file(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] fake_exists = make_fake_exists(["/specific/override"]) root["virtualenvs"] = "/specific/override" with FakeEnviron(WORKON_HOME="tempting", HOME="nonsense"), \ PatchedModule(os.path, exists=fake_exists): environ = {"WORKON_HOME": "/bad1", "HOME": "/bad2"} assert vexrc.get_ve_base(environ) == "/specific/override"
def test_get_ve_base_not_in_vexrc_file_rather_workon_home(self): vexrc = config.Vexrc() root = vexrc.headings[vexrc.default_heading] assert "virtualenvs" not in root fake_exists = make_fake_exists(["/workon/home"]) with FakeEnviron(WORKON_HOME="tempting", HOME="nonsense"), \ PatchedModule(os.path, exists=fake_exists): environ = {"WORKON_HOME": "/workon/home", "HOME": "/bad"} assert vexrc.get_ve_base(environ) == "/workon/home"
def test_ve_base_fake_windows(self): vexrc = config.Vexrc() environ = {'HOMEDRIVE': 'C:', 'HOMEPATH': 'foo', 'WORKON_HOME': ''} with patch('platform.system', return_value='Windows'), \ patch('os.name', new='nt'), \ patch('os.path.exists', return_value=True), \ patch('os.path.isfile', return_value=False): path = vexrc.get_ve_base(environ) import platform assert platform.system() == 'Windows' assert os.name == 'nt' import logging logging.error("path is %r", path) assert path assert path.startswith('C:')
def test_ve_base_fake_windows(self): vexrc = config.Vexrc() environ = {"HOMEDRIVE": "C:", "HOMEPATH": "foo", "WORKON_HOME": ""} with patch("platform.system", return_value="Windows"), \ patch("os.name", new="nt"), \ patch("os.path.exists", return_value=True), \ patch("os.path.isfile", return_value=False): path = vexrc.get_ve_base(environ) import platform assert platform.system() == "Windows" assert os.name == "nt" import logging logging.error("path is %r", path) assert path assert path.startswith("C:")
def test_read_nonexistent(self): vexrc = config.Vexrc() vexrc.read('unlikely_to_exist_1293', {})