Commits

holger krekel committed eb540f2

fix test runs on environments without a home directory
(in which case we use toxinidir as the homedir)

  • Participants
  • Parent commits cf9ab53

Comments (0)

Files changed (4)

 - fix issue118: correctly have two tests use realpath(). Thanks Barry
   Warsaw.
 
+- fix test runs on environments without a home directory
+  (in this case we use toxinidir as the homedir)
+
 1.6.0
 -----------------
 

File tests/test_config.py

     def test_defaults_distshare(self, tmpdir, newconfig):
         config = newconfig([], "")
         envconfig = config.envconfigs['python']
-        homedir = py.path.local._gethomedir()
-        assert config.distshare == homedir.join(".tox", "distshare")
+        assert config.distshare == config.homedir.join(".tox", "distshare")
 
     def test_defaults_changed_dir(self, tmpdir, newconfig):
         tmpdir.mkdir("abc").chdir()
             old.chdir()
         assert config.toxinipath == toxinipath
 
+def test_get_homedir(monkeypatch):
+    monkeypatch.setattr(py.path.local, "_gethomedir",
+                        classmethod(lambda x: {}[1]))
+    assert not get_homedir()
+    monkeypatch.setattr(py.path.local, "_gethomedir",
+                        classmethod(lambda x: 0/0))
+    assert not get_homedir()
+    monkeypatch.setattr(py.path.local, "_gethomedir",
+                        classmethod(lambda x: "123"))
+    assert get_homedir() == "123"
+
+
 class TestIniParser:
     def test_getdefault_single(self, tmpdir, newconfig):
         config = newconfig("""
         assert argv[3][0] == conf.envbindir
         assert argv[4][0] == conf.envtmpdir
         assert argv[5][0] == conf.envpython
-        assert argv[6][0] == str(py.path.local._gethomedir())
+        assert argv[6][0] == str(config.homedir)
         assert argv[7][0] == config.homedir.join(".tox", "distshare")
         assert argv[8][0] == conf.envlogdir
 
                 pypi    = http://pypi.python.org/simple
         """
         config = newconfig([], inisource)
-        homedir = str(py.path.local._gethomedir())
-        expected = "file://%s/.pip/downloads/simple" % homedir
+        expected = "file://%s/.pip/downloads/simple" % config.homedir
         assert config.indexserver['default'].url == expected
         assert config.indexserver['local1'].url == \
                config.indexserver['default'].url

File tests/test_z_cmdline.py

     sdist_path = session.sdist()
     assert sdist_path == p
 
-#@pytest.mark.xfail("sys.platform == 'win32'", reason="test needs better impl")
+@pytest.mark.xfail("sys.platform == 'win32' and sys.version_info < (2,6)",
+                   reason="test needs better impl")
 def test_envsitepackagesdir(cmd, initproj):
     initproj("pkg512-0.0.5", filedefs={
         'tox.ini': """
         [testenv]
         commands=
-            python -c "print('X:{envsitepackagesdir}')"
+            python -c "print(r'X:{envsitepackagesdir}')"
     """})
     result = cmd.run("tox")
     assert result.ret == 0
     result.stdout.fnmatch_lines("""
-        X:*.tox*python*site-packages*
+        X:*tox*site-packages*
     """)
 
 def verify_json_report_format(data, testenvs=True):

File tox/_config.py

         help="additional arguments available to command positional substition")
     return parser
 
-class Config:
+class Config(object):
     def __init__(self):
         self.envconfigs = {}
         self.invocationcwd = py.path.local()
         self.interpreters = Interpreters()
 
+    @property
+    def homedir(self):
+        homedir = get_homedir()
+        if homedir is None:
+            homedir = self.toxinidir  # XXX good idea?
+        return homedir
+
 class VenvConfig:
     def __init__(self, **kw):
         self.__dict__.update(kw)
 
 testenvprefix = "testenv:"
 
+def get_homedir():
+    try:
+        return py.path.local._gethomedir()
+    except Exception:
+        return None
+
 class parseini:
     def __init__(self, config, inipath):
         config.toxinipath = inipath
         else:
             raise ValueError("invalid context")
 
-        config.homedir = py.path.local._gethomedir()
-        if config.homedir is None:
-            config.homedir = config.toxinidir  # XXX good idea?
+
         reader.addsubstitions(toxinidir=config.toxinidir,
                               homedir=config.homedir)
         config.toxworkdir = reader.getpath(toxsection, "toxworkdir",