From 5260180521c416adf115b4117281221d747fe926 2011-06-26 09:20:44 From: Min RK Date: 2011-06-26 09:20:44 Subject: [PATCH] fix various tests on Windows Windows had a variety of mostly path-related test failures remaining. Most of these were Windows-excluding assumptions in the tests themselves. The one change to the code itself is stripping quotation marks on Windows in magic_cd. os.chdir doesn't like the quotes on Windows. absolute-path completions are now listed as a KnownFailure on Windows --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 80c7bb5..1c8b2bd 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2832,10 +2832,13 @@ Defaulting color scheme to 'NoColor'""" if opts.has_key('b'): raise UsageError("Bookmark '%s' not found. " "Use '%%bookmark -l' to see your bookmarks." % ps) - + + # strip extra quotes on Windows, because os.chdir doesn't like them + if sys.platform == 'win32': + ps = ps.strip('\'"') # at this point ps should point to the target dir if ps: - try: + try: os.chdir(os.path.expanduser(ps)) if hasattr(self.shell, 'term_title') and self.shell.term_title: set_term_title('IPython: ' + abbrev_cwd()) diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index e3ae238..58caa26 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -14,6 +14,7 @@ import nose.tools as nt # our own packages from IPython.core import completer +from IPython.external.decorators import knownfailureif from IPython.utils.tempdir import TemporaryDirectory #----------------------------------------------------------------------------- @@ -136,9 +137,8 @@ def test_has_open_quotes4(): for s in ['""', '""" """', '"hi" "ipython"']: nt.assert_false(completer.has_open_quotes(s)) - -def test_file_completions(): - +@knownfailureif(sys.platform == 'win32', "abspath completions fail on Windows") +def test_abspath_file_completions(): ip = get_ipython() with TemporaryDirectory() as tmpdir: prefix = os.path.join(tmpdir, 'foo') @@ -156,3 +156,28 @@ def test_file_completions(): c = ip.complete(prefix, cmd)[1] comp = [prefix+s for s in suffixes] nt.assert_equal(c, comp) + +def test_local_file_completions(): + ip = get_ipython() + cwd = os.getcwdu() + try: + with TemporaryDirectory() as tmpdir: + os.chdir(tmpdir) + prefix = './foo' + suffixes = map(str, [1,2]) + names = [prefix+s for s in suffixes] + for n in names: + open(n, 'w').close() + + # Check simple completion + c = ip.complete(prefix)[1] + nt.assert_equal(c, names) + + # Now check with a function call + cmd = 'a = f("%s' % prefix + c = ip.complete(prefix, cmd)[1] + comp = [prefix+s for s in suffixes] + nt.assert_equal(c, comp) + finally: + # prevent failures from making chdir stick + os.chdir(cwd) diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 086c2eb..cb141bb 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -301,8 +301,8 @@ def test_parse_options(): def test_dirops(): """Test various directory handling operations.""" - curpath = lambda :os.path.splitdrive(os.getcwdu())[1].replace('\\','/') - + # curpath = lambda :os.path.splitdrive(os.getcwdu())[1].replace('\\','/') + curpath = os.getcwdu startdir = os.getcwdu() ipdir = _ip.ipython_dir try: diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py index c3f7a2f..5d87c0e 100644 --- a/IPython/core/tests/test_oinspect.py +++ b/IPython/core/tests/test_oinspect.py @@ -101,7 +101,9 @@ def test_info(): fname = __file__ if fname.endswith(".pyc"): fname = fname[:-1] - nt.assert_equal(i['file'], fname) + # case-insensitive comparison needed on some filesystems + # e.g. Windows: + nt.assert_equal(i['file'].lower(), fname.lower()) nt.assert_equal(i['definition'], 'Call(self, *a, **kw)\n') nt.assert_equal(i['docstring'], Call.__doc__) nt.assert_equal(i['source'], None) diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 5e02514..0cbe76b 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -17,6 +17,7 @@ import sys import tempfile import nose.tools as nt +from nose import SkipTest from IPython.testing import decorators as dec from IPython.testing import tools as tt @@ -156,7 +157,11 @@ class TestMagicRunSimple(tt.TempFileMixin): def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" - + if sys.platform == 'win32': + try: + import win32api + except ImportError: + raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" diff --git a/IPython/utils/tests/test_path.py b/IPython/utils/tests/test_path.py index 0b85d2b..d464f31 100644 --- a/IPython/utils/tests/test_path.py +++ b/IPython/utils/tests/test_path.py @@ -143,6 +143,7 @@ def test_get_home_dir_3(): @with_environment +@skip_win32 def test_get_home_dir_4(): """Testcase $HOME is not set, os=='posix'. This should fail with HomeDirError""" @@ -227,9 +228,10 @@ def test_get_home_dir_8(): @with_environment def test_get_ipython_dir_1(): """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" - env['IPYTHON_DIR'] = "someplace/.ipython" + env_ipdir = os.path.join("someplace", ".ipython") + env['IPYTHON_DIR'] = env_ipdir ipdir = path.get_ipython_dir() - nt.assert_equal(ipdir, "someplace/.ipython") + nt.assert_equal(ipdir, env_ipdir) @with_environment @@ -293,8 +295,8 @@ def test_get_ipython_dir_6(): @with_environment def test_get_ipython_dir_7(): """test_get_ipython_dir_7, test home directory expansion on IPYTHON_DIR""" - home_dir = os.path.expanduser('~/') - env['IPYTHON_DIR'] = '~/somewhere' + home_dir = os.path.expanduser('~') + env['IPYTHON_DIR'] = os.path.join('~', 'somewhere') ipdir = path.get_ipython_dir() nt.assert_equal(ipdir, os.path.join(home_dir, 'somewhere'))