change all skip syntax to pytest

This commit is contained in:
Gil Forsyth 2016-06-22 17:32:02 -04:00
parent 965c802eff
commit 7e254d681e
3 changed files with 37 additions and 52 deletions

View file

@ -5,27 +5,27 @@ import os
import sys import sys
import ast import ast
from nose.tools import assert_raises
from xonsh.execer import Execer from xonsh.execer import Execer
from xonsh.tools import ON_WINDOWS from xonsh.tools import ON_WINDOWS
from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval, from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval,
check_parse, skip_if) check_parse)
import pytest
def setup_module(): def setup_module():
execer_setup() execer_setup()
@skip_if(not ON_WINDOWS)
@pytest.mark.skipif(not ON_WINDOWS, reason='Windows only stuff')
def test_win_ipconfig(): def test_win_ipconfig():
yield (check_eval, check_eval(os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all')
os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all')
@skip_if(not ON_WINDOWS) @pytest.mark.skipif(not ON_WINDOWS, reason='Windows only bin')
def test_ipconfig(): def test_ipconfig():
yield check_eval, 'ipconfig /all' check_eval('ipconfig /all')
@skip_if(ON_WINDOWS) @pytest.mark.skipif(ON_WINDOWS, reason='dont expect ls on windows')
def test_bin_ls(): def test_bin_ls():
yield check_eval, '/bin/ls -l' yield check_eval, '/bin/ls -l'
@ -63,7 +63,8 @@ def test_simple_func_broken():
def test_bad_indent(): def test_bad_indent():
code = ('if True:\n' code = ('if True:\n'
'x = 1\n') 'x = 1\n')
assert_raises(SyntaxError, check_parse, code) with pytest.raises(SyntaxError):
check_parse(code)
def test_good_rhs_subproc(): def test_good_rhs_subproc():
# nonsense but parsebale # nonsense but parsebale
@ -73,7 +74,8 @@ def test_good_rhs_subproc():
def test_bad_rhs_subproc(): def test_bad_rhs_subproc():
# nonsense but unparsebale # nonsense but unparsebale
code = 'str().split() | grep exit\n' code = 'str().split() | grep exit\n'
assert_raises(SyntaxError, check_parse, code) with pytest.raises(SyntaxError):
check_parse(code)
def test_indent_with_empty_line(): def test_indent_with_empty_line():
code = ('if True:\n' code = ('if True:\n'

View file

@ -6,14 +6,12 @@ import sys
import ast import ast
sys.path.insert(0, os.path.abspath('..')) # FIXME sys.path.insert(0, os.path.abspath('..')) # FIXME
import nose import pytest
from nose.tools import assert_equal
assert_equal.__self__.maxDiff = None
from xonsh.ast import pdump from xonsh.ast import pdump
from xonsh.parser import Parser from xonsh.parser import Parser
from tools import (mock_xonsh_env, skip_if, VER_3_4, VER_3_5, VER_MAJOR_MINOR, from tools import (mock_xonsh_env, VER_3_4, VER_3_5, VER_MAJOR_MINOR,
VER_FULL) VER_FULL)
PARSER = None PARSER = None
@ -58,7 +56,7 @@ def assert_nodes_equal(x, y, include_attributes=True):
print(pdump(x, include_attributes=include_attributes), '\n') print(pdump(x, include_attributes=include_attributes), '\n')
print('y:\n==') print('y:\n==')
print(pdump(y, include_attributes=include_attributes), '\n') print(pdump(y, include_attributes=include_attributes), '\n')
assert_equal(pdump(x, include_attributes=include_attributes), assert (pdump(x, include_attributes=include_attributes) ==
pdump(y, include_attributes=include_attributes)) pdump(y, include_attributes=include_attributes))
def check_ast(inp, run=True, mode='eval'): def check_ast(inp, run=True, mode='eval'):
@ -138,7 +136,7 @@ def test_binop_minus():
def test_binop_times(): def test_binop_times():
yield check_ast, '42 * 65' yield check_ast, '42 * 65'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_binop_matmult(): def test_binop_matmult():
yield check_ast, 'x @ y', False yield check_ast, 'x @ y', False
@ -502,47 +500,47 @@ def test_dict_two_comma():
def test_dict_three(): def test_dict_three():
yield check_ast, '{42: 65, 6: 28, 1: 2}' yield check_ast, '{42: 65, 6: 28, 1: 2}'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_dict_from_dict_two_xy(): def test_dict_from_dict_two_xy():
yield check_ast, '{"x": 1, **{"y": 2}}' yield check_ast, '{"x": 1, **{"y": 2}}'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_dict_from_dict_two_x_first(): def test_dict_from_dict_two_x_first():
yield check_ast, '{"x": 1, **{"x": 2}}' yield check_ast, '{"x": 1, **{"x": 2}}'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_dict_from_dict_two_x_second(): def test_dict_from_dict_two_x_second():
yield check_ast, '{**{"x": 2}, "x": 1}' yield check_ast, '{**{"x": 2}, "x": 1}'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_tuple(): def test_unpack_range_tuple():
yield check_stmts, '*range(4),' yield check_stmts, '*range(4),'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_tuple_4(): def test_unpack_range_tuple_4():
yield check_stmts, '*range(4), 4' yield check_stmts, '*range(4), 4'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_tuple_parens(): def test_unpack_range_tuple_parens():
yield check_ast, '(*range(4),)' yield check_ast, '(*range(4),)'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_tuple_parens_4(): def test_unpack_range_tuple_parens_4():
yield check_ast, '(*range(4), 4)' yield check_ast, '(*range(4), 4)'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_list(): def test_unpack_range_list():
yield check_ast, '[*range(4)]' yield check_ast, '[*range(4)]'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_list_4(): def test_unpack_range_list_4():
yield check_ast, '[*range(4), 4]' yield check_ast, '[*range(4), 4]'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_set(): def test_unpack_range_set():
yield check_ast, '{*range(4)}' yield check_ast, '{*range(4)}'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_unpack_range_set_4(): def test_unpack_range_set_4():
yield check_ast, '{*range(4), 4}' yield check_ast, '{*range(4), 4}'
@ -816,15 +814,15 @@ def test_call_int_base_dict():
def test_call_dict_kwargs(): def test_call_dict_kwargs():
yield check_ast, 'dict(**{"base": 8})' yield check_ast, 'dict(**{"base": 8})'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_call_list_many_star_args(): def test_call_list_many_star_args():
yield check_ast, 'min(*[1, 2], 3, *[4, 5])' yield check_ast, 'min(*[1, 2], 3, *[4, 5])'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_call_list_many_starstar_args(): def test_call_list_many_starstar_args():
yield check_ast, 'dict(**{"a": 2}, v=3, **{"c": 5})' yield check_ast, 'dict(**{"a": 2}, v=3, **{"c": 5})'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_call_list_many_star_and_starstar_args(): def test_call_list_many_star_and_starstar_args():
yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False
@ -940,7 +938,7 @@ def test_sub_eq():
def test_times_eq(): def test_times_eq():
yield check_stmts, 'x = 42; x *= 2' yield check_stmts, 'x = 42; x *= 2'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_matmult_eq(): def test_matmult_eq():
yield check_stmts, 'x @= y', False yield check_stmts, 'x @= y', False
@ -1226,7 +1224,7 @@ def test_for_zip_attr():
def test_for_else(): def test_for_else():
yield check_stmts, 'for x in range(6):\n pass\nelse: pass' yield check_stmts, 'for x in range(6):\n pass\nelse: pass'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_async_for(): def test_async_for():
yield check_stmts, "async def f():\n async for x in y:\n pass\n", False yield check_stmts, "async def f():\n async for x in y:\n pass\n", False
@ -1248,7 +1246,7 @@ def test_with_x_as_y_a_as_b():
def test_with_in_func(): def test_with_in_func():
yield check_stmts, "def f():\n with x:\n pass\n" yield check_stmts, "def f():\n with x:\n pass\n"
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_async_with(): def test_async_with():
yield check_stmts, "async def f():\n async with x as y:\n pass\n", False yield check_stmts, "async def f():\n async with x as y:\n pass\n", False
@ -1501,15 +1499,15 @@ def test_function_blank_line():
yield check_stmts, code, False yield check_stmts, code, False
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_async_func(): def test_async_func():
yield check_stmts, 'async def f():\n pass\n' yield check_stmts, 'async def f():\n pass\n'
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_async_decorator(): def test_async_decorator():
yield check_stmts, '@g\nasync def f():\n pass', False yield check_stmts, '@g\nasync def f():\n pass', False
@skip_if(VER_MAJOR_MINOR < VER_3_5) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test')
def test_async_await(): def test_async_await():
yield check_stmts, "async def f():\n await fut\n", False yield check_stmts, "async def f():\n await fut\n", False

View file

@ -9,8 +9,6 @@ import subprocess
from collections import defaultdict from collections import defaultdict
from contextlib import contextmanager from contextlib import contextmanager
from nose.plugins.skip import SkipTest
from xonsh.built_ins import ensure_list_of_strs from xonsh.built_ins import ensure_list_of_strs
from xonsh.environ import Env from xonsh.environ import Env
builtins.__xonsh_env__ = Env() builtins.__xonsh_env__ = Env()
@ -89,19 +87,6 @@ def mock_xonsh_env(xenv):
del builtins.aliases del builtins.aliases
def skipper():
"""Raises SkipTest"""
raise SkipTest
def skip_if(cond):
"""Skips a test under a given condition."""
def dec(f):
if cond:
return skipper
else:
return f
return dec
# #
# Execer tools # Execer tools
# #