Make tests support python2.6
Old unittest is not working for unknown reason, using unittest2 instead
This commit is contained in:
parent
0a05b2961a
commit
aa0a8bf76d
|
@ -1,10 +1,11 @@
|
||||||
language: python
|
language: python
|
||||||
python:
|
python:
|
||||||
|
- "2.6"
|
||||||
- "2.7"
|
- "2.7"
|
||||||
- "3.2"
|
- "3.2"
|
||||||
- "3.3"
|
- "3.3"
|
||||||
install: "pip install ."
|
install: tests/install.sh
|
||||||
script: python setup.py test
|
script: tests/test.sh
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- tests
|
- tests
|
||||||
|
|
5
setup.py
5
setup.py
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
@ -11,6 +12,8 @@ try:
|
||||||
except IOError:
|
except IOError:
|
||||||
README = ''
|
README = ''
|
||||||
|
|
||||||
|
old_python = sys.version_info < (2, 7)
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Powerline',
|
name='Powerline',
|
||||||
version='beta',
|
version='beta',
|
||||||
|
@ -33,5 +36,5 @@ setup(
|
||||||
'Sphinx',
|
'Sphinx',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
test_suite='tests',
|
test_suite='tests' if not old_python else None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import sys
|
||||||
|
if sys.version_info < (2, 7):
|
||||||
|
from unittest2 import TestCase, main # NOQA
|
||||||
|
else:
|
||||||
|
from unittest import TestCase, main # NOQA
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
pip install .
|
||||||
|
if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then
|
||||||
|
# Python 2
|
||||||
|
pip install mercurial
|
||||||
|
if python -c 'import sys; sys.exit(1 * (sys.version_info[1] >= 7))' ; then
|
||||||
|
# Python 2.6
|
||||||
|
pip install unittest2
|
||||||
|
fi
|
||||||
|
fi
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
if python -c 'import sys; sys.exit(1 * (sys.version_info >= (2, 7)))' ; then
|
||||||
|
# Python 2.6
|
||||||
|
export PYTHONPATH="${PYTHONPATH}:`realpath .`"
|
||||||
|
for file in tests/test_*.py ; do
|
||||||
|
if ! python $file ; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
python setup.py test
|
||||||
|
fi
|
|
@ -3,12 +3,12 @@
|
||||||
'''Dynamic configuration files tests.'''
|
'''Dynamic configuration files tests.'''
|
||||||
|
|
||||||
|
|
||||||
from unittest import TestCase
|
|
||||||
import tests.vim as vim_module
|
import tests.vim as vim_module
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from .lib import Args, urllib_read, replace_module_attr
|
from tests.lib import Args, urllib_read, replace_module_attr
|
||||||
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
VBLOCK = chr(ord('V') - 0x40)
|
VBLOCK = chr(ord('V') - 0x40)
|
||||||
|
@ -75,3 +75,8 @@ def tearDownModule():
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
old_cwd = None
|
old_cwd = None
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from tests import main
|
||||||
|
main()
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from powerline.lib import mergedicts, underscore_to_camelcase, add_divider_highlight_group, humanize_bytes
|
from powerline.lib import mergedicts, underscore_to_camelcase, add_divider_highlight_group, humanize_bytes
|
||||||
from powerline.lib.vcs import guess
|
from powerline.lib.vcs import guess
|
||||||
from unittest import TestCase
|
|
||||||
from subprocess import call, PIPE
|
from subprocess import call, PIPE
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
class TestLib(TestCase):
|
class TestLib(TestCase):
|
||||||
|
@ -79,8 +79,13 @@ class TestVCS(TestCase):
|
||||||
os.remove(os.path.join('hg_repo', 'file'))
|
os.remove(os.path.join('hg_repo', 'file'))
|
||||||
|
|
||||||
|
|
||||||
|
old_HGRCPATH = None
|
||||||
|
old_cwd = None
|
||||||
|
|
||||||
|
|
||||||
def setUpModule():
|
def setUpModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
|
global old_HGRCPATH
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
call(['git', 'init', '--quiet', 'git_repo'])
|
call(['git', 'init', '--quiet', 'git_repo'])
|
||||||
|
@ -88,6 +93,8 @@ def setUpModule():
|
||||||
call(['git', 'config', '--local', 'user.email', 'bar@example.org'], cwd='git_repo')
|
call(['git', 'config', '--local', 'user.email', 'bar@example.org'], cwd='git_repo')
|
||||||
call(['git', 'commit', '--allow-empty', '--message', 'Initial commit', '--quiet'], cwd='git_repo')
|
call(['git', 'commit', '--allow-empty', '--message', 'Initial commit', '--quiet'], cwd='git_repo')
|
||||||
if use_mercurial:
|
if use_mercurial:
|
||||||
|
old_HGRCPATH = os.environ.get('HGRCPATH')
|
||||||
|
os.environ['HGRCPATH'] = ''
|
||||||
call(['hg', 'init', 'hg_repo'])
|
call(['hg', 'init', 'hg_repo'])
|
||||||
with open(os.path.join('hg_repo', '.hg', 'hgrc'), 'w') as hgrc:
|
with open(os.path.join('hg_repo', '.hg', 'hgrc'), 'w') as hgrc:
|
||||||
hgrc.write('[ui]\n')
|
hgrc.write('[ui]\n')
|
||||||
|
@ -96,6 +103,7 @@ def setUpModule():
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
|
global old_HGRCPATH
|
||||||
for repo_dir in ['git_repo'] + (['hg_repo'] if use_mercurial else []):
|
for repo_dir in ['git_repo'] + (['hg_repo'] if use_mercurial else []):
|
||||||
for root, dirs, files in list(os.walk(repo_dir, topdown=False)):
|
for root, dirs, files in list(os.walk(repo_dir, topdown=False)):
|
||||||
for file in files:
|
for file in files:
|
||||||
|
@ -103,4 +111,14 @@ def tearDownModule():
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
os.rmdir(os.path.join(root, dir))
|
os.rmdir(os.path.join(root, dir))
|
||||||
os.rmdir(repo_dir)
|
os.rmdir(repo_dir)
|
||||||
os.chdir(old_cwd) # NOQA
|
if use_mercurial:
|
||||||
|
if old_HGRCPATH is None:
|
||||||
|
os.environ.pop('HGRCPATH')
|
||||||
|
else:
|
||||||
|
os.environ['HGRCPATH'] = old_HGRCPATH
|
||||||
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from tests import main
|
||||||
|
main()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from unittest import TestCase
|
|
||||||
from powerline.segments import shell, common
|
from powerline.segments import shell, common
|
||||||
import tests.vim as vim_module
|
import tests.vim as vim_module
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from .lib import Args, urllib_read, replace_module, replace_module_attr, new_module, replace_module_module, replace_env
|
from tests.lib import Args, urllib_read, replace_module, replace_module_attr, new_module, replace_module_module, replace_env
|
||||||
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
vim = None
|
vim = None
|
||||||
|
@ -96,11 +96,9 @@ class TestCommon(TestCase):
|
||||||
self.assertEqual(common.cwd(dir_limit_depth=2, dir_shorten_len=2),
|
self.assertEqual(common.cwd(dir_limit_depth=2, dir_shorten_len=2),
|
||||||
[{'contents': '[not found]', 'divider_highlight_group': 'cwd:divider', 'highlight_group': ['cwd:current_folder', 'cwd']}])
|
[{'contents': '[not found]', 'divider_highlight_group': 'cwd:divider', 'highlight_group': ['cwd:current_folder', 'cwd']}])
|
||||||
new_os.getcwdu = lambda: raises(OSError())
|
new_os.getcwdu = lambda: raises(OSError())
|
||||||
with self.assertRaises(OSError):
|
self.assertRaises(OSError, common.cwd, tuple(), {'dir_limit_depth': 2, 'dir_shorten_len': 2})
|
||||||
common.cwd(dir_limit_depth=2, dir_shorten_len=2),
|
|
||||||
new_os.getcwdu = lambda: raises(ValueError())
|
new_os.getcwdu = lambda: raises(ValueError())
|
||||||
with self.assertRaises(ValueError):
|
self.assertRaises(ValueError, common.cwd, tuple(), {'dir_limit_depth': 2, 'dir_shorten_len': 2})
|
||||||
common.cwd(dir_limit_depth=2, dir_shorten_len=2),
|
|
||||||
|
|
||||||
def test_date(self):
|
def test_date(self):
|
||||||
with replace_module_attr(common, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))):
|
with replace_module_attr(common, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))):
|
||||||
|
@ -280,8 +278,10 @@ old_cwd = None
|
||||||
|
|
||||||
def setUpModule():
|
def setUpModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
|
global __file__
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
|
__file__ = os.path.abspath(__file__)
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
from powerline.segments import vim
|
from powerline.segments import vim
|
||||||
globals()['vim'] = vim
|
globals()['vim'] = vim
|
||||||
|
@ -291,3 +291,8 @@ def tearDownModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from tests import main
|
||||||
|
main()
|
||||||
|
|
27
tests/vim.py
27
tests/vim.py
|
@ -22,13 +22,19 @@ def _logged(func):
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def f(*args):
|
def f(*args, **kwargs):
|
||||||
_log.append((func.__name__, args))
|
_log.append((func.__name__, args))
|
||||||
return func(*args)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
def _log_print():
|
||||||
|
import sys
|
||||||
|
for entry in _log:
|
||||||
|
sys.stdout.write(repr(entry) + '\n')
|
||||||
|
|
||||||
|
|
||||||
@_logged
|
@_logged
|
||||||
def command(cmd):
|
def command(cmd):
|
||||||
if cmd.startswith('let g:'):
|
if cmd.startswith('let g:'):
|
||||||
|
@ -237,13 +243,13 @@ class _Buffer(object):
|
||||||
_dict = None
|
_dict = None
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _init():
|
def _init():
|
||||||
global _dict
|
global _dict
|
||||||
|
|
||||||
if _dict:
|
if _dict:
|
||||||
return _dict
|
return _dict
|
||||||
|
|
||||||
import imp
|
|
||||||
_dict = {}
|
_dict = {}
|
||||||
for varname, value in globals().items():
|
for varname, value in globals().items():
|
||||||
if varname[0] != '_':
|
if varname[0] != '_':
|
||||||
|
@ -252,6 +258,7 @@ def _init():
|
||||||
return _dict
|
return _dict
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _get_segment_info():
|
def _get_segment_info():
|
||||||
mode_translations = {
|
mode_translations = {
|
||||||
chr(ord('V') - 0x40): '^V',
|
chr(ord('V') - 0x40): '^V',
|
||||||
|
@ -268,10 +275,12 @@ def _get_segment_info():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _launch_event(event):
|
def _launch_event(event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _start_mode(mode):
|
def _start_mode(mode):
|
||||||
global _mode
|
global _mode
|
||||||
if mode == 'i':
|
if mode == 'i':
|
||||||
|
@ -281,6 +290,7 @@ def _start_mode(mode):
|
||||||
_mode = mode
|
_mode = mode
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _undo():
|
def _undo():
|
||||||
if len(_undostate[_buffer()]) == 1:
|
if len(_undostate[_buffer()]) == 1:
|
||||||
return
|
return
|
||||||
|
@ -290,6 +300,7 @@ def _undo():
|
||||||
_buf_options[_buffer()]['modified'] = 0
|
_buf_options[_buffer()]['modified'] = 0
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _edit(name=None):
|
def _edit(name=None):
|
||||||
global _last_bufnr
|
global _last_bufnr
|
||||||
if _buffer() and buffers[_buffer()].name is None:
|
if _buffer() and buffers[_buffer()].name is None:
|
||||||
|
@ -300,12 +311,14 @@ def _edit(name=None):
|
||||||
windows[_window - 1].buffer = buf
|
windows[_window - 1].buffer = buf
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _new(name=None):
|
def _new(name=None):
|
||||||
global _window
|
global _window
|
||||||
_Window(buffer={'name': name})
|
_Window(buffer={'name': name})
|
||||||
_window = len(windows)
|
_window = len(windows)
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _del_window(winnr):
|
def _del_window(winnr):
|
||||||
win = windows.pop(winnr - 1)
|
win = windows.pop(winnr - 1)
|
||||||
_win_scopes.pop(winnr)
|
_win_scopes.pop(winnr)
|
||||||
|
@ -314,6 +327,7 @@ def _del_window(winnr):
|
||||||
return win
|
return win
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _close(winnr, wipe=True):
|
def _close(winnr, wipe=True):
|
||||||
global _window
|
global _window
|
||||||
win = _del_window(winnr)
|
win = _del_window(winnr)
|
||||||
|
@ -329,6 +343,7 @@ def _close(winnr, wipe=True):
|
||||||
_Window()
|
_Window()
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _bw(bufnr=None):
|
def _bw(bufnr=None):
|
||||||
bufnr = bufnr or _buffer()
|
bufnr = bufnr or _buffer()
|
||||||
winnr = 1
|
winnr = 1
|
||||||
|
@ -342,10 +357,12 @@ def _bw(bufnr=None):
|
||||||
_b(max(buffers.keys()))
|
_b(max(buffers.keys()))
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _b(bufnr):
|
def _b(bufnr):
|
||||||
windows[_window - 1].buffer = buffers[bufnr]
|
windows[_window - 1].buffer = buffers[bufnr]
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _set_cursor(line, col):
|
def _set_cursor(line, col):
|
||||||
windows[_window - 1].cursor = (line, col)
|
windows[_window - 1].cursor = (line, col)
|
||||||
if _mode == 'n':
|
if _mode == 'n':
|
||||||
|
@ -354,10 +371,12 @@ def _set_cursor(line, col):
|
||||||
_launch_event('CursorMovedI')
|
_launch_event('CursorMovedI')
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _get_buffer():
|
def _get_buffer():
|
||||||
return buffers[_buffer()]
|
return buffers[_buffer()]
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _set_bufoption(option, value, bufnr=None):
|
def _set_bufoption(option, value, bufnr=None):
|
||||||
_buf_options[bufnr or _buffer()][option] = value
|
_buf_options[bufnr or _buffer()][option] = value
|
||||||
if option == 'filetype':
|
if option == 'filetype':
|
||||||
|
@ -377,6 +396,7 @@ class _WithNewBuffer(object):
|
||||||
_bw(self.bufnr)
|
_bw(self.bufnr)
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _set_dict(d, new, setfunc=None):
|
def _set_dict(d, new, setfunc=None):
|
||||||
if not setfunc:
|
if not setfunc:
|
||||||
def setfunc(k, v):
|
def setfunc(k, v):
|
||||||
|
@ -432,6 +452,7 @@ class _WithDict(object):
|
||||||
self.d.pop(k)
|
self.d.pop(k)
|
||||||
|
|
||||||
|
|
||||||
|
@_logged
|
||||||
def _with(key, *args, **kwargs):
|
def _with(key, *args, **kwargs):
|
||||||
if key == 'buffer':
|
if key == 'buffer':
|
||||||
return _WithNewBuffer(_edit, *args, **kwargs)
|
return _WithNewBuffer(_edit, *args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue