Commits

holger krekel committed f0bc502

don't warn if a test command is specified in a relative manner

  • Participants
  • Parent commits 5e7a891

Comments (0)

Files changed (7)

 1.4.dev
 -----------------
 
+- fix issue26 - no warnings on absolute or relative specified paths for commands
 - fix issue33 - commentchars are ignored in key-value settings allowing
   for specifying commands like: python -c "import sys ; print sys"
   which would formerly raise irritating errors because the ";"
         description='virtualenv-based automation of test activities',
         long_description=long_description,
         url='http://codespeak.net/tox',
-        version='1.4.dev8',
+        version='1.4.dev9',
         license='GPLv2 or later',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
         author='holger krekel',
     )
 
 if __name__ == '__main__':
-    main()
+    main()

File tests/conftest.py

             "looking for %r, no reports found at >=%d in %r" %
             (cat, self._index+1, self._calls))
 
-    def expect(self, cat, messagepattern="*"):
+    def expect(self, cat, messagepattern="*", invert=False):
         __tracebackhide__ = True
         if not messagepattern.startswith("*"):
             messagepattern = "*" + messagepattern
             for lmsg in call[1:]:
                 lmsg = str(lmsg).replace("\n", " ")
                 if fnmatch(lmsg, messagepattern):
+                    if invert:
+                        raise AssertionError("found %s(%r), didn't expect it" %
+                            (cat, messagepattern))
                     return
-        raise AssertionError(
-            "looking for %s(%r), no reports found at >=%d in %r" %
-            (cat, messagepattern, self._index+1, self._calls))
+        if not invert:
+            raise AssertionError(
+             "looking for %s(%r), no reports found at >=%d in %r" %
+                (cat, messagepattern, self._index+1, self._calls))
+
+    def not_expect(self, cat, messagepattern="*"):
+        return self.expect(cat, messagepattern, invert=True)
 
 class pcallMock:
     def __init__(self, args, cwd, env, stdout, stderr, shell):

File tests/test_venv.py

 import py
 import tox
+import pytest
 import os, sys
 from tox._venv import VirtualEnv, CreationConfig, getdigest
 
         # realpath is needed for stuff like the debian symlinks
         assert py.path.local(sys.executable).realpath() == args[0]
         #assert Envconfig.toxworkdir in args
-        assert venv.getcommandpath("easy_install")
+        assert venv.getcommandpath("easy_install", cwd=py.path.local())
     interp = venv._getliveconfig().python
     assert interp == venv.getconfigexecutable()
     assert venv.path_config.check(exists=False)
     venv.test()
     mocksession.report.expect("warning", "*test command found but not*")
 
+@pytest.mark.skipif("not sys.platform.startswith('linux')")
+def test_install_command_not_installed(newmocksession):
+    mocksession = newmocksession(['--recreate'], """
+        [testenv]
+        commands=
+            bash
+    """)
+    venv = mocksession.getenv('python')
+    venv.test()
+    mocksession.report.expect("warning", "*test command found but not*")
+
+
 def test_install_python3(tmpdir, newmocksession):
     if not py.path.local.sysfind('python3.1'):
         py.test.skip("needs python3.1")
     assert env is not None
     assert 'PYTHONIOENCODING' in env
     assert env['PYTHONIOENCODING'] == 'utf_8'
+
+def test_command_relative_issue26(newmocksession, tmpdir, monkeypatch):
+    mocksession = newmocksession([], """
+        [testenv]
+    """)
+    x = tmpdir.ensure("x")
+    venv = mocksession.getenv("python")
+    x2 = venv.getcommandpath("./x", cwd=tmpdir)
+    assert x == x2
+    mocksession.report.not_expect("warning", "*test command found but not*")
+    x3 = venv.getcommandpath("/bin/bash", cwd=tmpdir)
+    assert x3 == "/bin/bash"
+    mocksession.report.not_expect("warning", "*test command found but not*")
+    monkeypatch.setenv("PATH", str(tmpdir))
+    x4 = venv.getcommandpath("x", cwd=tmpdir)
+    mocksession.report.expect("warning", "*test command found but not*")

File tox/__init__.py

 #
-__version__ = '1.4.dev8'
+__version__ = '1.4.dev9'
 
 class exception:
     class Error(Exception):

File tox/_venv.py

     def __repr__(self):
         return "<VirtualEnv at %r>" %(self.path)
 
-    def getcommandpath(self, name=None):
+    def getcommandpath(self, name=None, venv=True, cwd=None):
         if name is None:
             return self.envconfig.envpython
         name = str(name)
         if os.path.isabs(name):
             return name
+        if os.path.split(name)[0] == ".":
+            p = cwd.join(name)
+            if p.check():
+                return str(p)
         p = py.path.local.sysfind(name)
         if p is None:
             raise tox.exception.InvocationError("could not find executable %r"
                 % (name,))
         if p.relto(self.envconfig.envdir):
             return p
+        if venv:
+            self.session.report.warning(
+                "test command found but not installed in testenv\n"
+                "  cmd: %s\n"
+                "  env: %s\n"
+                "Maybe forgot to specify a dependency?" % (p,
+                self.envconfig.envdir))
         return str(p) # will not be rewritten for reporting
 
     def _ispython3(self):
         self.session.make_emptydir(self.path)
         basepath = self.path.dirpath()
         basepath.ensure(dir=1)
-        old = py.path.local()
-        try:
-            basepath.chdir()
-            args.append(self.path.basename)
-            self._pcall(args, venv=False, action=action)
-            #if self._ispython3():
-            #    self.easy_install(["-U", "distribute"])
-        finally:
-            old.chdir()
+        args.append(self.path.basename)
+        self._pcall(args, venv=False, action=action, cwd=basepath)
         self.just_created = True
 
     def install_sdist(self, sdistpath):
             del os.environ['PYTHONDONTWRITEBYTECODE']
         except KeyError:
             pass
-        if cwd:
-            cwd.ensure(dir=1)
-
+        assert cwd
+        cwd.ensure(dir=1)
         old = self.patchPATH()
         try:
-            args[0] = self.getcommandpath(args[0])
-            if venv:
-                if not py.path.local(args[0]).relto(self.envconfig.envdir):
-                    self.session.report.warning(
-                        "test command found but not installed in testenv\n"
-                        "  cmd: %s\n"
-                        "  env: %s\n"
-                        "Maybe forgot to specify a dependency?" % (args[0],
-                        self.envconfig.envdir))
+            args[0] = self.getcommandpath(args[0], venv, cwd)
             env = self._getenv() or os.environ.copy()
             env.update(extraenv)
             return action.popen(args, cwd=cwd, env=env, redirect=redirect)

File toxbootstrap.py

 
 """
 
-__version__ = '1.4.dev8'
+__version__ = '1.4.dev9'
 
 import sys
 import os