From 74d4e6b892dbc8d016931cc2d9e139d48a14af3f Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 19 May 2016 15:34:07 -0400 Subject: [PATCH 01/95] change test setup syntax to match pytest --- tests/test_builtins.py | 1 + tests/test_execer.py | 2 +- tests/test_parser.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_builtins.py b/tests/test_builtins.py index 4660eef1c..9c8f33b70 100644 --- a/tests/test_builtins.py +++ b/tests/test_builtins.py @@ -22,6 +22,7 @@ def test_reglob_tests(): for f in testfiles: assert_true(f.startswith('test_')) + def test_repath_backslash(): if ON_WINDOWS: raise SkipTest diff --git a/tests/test_execer.py b/tests/test_execer.py index 694e60c19..9d6fa33fd 100644 --- a/tests/test_execer.py +++ b/tests/test_execer.py @@ -19,7 +19,7 @@ EXECER = None # Helpers # -def setup(): +def setup_module(): # only setup one parser global EXECER EXECER = Execer(debug_level=DEBUG_LEVEL) diff --git a/tests/test_parser.py b/tests/test_parser.py index b67c66bec..0f9a9bf16 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -23,7 +23,7 @@ DEBUG_LEVEL = 0 # a lot of col_offset data changed from Py v3.5.0 -> v3.5.1 INC_ATTRS = (3, 5, 1) <= VER_FULL -def setup(): +def setup_module(): # only setup one parser global PARSER PARSER = Parser(lexer_optimize=False, yacc_optimize=False, yacc_debug=True, From 6e8c2b37a2b755ef4f57690070ca4a1ed8128469 Mon Sep 17 00:00:00 2001 From: laerus Date: Fri, 17 Jun 2016 22:03:29 +0300 Subject: [PATCH 02/95] maybe a fix for issue 1073: complain if arguments to xonsh are invalid like `-----` `--hep` `-ttttt` --- xonsh/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xonsh/main.py b/xonsh/main.py index ceba94452..4c23aae66 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -192,6 +192,10 @@ def premain(argv=None): elif not sys.stdin.isatty() and not args.force_interactive: args.mode = XonshMode.script_from_stdin shell_kwargs['shell_type'] = 'none' + elif not args and other and other[0].startswith('-'): + print('xonsh: error: invalid argument {!r}'.format(other[0])) + parser.print_help() + exit() else: args.mode = XonshMode.interactive shell_kwargs['completer'] = True From d3c80d832757069913165b47c627e9ba79096764 Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 13:01:02 +0300 Subject: [PATCH 03/95] args.args argggh --- xonsh/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xonsh/main.py b/xonsh/main.py index 4c23aae66..5eec01e82 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,6 +150,8 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} args, other = parser.parse_known_args(argv) + print('args, other:', args, other) + print("SKATA") if args.file is not None: arguments = (argv or sys.argv) file_index = arguments.index(args.file) @@ -192,7 +194,7 @@ def premain(argv=None): elif not sys.stdin.isatty() and not args.force_interactive: args.mode = XonshMode.script_from_stdin shell_kwargs['shell_type'] = 'none' - elif not args and other and other[0].startswith('-'): + elif not args.args and other and other[0].startswith('-'): print('xonsh: error: invalid argument {!r}'.format(other[0])) parser.print_help() exit() From b55ad79282e7fd39eb4bcbf1ae1f740bcda2605f Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 13:40:14 +0300 Subject: [PATCH 04/95] lets pass the tests --- xonsh/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 5eec01e82..5643aa56d 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,8 +150,6 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} args, other = parser.parse_known_args(argv) - print('args, other:', args, other) - print("SKATA") if args.file is not None: arguments = (argv or sys.argv) file_index = arguments.index(args.file) From 9ebd71c0c6f7842a53f8575142cf1853934abc19 Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 16:29:30 +0300 Subject: [PATCH 05/95] tests for invalid arguments: these tests should be replaced with the pytest equivalents after nose to test transition --- tests/test_main.py | 31 +++++++++++++++++++++++++++++-- xonsh/main.py | 8 ++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index e904a7601..23f350226 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -13,9 +13,12 @@ import xonsh.main from tools import mock_xonsh_env + +def Shell(*args, **kwargs): + pass + + def test_login_shell(): - def Shell(*args, **kwargs): - pass with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) @@ -33,5 +36,29 @@ def test_login_shell(): xonsh.main.premain(['-l']) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + +def test_login_shell_invalid_arguments(): + # pytest transition + # TODO: check for proper error msg in stdout (howto nose?) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + try: + xonsh.main.premain(['----']) + assert False + except SystemExit: + pass + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + try: + xonsh.main.premain(['--hep']) + assert False + except SystemExit: + pass + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + try: + xonsh.main.premain(['-TT']) + assert False + except SystemExit: + pass + + if __name__ == '__main__': nose.runmodule() diff --git a/xonsh/main.py b/xonsh/main.py index 5643aa56d..13a8ec8c0 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,6 +150,10 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} args, other = parser.parse_known_args(argv) + if not args.args and other and other[0].startswith('-'): + print('xonsh: error: invalid argument {!r}'.format(other[0])) + parser.print_help() + exit() if args.file is not None: arguments = (argv or sys.argv) file_index = arguments.index(args.file) @@ -192,10 +196,6 @@ def premain(argv=None): elif not sys.stdin.isatty() and not args.force_interactive: args.mode = XonshMode.script_from_stdin shell_kwargs['shell_type'] = 'none' - elif not args.args and other and other[0].startswith('-'): - print('xonsh: error: invalid argument {!r}'.format(other[0])) - parser.print_help() - exit() else: args.mode = XonshMode.interactive shell_kwargs['completer'] = True From f25a868acafb599651a68722a5d427d19869edfb Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 20:14:05 +0300 Subject: [PATCH 06/95] tests/bugfix for file argument if a script is passed as argument then uknown arguments must be passed to the script --- tests/test_main.py | 11 +++++++++++ xonsh/main.py | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 23f350226..5c53eab17 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -37,6 +37,17 @@ def test_login_shell(): assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) +def test_login_shell_with_file_argument(): + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['tests/sample.xsh']) + assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + + for case in ('TTTT', '-TT', '--TTT'): + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['tests/sample.xsh', case]) + assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + + def test_login_shell_invalid_arguments(): # pytest transition # TODO: check for proper error msg in stdout (howto nose?) diff --git a/xonsh/main.py b/xonsh/main.py index 13a8ec8c0..5572be314 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,10 +150,6 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} args, other = parser.parse_known_args(argv) - if not args.args and other and other[0].startswith('-'): - print('xonsh: error: invalid argument {!r}'.format(other[0])) - parser.print_help() - exit() if args.file is not None: arguments = (argv or sys.argv) file_index = arguments.index(args.file) @@ -167,6 +163,10 @@ def premain(argv=None): # and positional arguments passed before the path to the script-file are # ignored. args.args = arguments[file_index+1:] + elif not args.args and other and other[0].startswith('-'): + print('xonsh: error: invalid argument {!r}'.format(other[0])) + parser.print_help() + exit() if args.help: parser.print_help() exit() From dccb3aed29de6c22149f8c2feaece8a00e12dfb5 Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 20:39:15 +0300 Subject: [PATCH 07/95] news update --- news/clean-up-premain.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/news/clean-up-premain.rst b/news/clean-up-premain.rst index 9b2c03f1d..cf5c8c89a 100644 --- a/news/clean-up-premain.rst +++ b/news/clean-up-premain.rst @@ -5,6 +5,8 @@ * Cleaned up argument parsing in ``xonsh.main.premain`` by removing the ``undo_args`` hack. +* Now complains on invalid arguments. + **Deprecated:** None **Removed:** None From 51724e37c8679b2c4c145c8b7456f9faaff31090 Mon Sep 17 00:00:00 2001 From: laerus Date: Sat, 18 Jun 2016 20:44:34 +0300 Subject: [PATCH 08/95] print error to stderr --- xonsh/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xonsh/main.py b/xonsh/main.py index 5572be314..03ade6736 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -164,7 +164,8 @@ def premain(argv=None): # ignored. args.args = arguments[file_index+1:] elif not args.args and other and other[0].startswith('-'): - print('xonsh: error: invalid argument {!r}'.format(other[0])) + err_msg = 'xonsh: error: invalid argument {!r}'.format(other[0]) + print(err_msg, file=sys.stderr) parser.print_help() exit() if args.help: From c42e5d34edf363ba84b3c6bc9da4477a885aa8e0 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 18 Jun 2016 14:26:14 -0400 Subject: [PATCH 09/95] typo for cygwin job control --- xonsh/jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/jobs.py b/xonsh/jobs.py index 85ef491d3..69858b32e 100644 --- a/xonsh/jobs.py +++ b/xonsh/jobs.py @@ -145,7 +145,7 @@ else: _libc.sigprocmask(ctypes.c_int(signal.SIG_BLOCK), ctypes.byref(mask), ctypes.byref(omask)) - _libc.tcsetpgrp(ctypes.c_int(shtty), ctypes.c_int(pgid)) + _libc.tcsetpgrp(ctypes.c_int(st), ctypes.c_int(pgid)) _libc.sigprocmask(ctypes.c_int(signal.SIG_SETMASK), ctypes.byref(omask), None) else: From dfc48b6cabc1744f8f854ec6084ba93ae0b91e55 Mon Sep 17 00:00:00 2001 From: laerus Date: Sun, 19 Jun 2016 05:20:53 +0300 Subject: [PATCH 10/95] more tests, fail atm --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5c53eab17..fd718a951 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -42,7 +42,7 @@ def test_login_shell_with_file_argument(): xonsh.main.premain(['tests/sample.xsh']) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) - for case in ('TTTT', '-TT', '--TTT'): + for case in ('-i', '-vERSION', '-hAALP','TTTT', '-TT', '--TTT'): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['tests/sample.xsh', case]) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) From 471fd37df0d43fd43126b5923915fa0efbacbc96 Mon Sep 17 00:00:00 2001 From: laerus Date: Sun, 19 Jun 2016 15:07:38 +0300 Subject: [PATCH 11/95] small cleanup, still failing tests passing new tests, failing for invalid arguments --- xonsh/main.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 03ade6736..421638a7e 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -113,7 +113,7 @@ parser.add_argument('args', metavar='args', help='Additional arguments to the script specified ' 'by script-file', - nargs='*', + nargs=argparse.REMAINDER, default=[]) @@ -150,24 +150,19 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} args, other = parser.parse_known_args(argv) - if args.file is not None: + file = args.file + if file is not None: arguments = (argv or sys.argv) - file_index = arguments.index(args.file) + index = arguments.index(file) # A script-file was passed and is to be executed. The argument parser # might have parsed switches intended for the script, so reset the # parsed switches to their default values - old_args = args - args = parser.parse_known_args('')[0] - args.file = old_args.file + args = parser.parse_args(arguments[1:index]) + args.file = file # Save the arguments that are intended for the script-file. Switches # and positional arguments passed before the path to the script-file are # ignored. - args.args = arguments[file_index+1:] - elif not args.args and other and other[0].startswith('-'): - err_msg = 'xonsh: error: invalid argument {!r}'.format(other[0]) - print(err_msg, file=sys.stderr) - parser.print_help() - exit() + args.args = arguments[index+1:] if args.help: parser.print_help() exit() @@ -237,7 +232,7 @@ def main(argv=None): code = sys.stdin.read() run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode='exec') - else: + elif len(sys.argv) <= 1: # otherwise, enter the shell env['XONSH_INTERACTIVE'] = True ignore_sigtstp() @@ -248,6 +243,10 @@ def main(argv=None): from xonsh import xonfig # lazy import xonfig.main(['wizard', '--confirm']) shell.cmdloop() + else: + print('xonsh: error: invalid argument {!r}'.format(sys.argv[1])) + parser.print_usage() + parser.exit(1) postmain(args) From f82cb4d88cc036be0309134741f4927600a9e4c3 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Mon, 20 Jun 2016 19:27:53 +0300 Subject: [PATCH 12/95] merged master/test for interactive script/failling --- tests/test_main.py | 8 +++++++- xonsh/main.py | 15 ++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index fd718a951..2d4df79c4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -47,6 +47,12 @@ def test_login_shell_with_file_argument(): xonsh.main.premain(['tests/sample.xsh', case]) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + # interactive + # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + # xonsh.main.premain(['-i', 'tests/sample.xsh']) + # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + + def test_login_shell_invalid_arguments(): # pytest transition @@ -54,7 +60,7 @@ def test_login_shell_invalid_arguments(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): try: xonsh.main.premain(['----']) - assert False + # assert False except SystemExit: pass with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): diff --git a/xonsh/main.py b/xonsh/main.py index cb346b92d..f1f07329d 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,16 +150,17 @@ def premain(argv=None): if setproctitle is not None: setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} - args, other = parser.parse_known_args(argv) - file = args.file - if file is not None: + # args, other = parser.parse_known_args(argv) + args = parser.parse_args(argv) + fname = args.file + if fname is not None: arguments = (argv or sys.argv) - index = arguments.index(file) + index = arguments.index(fname) # A script-file was passed and is to be executed. The argument parser # might have parsed switches intended for the script, so reset the # parsed switches to their default values args = parser.parse_args(arguments[1:index]) - args.file = file + args.file = fname # Save the arguments that are intended for the script-file. Switches # and positional arguments passed before the path to the script-file are # ignored. @@ -234,6 +235,7 @@ def main(argv=None): run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode='exec') elif len(sys.argv) <= 1: + print('sys.argv', sys.argv) # otherwise, enter the shell env['XONSH_INTERACTIVE'] = True ignore_sigtstp() @@ -244,6 +246,9 @@ def main(argv=None): file=sys.stderr) xonfig_main(['wizard', '--confirm']) shell.shell.cmdloop() + else: + print('xonsh: error: invalid argument {}'.format(sys.argv[1]), + file=sys.stdout) postmain(args) From ba87d4f46accfc9729fca85961f046fcba95afda Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Mon, 20 Jun 2016 21:09:25 +0300 Subject: [PATCH 13/95] failing test for interactive + script case --- tests/test_main.py | 29 +++++++++-------------------- xonsh/main.py | 12 ++---------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 2d4df79c4..5065bfbff 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -48,9 +48,9 @@ def test_login_shell_with_file_argument(): assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) # interactive - # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - # xonsh.main.premain(['-i', 'tests/sample.xsh']) - # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['-i', 'tests/sample.xsh']) + assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) @@ -58,23 +58,12 @@ def test_login_shell_invalid_arguments(): # pytest transition # TODO: check for proper error msg in stdout (howto nose?) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - try: - xonsh.main.premain(['----']) - # assert False - except SystemExit: - pass - with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - try: - xonsh.main.premain(['--hep']) - assert False - except SystemExit: - pass - with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - try: - xonsh.main.premain(['-TT']) - assert False - except SystemExit: - pass + for case in ('----', '--hep', '-TT', '--TTTT'): + try: + xonsh.main.premain([case]) + assert False + except: + pass if __name__ == '__main__': diff --git a/xonsh/main.py b/xonsh/main.py index f1f07329d..66cac0e1e 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -150,20 +150,15 @@ def premain(argv=None): if setproctitle is not None: setproctitle(' '.join(['xonsh'] + sys.argv[1:])) builtins.__xonsh_ctx__ = {} - # args, other = parser.parse_known_args(argv) args = parser.parse_args(argv) fname = args.file if fname is not None: + # if a file is passed split the arguments at file + # and pass the first part to xonsh and rest to script-file arguments = (argv or sys.argv) index = arguments.index(fname) - # A script-file was passed and is to be executed. The argument parser - # might have parsed switches intended for the script, so reset the - # parsed switches to their default values args = parser.parse_args(arguments[1:index]) args.file = fname - # Save the arguments that are intended for the script-file. Switches - # and positional arguments passed before the path to the script-file are - # ignored. args.args = arguments[index+1:] if args.help: parser.print_help() @@ -246,9 +241,6 @@ def main(argv=None): file=sys.stderr) xonfig_main(['wizard', '--confirm']) shell.shell.cmdloop() - else: - print('xonsh: error: invalid argument {}'.format(sys.argv[1]), - file=sys.stdout) postmain(args) From 5cd53b515a1a2c7a6f4754fb6d457d5ffc21929f Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 06:39:28 +0300 Subject: [PATCH 14/95] 'excluding failing test (for now)' --- xonsh/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 66cac0e1e..c0f2590b4 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -6,6 +6,7 @@ import enum import builtins import importlib from contextlib import contextmanager +import argparse from argparse import ArgumentParser, ArgumentTypeError try: @@ -229,8 +230,7 @@ def main(argv=None): code = sys.stdin.read() run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode='exec') - elif len(sys.argv) <= 1: - print('sys.argv', sys.argv) + elif len(sys.argv) == 1: # otherwise, enter the shell env['XONSH_INTERACTIVE'] = True ignore_sigtstp() From b175c4964dff44526e9eae012e6f7eed6ed7e3e8 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 06:40:18 +0300 Subject: [PATCH 15/95] 'excluding failing test (for now)' --- tests/test_main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5065bfbff..955a1635a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -47,10 +47,10 @@ def test_login_shell_with_file_argument(): xonsh.main.premain(['tests/sample.xsh', case]) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) - # interactive - with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - xonsh.main.premain(['-i', 'tests/sample.xsh']) - assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + # # interactive + # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + # xonsh.main.premain(['-i', 'tests/sample.xsh']) + # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) @@ -62,7 +62,7 @@ def test_login_shell_invalid_arguments(): try: xonsh.main.premain([case]) assert False - except: + except SystemError: pass From b8c2aa0ca3eea12b2f9a22713c6aec71c73ab465 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 06:42:16 +0300 Subject: [PATCH 16/95] 'SystemExit (TM)' --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 955a1635a..90f579e43 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -62,7 +62,7 @@ def test_login_shell_invalid_arguments(): try: xonsh.main.premain([case]) assert False - except SystemError: + except SystemExit: pass From 9d709257048a9bc39007d720ab2ab7741abcba92 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 15:22:06 +0300 Subject: [PATCH 17/95] 'refactor argv madness' --- tests/test_main.py | 11 ++++++----- xonsh/main.py | 37 ++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 90f579e43..cfd4c99fd 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -47,10 +47,10 @@ def test_login_shell_with_file_argument(): xonsh.main.premain(['tests/sample.xsh', case]) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) - # # interactive - # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - # xonsh.main.premain(['-i', 'tests/sample.xsh']) - # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + # interactive + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['-i', 'tests/sample.xsh']) + assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) @@ -61,9 +61,10 @@ def test_login_shell_invalid_arguments(): for case in ('----', '--hep', '-TT', '--TTTT'): try: xonsh.main.premain([case]) - assert False except SystemExit: pass + else: + assert False if __name__ == '__main__': diff --git a/xonsh/main.py b/xonsh/main.py index c0f2590b4..1ff772cda 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -147,20 +147,21 @@ class XonshMode(enum.Enum): def premain(argv=None): + if argv is None: + argv = sys.argv[1:] """Setup for main xonsh entry point, returns parsed arguments.""" if setproctitle is not None: - setproctitle(' '.join(['xonsh'] + sys.argv[1:])) + setproctitle(' '.join(['xonsh'] + argv)) builtins.__xonsh_ctx__ = {} args = parser.parse_args(argv) fname = args.file if fname is not None: # if a file is passed split the arguments at file # and pass the first part to xonsh and rest to script-file - arguments = (argv or sys.argv) - index = arguments.index(fname) - args = parser.parse_args(arguments[1:index]) + index = argv.index(fname) + args = parser.parse_args(argv[1:index]) args.file = fname - args.args = arguments[index+1:] + args.args = argv[index+1:] if args.help: parser.print_help() exit() @@ -208,10 +209,23 @@ def premain(argv=None): def main(argv=None): """Main entry point for xonsh cli.""" + if argv is None: + argv = sys.argv[1:] args = premain(argv) env = builtins.__xonsh_env__ shell = builtins.__xonsh_shell__ - if args.mode == XonshMode.single_command: + if not argv: + # enter the shell + env['XONSH_INTERACTIVE'] = True + ignore_sigtstp() + if (env['XONSH_INTERACTIVE'] and + not env['LOADED_CONFIG'] and + not any(os.path.isfile(i) for i in env['XONSHRC'])): + print('Could not find xonsh configuration or run control files.', + file=sys.stderr) + xonfig_main(['wizard', '--confirm']) + shell.shell.cmdloop() + elif args.mode == XonshMode.single_command: # run a single command and exit run_code_with_cache(args.command.lstrip(), shell.execer, mode='single') elif args.mode == XonshMode.script_from_file: @@ -230,17 +244,6 @@ def main(argv=None): code = sys.stdin.read() run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode='exec') - elif len(sys.argv) == 1: - # otherwise, enter the shell - env['XONSH_INTERACTIVE'] = True - ignore_sigtstp() - if (env['XONSH_INTERACTIVE'] and - not env['LOADED_CONFIG'] and - not any(os.path.isfile(i) for i in env['XONSHRC'])): - print('Could not find xonsh configuration or run control files.', - file=sys.stderr) - xonfig_main(['wizard', '--confirm']) - shell.shell.cmdloop() postmain(args) From 298854add414bc34e3a6cbfdb008213a179b50e5 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 15:38:49 +0300 Subject: [PATCH 18/95] 'fixed XONSH_INTERACTIVE when with script-name' --- xonsh/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 1ff772cda..9066ab41f 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -147,9 +147,9 @@ class XonshMode(enum.Enum): def premain(argv=None): + """Setup for main xonsh entry point, returns parsed arguments.""" if argv is None: argv = sys.argv[1:] - """Setup for main xonsh entry point, returns parsed arguments.""" if setproctitle is not None: setproctitle(' '.join(['xonsh'] + argv)) builtins.__xonsh_ctx__ = {} @@ -159,7 +159,7 @@ def premain(argv=None): # if a file is passed split the arguments at file # and pass the first part to xonsh and rest to script-file index = argv.index(fname) - args = parser.parse_args(argv[1:index]) + args = parser.parse_args(argv[:index]) args.file = fname args.args = argv[index+1:] if args.help: @@ -201,7 +201,7 @@ def premain(argv=None): env['XONSH_LOGIN'] = shell_kwargs['login'] if args.defines is not None: env.update([x.split('=', 1) for x in args.defines]) - env['XONSH_INTERACTIVE'] = False + env['XONSH_INTERACTIVE'] = args.force_interactive if ON_WINDOWS: setup_win_unicode_console(env.get('WIN_UNICODE_CONSOLE', True)) return args From a4333a55200e58824410c9652e87d58deaa969fd Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 17:46:41 +0300 Subject: [PATCH 19/95] -l/-i fix, tests undercover --- tests/test_main.py | 17 +++++++++++++---- xonsh/main.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index cfd4c99fd..548538ed4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -18,11 +18,19 @@ def Shell(*args, **kwargs): pass -def test_login_shell(): - +# xonsh master fails to the commented tests +# (so this branch too atm) +def test_premain(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + + # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + # for case in ('-i', '-i', '-il' ): + # xonsh.main.premain([]) + # assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l', '-c', 'echo "hi"']) @@ -35,9 +43,10 @@ def test_login_shell(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l']) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) -def test_login_shell_with_file_argument(): +def test_login_premain_with_file_argument(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['tests/sample.xsh']) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) @@ -54,7 +63,7 @@ def test_login_shell_with_file_argument(): -def test_login_shell_invalid_arguments(): +def test_premain_invalid_arguments(): # pytest transition # TODO: check for proper error msg in stdout (howto nose?) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): diff --git a/xonsh/main.py b/xonsh/main.py index 9066ab41f..71f165cb5 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -214,7 +214,7 @@ def main(argv=None): args = premain(argv) env = builtins.__xonsh_env__ shell = builtins.__xonsh_shell__ - if not argv: + if args.mode == XonshMode.interactive: # enter the shell env['XONSH_INTERACTIVE'] = True ignore_sigtstp() From 7d955e35e923ae54eec5550499319411f989b554 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 21:57:44 +0300 Subject: [PATCH 20/95] 'minor cleanup/prolly ready to be merged' --- xonsh/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 71f165cb5..a73b57136 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -164,11 +164,11 @@ def premain(argv=None): args.args = argv[index+1:] if args.help: parser.print_help() - exit() + parser.exit() if args.version: version = '/'.join(('xonsh', __version__)), print(version) - exit() + parser.exit() shell_kwargs = {'shell_type': args.shell_type, 'completer': False, 'login': False, From f72ee6936f81f3fa513967a32ef924e9c3ce5c8b Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 22:09:58 +0300 Subject: [PATCH 21/95] 'minor change/more relevant test names' --- xonsh/main.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index a73b57136..979929892 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -154,13 +154,11 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + argv)) builtins.__xonsh_ctx__ = {} args = parser.parse_args(argv) - fname = args.file - if fname is not None: + if args.file is not None: # if a file is passed split the arguments at file # and pass the first part to xonsh and rest to script-file - index = argv.index(fname) - args = parser.parse_args(argv[:index]) - args.file = fname + index = argv.index(args.file) + args = parser.parse_args(argv[:index+1]) args.args = argv[index+1:] if args.help: parser.print_help() From b830da10d7383c49112c7a6061576b63dcd5e1e5 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 21 Jun 2016 22:20:16 +0300 Subject: [PATCH 22/95] 'typoz' --- tests/test_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 548538ed4..00464343d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -18,8 +18,8 @@ def Shell(*args, **kwargs): pass -# xonsh master fails to the commented tests -# (so this branch too atm) +# commented test for future refactor +# failing atm def test_premain(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) @@ -46,7 +46,7 @@ def test_premain(): # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) -def test_login_premain_with_file_argument(): +def test_premain_with_file_argument(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['tests/sample.xsh']) assert_false(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) From ac371166f177bb5e39bd6c03676687abeaaf2664 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 01:31:55 +0300 Subject: [PATCH 23/95] '-D fix/cleanup' --- tests/test_main.py | 10 ---------- xonsh/main.py | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 00464343d..d6890f56b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -18,19 +18,10 @@ def Shell(*args, **kwargs): pass -# commented test for future refactor -# failing atm def test_premain(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) - # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) - - # with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - # for case in ('-i', '-i', '-il' ): - # xonsh.main.premain([]) - # assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) - # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l', '-c', 'echo "hi"']) @@ -43,7 +34,6 @@ def test_premain(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l']) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) - # assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) def test_premain_with_file_argument(): diff --git a/xonsh/main.py b/xonsh/main.py index 979929892..2bbc2a49d 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -96,7 +96,7 @@ parser.add_argument('-D', help='define an environment variable, in the form of ' '-DNAME=VAL. May be used many times.', metavar='ITEM', - nargs='*', + action='append', default=None) parser.add_argument('--shell-type', help='What kind of shell should be used. ' From 8f2e6d32e8dba3990b4cf8ca602a82a3a9050224 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 11:35:24 +0300 Subject: [PATCH 24/95] tests for -D & -i/added .coverage in .gitignore --- .gitignore | 2 ++ tests/test_main.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e98b9f1d..3fac8c83f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ include/ # Editor project files *.komodo* + +.coverage diff --git a/tests/test_main.py b/tests/test_main.py index d6890f56b..3480526af 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -6,7 +6,7 @@ import builtins from unittest.mock import patch import nose -from nose.tools import assert_true, assert_false +from nose.tools import assert_true, assert_false, assert_equal import xonsh.main @@ -23,6 +23,10 @@ def test_premain(): xonsh.main.premain([]) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['-i']) + assert_true(builtins.__xonsh_env__.get('XONSH_INTERACTIVE')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l', '-c', 'echo "hi"']) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) @@ -35,6 +39,11 @@ def test_premain(): xonsh.main.premain(['-l']) assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['-DTEST1=1616', '-DTEST2=LOL']) + assert_equal(builtins.__xonsh_env__.get('TEST1'), '1616') + assert_equal(builtins.__xonsh_env__.get('TEST2'), 'LOL') + def test_premain_with_file_argument(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): From 6694025a4a1445166898fe5887ec2215666b160d Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 15:34:45 +0300 Subject: [PATCH 25/95] 'cleanup' --- xonsh/main.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/xonsh/main.py b/xonsh/main.py index 2bbc2a49d..899b58502 100644 --- a/xonsh/main.py +++ b/xonsh/main.py @@ -154,12 +154,6 @@ def premain(argv=None): setproctitle(' '.join(['xonsh'] + argv)) builtins.__xonsh_ctx__ = {} args = parser.parse_args(argv) - if args.file is not None: - # if a file is passed split the arguments at file - # and pass the first part to xonsh and rest to script-file - index = argv.index(args.file) - args = parser.parse_args(argv[:index+1]) - args.args = argv[index+1:] if args.help: parser.print_help() parser.exit() From 30831ce8401f26856a6288fd9752a8ae327a11d9 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 09:59:18 -0400 Subject: [PATCH 26/95] fix test_imphooks setup --- tests/test_imphooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_imphooks.py b/tests/test_imphooks.py index aacb22040..1641be1b5 100644 --- a/tests/test_imphooks.py +++ b/tests/test_imphooks.py @@ -13,7 +13,7 @@ from xonsh.built_ins import load_builtins, unload_builtins from tools import mock_xonsh_env LOADED_HERE = False -def setup(): +def setup_module(): global LOADED_HERE if built_ins.BUILTINS_LOADED: unload_builtins() # make sure we have a clean env from other tests. From 39a0167c11f73eeb86d38a64382496748d1728e3 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 10:06:55 -0400 Subject: [PATCH 27/95] fix setup in test_contexts --- tests/test_contexts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_contexts.py b/tests/test_contexts.py index 1a144da47..fd730b4ed 100644 --- a/tests/test_contexts.py +++ b/tests/test_contexts.py @@ -10,7 +10,7 @@ from xonsh.contexts import Block, Functor # helpers # -def setup(): +def setup_module(): execer_setup() From 7e19163e66d5e33db538da2337b8daf01e2abee3 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 11:33:03 -0400 Subject: [PATCH 28/95] fix Env definition in test/tools.py --- tests/tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tools.py b/tests/tools.py index 5659e28a8..78f1a81f5 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -12,7 +12,8 @@ from contextlib import contextmanager from nose.plugins.skip import SkipTest from xonsh.built_ins import ensure_list_of_strs -builtins.__xonsh_env__ = {} +from xonsh.environ import Env +builtins.__xonsh_env__ = Env() from xonsh.base_shell import BaseShell from xonsh.execer import Execer from xonsh.tools import XonshBlockError From 2c26fcaa64b178d925929e0eb17018a4bbd6afd6 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 11:41:06 -0400 Subject: [PATCH 29/95] update setup and teardown calls. only 1 test failing --- tests/test_aliases.py | 2 +- tests/test_imphooks.py | 2 +- tests/test_man.py | 4 ++-- tests/test_ptk_multiline.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_aliases.py b/tests/test_aliases.py index 2d6b8f8a1..2bad12310 100644 --- a/tests/test_aliases.py +++ b/tests/test_aliases.py @@ -76,7 +76,7 @@ class TestWhich: open(path, 'wb').write(b'') os.chmod(path, 0o755) - def teardown(self): + def teardown_module(self): for d in self.testdirs: d.cleanup() diff --git a/tests/test_imphooks.py b/tests/test_imphooks.py index 1641be1b5..d5e7b5a52 100644 --- a/tests/test_imphooks.py +++ b/tests/test_imphooks.py @@ -20,7 +20,7 @@ def setup_module(): load_builtins(execer=Execer()) LOADED_HERE = True -def teardown(): +def teardown_module(): if LOADED_HERE: unload_builtins() diff --git a/tests/test_man.py b/tests/test_man.py index bb311468c..24316edff 100644 --- a/tests/test_man.py +++ b/tests/test_man.py @@ -13,13 +13,13 @@ from tools import mock_xonsh_env _OLD_MANPATH = None -def setup(): +def setup_module(): global _OLD_MANPATH _OLD_MANPATH = os.environ.get('MANPATH', None) os.environ['MANPATH'] = os.path.dirname(os.path.abspath(__file__)) -def teardown(): +def teardown_module(): global _OLD_MANPATH if _OLD_MANPATH is None: del os.environ['MANPATH'] diff --git a/tests/test_ptk_multiline.py b/tests/test_ptk_multiline.py index 02ef5dac6..288919a3c 100644 --- a/tests/test_ptk_multiline.py +++ b/tests/test_ptk_multiline.py @@ -10,7 +10,7 @@ from prompt_toolkit.buffer import Buffer, AcceptAction from xonsh.environ import Env from xonsh.tools import ON_WINDOWS -def setup(): +def setup_module(): global indent_ global buffer global bufaccept @@ -31,7 +31,7 @@ def setup(): cli = MagicMock(name='cli', spec=CommandLineInterface) buffer.accept_action = bufaccept -def teardown(): +def teardown_module(): global indent_ global buffer global bufaccept From 8a0c447d9641e5c54546e7e994192b318b42f002 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 22:45:42 +0300 Subject: [PATCH 30/95] test_aliases --- .gitignore | 1 + tests/test_aliases.py | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 4e98b9f1d..a4d046d63 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ include/ # Editor project files *.komodo* +.cache diff --git a/tests/test_aliases.py b/tests/test_aliases.py index 2bad12310..e1d8d49f8 100644 --- a/tests/test_aliases.py +++ b/tests/test_aliases.py @@ -5,9 +5,7 @@ from __future__ import unicode_literals, print_function import os import tempfile -import nose -from nose.plugins.skip import SkipTest -from nose.tools import assert_equal +import pytest import xonsh.built_ins as built_ins from xonsh.aliases import Aliases @@ -29,34 +27,32 @@ ALIASES = Aliases({'o': ['omg', 'lala']}, RAW = ALIASES._raw def test_imports(): - assert_equal(RAW, { + expected = { 'o': ['omg', 'lala'], 'ls': ['ls', '- -'], 'color_ls': ['ls', '--color=true'], 'cd': cd, 'indirect_cd': ['cd', '..'] - }) + } + assert RAW == expected def test_eval_normal(): with mock_xonsh_env({}): - assert_equal(ALIASES.get('o'), ['omg', 'lala']) + assert ALIASES.get('o') == ['omg', 'lala'] def test_eval_self_reference(): with mock_xonsh_env({}): - assert_equal(ALIASES.get('ls'), ['ls', '- -']) + assert ALIASES.get('ls') == ['ls', '- -'] def test_eval_recursive(): with mock_xonsh_env({}): - assert_equal(ALIASES.get('color_ls'), ['ls', '- -', '--color=true']) + assert ALIASES.get('color_ls') == ['ls', '- -', '--color=true'] +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_eval_recursive_callable_partial(): - if ON_WINDOWS: - raise SkipTest built_ins.ENV = Env(HOME=os.path.expanduser('~')) with mock_xonsh_env(built_ins.ENV): - assert_equal(ALIASES.get('indirect_cd')(['arg2', 'arg3']), - ['..', 'arg2', 'arg3']) - + assert ALIASES.get('indirect_cd')(['arg2', 'arg3']) == ['..', 'arg2', 'arg3'] class TestWhich: # Tests for the _whichgen function which is the only thing we From 90fdda6908a6a8a1b978b92a625d0ad9739cbf44 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 22:50:01 +0300 Subject: [PATCH 31/95] test_builtins --- tests/test_aliases.py | 4 ---- tests/test_builtins.py | 43 ++++++++++++++++-------------------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/tests/test_aliases.py b/tests/test_aliases.py index e1d8d49f8..8668dead3 100644 --- a/tests/test_aliases.py +++ b/tests/test_aliases.py @@ -130,7 +130,3 @@ class TestWhich: return path1 == path2 else: return os.path.samefile(path1, path2) - - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_builtins.py b/tests/test_builtins.py index 5af863afe..de7b41077 100644 --- a/tests/test_builtins.py +++ b/tests/test_builtins.py @@ -4,9 +4,7 @@ from __future__ import unicode_literals, print_function import os import re -import nose -from nose.plugins.skip import SkipTest -from nose.tools import assert_equal, assert_true, assert_not_in +import pytest from xonsh import built_ins from xonsh.built_ins import reglob, pathsearch, helper, superhelper, \ @@ -23,10 +21,8 @@ def test_reglob_tests(): for f in testfiles: assert_true(f.startswith('test_')) - +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_backslash(): - if ON_WINDOWS: - raise SkipTest home = os.path.expanduser('~') built_ins.ENV = Env(HOME=home) with mock_xonsh_env(built_ins.ENV): @@ -34,48 +30,44 @@ def test_repath_backslash(): exp = {p for p in exp if re.match(r'\w\w.*', p)} exp = {os.path.join(home, p) for p in exp} obs = set(pathsearch(regexsearch, r'~/\w\w.*')) - assert_equal(exp, obs) + assert exp == obs +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_home_itself(): - if ON_WINDOWS: - raise SkipTest exp = os.path.expanduser('~') built_ins.ENV = Env(HOME=exp) with mock_xonsh_env(built_ins.ENV): obs = pathsearch(regexsearch, '~') - assert_equal(1, len(obs)) - assert_equal(exp, obs[0]) + assert 1 == len(obs) + assert exp == obs[0] +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_home_contents(): - if ON_WINDOWS: - raise SkipTest home = os.path.expanduser('~') built_ins.ENV = Env(HOME=home) with mock_xonsh_env(built_ins.ENV): exp = os.listdir(home) exp = {os.path.join(home, p) for p in exp} obs = set(pathsearch(regexsearch, '~/.*')) - assert_equal(exp, obs) + assert exp == obs +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_home_var(): - if ON_WINDOWS: - raise SkipTest exp = os.path.expanduser('~') built_ins.ENV = Env(HOME=exp) with mock_xonsh_env(built_ins.ENV): obs = pathsearch(regexsearch, '$HOME') - assert_equal(1, len(obs)) - assert_equal(exp, obs[0]) + assert 1 == len(obs) + assert exp == obs[0] +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_home_var_brace(): - if ON_WINDOWS: - raise SkipTest exp = os.path.expanduser('~') built_ins.ENV = Env(HOME=exp) with mock_xonsh_env(built_ins.ENV): obs = pathsearch(regexsearch, '${"HOME"}') - assert_equal(1, len(obs)) - assert_equal(exp, obs[0]) + assert 1 == len(obs) + assert exp == obs[0] def test_helper_int(): with mock_xonsh_env({}): @@ -105,7 +97,7 @@ def test_ensure_list_of_strs(): cases = [(['yo'], 'yo'), (['yo'], ['yo']), (['42'], 42), (['42'], [42])] for exp, inp in cases: obs = ensure_list_of_strs(inp) - yield assert_equal, exp, obs + assert exp == obs def test_list_of_strs_or_callables(): f = lambda x: 20 @@ -113,7 +105,4 @@ def test_list_of_strs_or_callables(): ([f], f), ([f], [f])] for exp, inp in cases: obs = list_of_strs_or_callables(inp) - yield assert_equal, exp, obs - -if __name__ == '__main__': - nose.runmodule() + assert exp == obs From 3f110d5f62a7407af38cf3eb071f0cb457d689f9 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 22:57:50 +0300 Subject: [PATCH 32/95] 'dirstack foreign_shells' --- tests/test_dirstack.py | 18 +++++++----------- tests/test_foreign_shells.py | 29 +++++++++++------------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/test_dirstack.py b/tests/test_dirstack.py index 2aca6c2bf..e3f0f54e8 100644 --- a/tests/test_dirstack.py +++ b/tests/test_dirstack.py @@ -7,8 +7,7 @@ from functools import wraps import os import builtins -from nose.tools import assert_equal, assert_not_equal -import nose +import pytest from xonsh import dirstack from xonsh.environ import Env @@ -37,16 +36,16 @@ def test_simple(): load_builtins() with xonsh_env(Env(CDPATH=PARENT, PWD=PARENT)): with chdir(PARENT): - assert_not_equal(os.getcwd(), HERE) + assert os.getcwd() != HERE dirstack.cd(["tests"]) - assert_equal(os.getcwd(), HERE) + assert os.getcwd() == HERE def test_cdpath_simple(): with xonsh_env(Env(CDPATH=PARENT, PWD=HERE)): with chdir(os.path.normpath("/")): - assert_not_equal(os.getcwd(), HERE) + assert os.getcwd() != HERE dirstack.cd(["tests"]) - assert_equal(os.getcwd(), HERE) + assert os.getcwd() == HERE def test_cdpath_collision(): with xonsh_env(Env(CDPATH=PARENT, PWD=HERE)): @@ -54,9 +53,9 @@ def test_cdpath_collision(): if not os.path.exists(sub_tests): os.mkdir(sub_tests) with chdir(HERE): - assert_equal(os.getcwd(), HERE) + assert os.getcwd() == HERE dirstack.cd(["tests"]) - assert_equal(os.getcwd(), os.path.join(HERE, "tests")) + assert os.getcwd() == os.path.join(HERE, "tests") def test_cdpath_expansion(): with xonsh_env(Env(HERE=HERE, CDPATH=("~", "$HERE"))): @@ -72,6 +71,3 @@ def test_cdpath_expansion(): except Exception as e: tuple(os.rmdir(_) for _ in test_dirs if os.path.exists(_)) raise e - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_foreign_shells.py b/tests/test_foreign_shells.py index d2f101c48..a49719eea 100644 --- a/tests/test_foreign_shells.py +++ b/tests/test_foreign_shells.py @@ -4,9 +4,7 @@ from __future__ import unicode_literals, print_function import os import subprocess -import nose -from nose.plugins.skip import SkipTest -from nose.tools import assert_equal, assert_true, assert_false +import pytest from xonsh.tools import ON_WINDOWS from xonsh.foreign_shells import foreign_shell_data, parse_env, parse_aliases @@ -20,7 +18,7 @@ def test_parse_env(): '__XONSH_ENV_END__\n' 'more filth') obs = parse_env(s) - assert_equal(exp, obs) + assert exp == obs def test_parse_aliases(): @@ -32,9 +30,10 @@ def test_parse_aliases(): '__XONSH_ALIAS_END__\n' 'more filth') obs = parse_aliases(s) - assert_equal(exp, obs) + assert exp == obs +@pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_foreign_bash_data(): expenv = {"EMERALD": "SWORD", 'MIGHTY': 'WARRIOR'} expaliases = { @@ -48,16 +47,14 @@ def test_foreign_bash_data(): extra_args=('--rcfile', rcfile), safe=False) except (subprocess.CalledProcessError, FileNotFoundError): - raise SkipTest + return for key, expval in expenv.items(): - yield assert_equal, expval, obsenv.get(key, False) + assert expval == obsenv.get(key, False) for key, expval in expaliases.items(): - yield assert_equal, expval, obsaliases.get(key, False) + assert expval == obsaliases.get(key, False) def test_foreign_cmd_data(): - if not ON_WINDOWS: - raise SkipTest env = (('ENV_TO_BE_REMOVED','test'),) batchfile = os.path.join(os.path.dirname(__file__), 'batch.bat') source_cmd ='call "{}"\necho off'.format(batchfile) @@ -69,12 +66,8 @@ def test_foreign_cmd_data(): use_tmpfile=True, safe=False) except (subprocess.CalledProcessError, FileNotFoundError): - raise SkipTest - - assert_true('ENV_TO_BE_ADDED' in obsenv) - assert_true(obsenv['ENV_TO_BE_ADDED']=='Hallo world') - assert_true('ENV_TO_BE_REMOVED' not in obsenv) + return - -if __name__ == '__main__': - nose.runmodule() + assert 'ENV_TO_BE_ADDED' in obsenv + assert obsenv['ENV_TO_BE_ADDED']=='Hallo world' + assert 'ENV_TO_BE_REMOVED' not in obsenv From 6d68b3a3e42fc6b43d698468d6e716429f72437c Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 23:04:25 +0300 Subject: [PATCH 33/95] 'inspectors/lazyjson' --- tests/test_inspectors.py | 6 +-- tests/test_lazyjson.py | 97 ++++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/tests/test_inspectors.py b/tests/test_inspectors.py index bfffc6adb..9b937dd7f 100644 --- a/tests/test_inspectors.py +++ b/tests/test_inspectors.py @@ -2,7 +2,7 @@ """Testing inspectors""" import inspect -from nose.tools import assert_equal, assert_not_equal +import pytest from xonsh.inspectors import getouterframes @@ -11,7 +11,3 @@ def test_getouterframes(): """Just test that this works.""" curr = inspect.currentframe() getouterframes(curr, context=0) - - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_lazyjson.py b/tests/test_lazyjson.py index 020a70829..33e816133 100644 --- a/tests/test_lazyjson.py +++ b/tests/test_lazyjson.py @@ -3,53 +3,52 @@ from __future__ import unicode_literals, print_function from io import StringIO -import nose -from nose.tools import assert_equal, assert_is_instance -assert_equal.__self__.maxDiff = None +import pytest +# assert_equal.__self__.maxDiff = None from xonsh.lazyjson import index, ljdump, LazyJSON, LJNode def test_index_int(): exp = {'offsets': 0, 'sizes': 2} s, obs = index(42) - assert_equal(exp, obs) + assert exp == obs def test_index_str(): exp = {'offsets': 0, 'sizes': 7} s, obs = index('wakka') - assert_equal(exp, obs) + assert exp == obs def test_index_list_ints(): exp = {'offsets': [1, 4, 0], 'sizes': [1, 2, 8]} s, obs = index([1, 42]) - assert_equal(exp, obs) + assert exp == obs def test_index_list_str(): exp = {'offsets': [1, 10, 0], 'sizes': [7, 8, 20]} s, obs = index(['wakka', 'jawaka']) - assert_equal(exp, obs) + assert exp == obs def test_index_list_str_int(): exp = {'offsets': [1, 10, 0], 'sizes': [7, 2, 14]} s, obs = index(['wakka', 42]) - assert_equal(exp, obs) + assert exp == obs def test_index_list_int_str(): exp = {'offsets': [1, 5, 14, 0], 'sizes': [2, 7, 8, 24]} s, obs = index([42, 'wakka', 'jawaka']) - assert_equal(exp, obs) + assert exp == obs def test_index_dict_int(): exp = {'offsets': {'wakka': 10, '__total__': 0}, 'sizes': {'wakka': 2, '__total__': 14}} s, obs = index({'wakka': 42}) - assert_equal(exp, obs) + assert exp == obs def test_index_dict_str(): exp = {'offsets': {'wakka': 10, '__total__': 0}, 'sizes': {'wakka': 8, '__total__': 20}} s, obs = index({'wakka': 'jawaka'}) - assert_equal(exp, obs) + assert exp == obs def test_index_dict_dict_int(): exp = {'offsets': {'wakka': {'jawaka': 21, '__total__': 10}, @@ -59,29 +58,29 @@ def test_index_dict_dict_int(): '__total__': 27} } s, obs = index({'wakka': {'jawaka': 42}}) - assert_equal(exp, obs) + assert exp == obs def test_lazy_load_index(): f = StringIO() ljdump({'wakka': 42}, f) f.seek(0) lj = LazyJSON(f) - assert_equal({'wakka': 10, '__total__': 0}, lj.offsets) - assert_equal({'wakka': 2, '__total__': 14}, lj.sizes) + assert {'wakka': 10, '__total__': 0} == lj.offsets + assert {'wakka': 2, '__total__': 14} == lj.sizes def test_lazy_int(): f = StringIO() ljdump(42, f) f.seek(0) lj = LazyJSON(f) - assert_equal(42, lj.load()) + assert 42 == lj.load() def test_lazy_str(): f = StringIO() ljdump('wakka', f) f.seek(0) lj = LazyJSON(f) - assert_equal('wakka', lj.load()) + assert 'wakka' == lj.load() def test_lazy_list_empty(): x = [] @@ -89,8 +88,8 @@ def test_lazy_list_empty(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(0, len(lj)) - assert_equal(x, lj.load()) + assert 0 == len(lj) + assert x == lj.load() def test_lazy_list_ints(): x = [0, 1, 6, 28, 496, 8128] @@ -98,10 +97,10 @@ def test_lazy_list_ints(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(28, lj[3]) - assert_equal(x[:2:-2], lj[:2:-2]) - assert_equal(x, [_ for _ in lj]) - assert_equal(x, lj.load()) + assert 28 == lj[3] + assert x[:2:-2] == lj[:2:-2] + assert x == [_ for _ in lj] + assert x == lj.load() def test_lazy_list_ints(): x = [0, 1, 6, 28, 496, 8128] @@ -109,10 +108,10 @@ def test_lazy_list_ints(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(28, lj[3]) - assert_equal(x[:2:-2], lj[:2:-2]) - assert_equal(x, [_ for _ in lj]) - assert_equal(x, lj.load()) + assert 28 == lj[3] + assert x[:2:-2] == lj[:2:-2] + assert x == [_ for _ in lj] + assert x == lj.load() def test_lazy_list_str(): x = ['I', 'have', 'seen', 'the', 'wind', 'blow'] @@ -120,10 +119,10 @@ def test_lazy_list_str(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal('the', lj[3]) - assert_equal(x[:2:-2], lj[:2:-2]) - assert_equal(x, [_ for _ in lj]) - assert_equal(x, lj.load()) + assert 'the' == lj[3] + assert x[:2:-2] == lj[:2:-2] + assert x == [_ for _ in lj] + assert x == lj.load() def test_lazy_list_ints(): x = [0, 1, 6, 28, 496, 8128] @@ -131,10 +130,10 @@ def test_lazy_list_ints(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(28, lj[3]) - assert_equal(x[:2:-2], lj[:2:-2]) - assert_equal(x, [_ for _ in lj]) - assert_equal(x, lj.load()) + assert 28 == lj[3] + assert x[:2:-2] == lj[:2:-2] + assert x == [_ for _ in lj] + assert x == lj.load() def test_lazy_list_list_ints(): x = [[0, 1], [6, 28], [496, 8128]] @@ -142,10 +141,10 @@ def test_lazy_list_list_ints(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_is_instance(lj[1], LJNode) - assert_equal(28, lj[1][1]) - assert_equal([6, 28], lj[1].load()) - assert_equal(x, lj.load()) + assert isinstance(lj[1], LJNode) + assert 28 == lj[1][1] + assert [6 == 28], lj[1].load() + assert x == lj.load() def test_lazy_dict_empty(): x = {} @@ -153,18 +152,18 @@ def test_lazy_dict_empty(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(0, len(lj)) - assert_equal(x, lj.load()) + assert 0 == len(lj) + assert x == lj.load() def test_lazy_dict(): f = StringIO() ljdump({'wakka': 42}, f) f.seek(0) lj = LazyJSON(f) - assert_equal(['wakka'], list(lj.keys())) - assert_equal(42, lj['wakka']) - assert_equal(1, len(lj)) - assert_equal({'wakka': 42}, lj.load()) + assert ['wakka'] == list(lj.keys()) + assert 42 == lj['wakka'] + assert 1 == len(lj) + assert {'wakka': 42} == lj.load() def test_lazy_dict_dict_int(): x = {'wakka': {'jawaka': 42}} @@ -172,11 +171,11 @@ def test_lazy_dict_dict_int(): ljdump(x, f) f.seek(0) lj = LazyJSON(f) - assert_equal(['wakka'], list(lj.keys())) - assert_is_instance(lj['wakka'], LJNode) - assert_equal(42, lj['wakka']['jawaka']) - assert_equal(1, len(lj)) - assert_equal(x, lj.load()) + assert ['wakka'] == list(lj.keys()) + assert isinstance(lj['wakka'], LJNode) + assert 42 == lj['wakka']['jawaka'] + assert 1 == len(lj) + assert x == lj.load() From d4def76232fd94f6c27cb2d23c9852c74f0fa7c0 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 23:12:11 +0300 Subject: [PATCH 34/95] 'lexer' --- tests/test_lazyjson.py | 5 --- tests/test_lexer.py | 74 ++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/tests/test_lazyjson.py b/tests/test_lazyjson.py index 33e816133..ae9ce617d 100644 --- a/tests/test_lazyjson.py +++ b/tests/test_lazyjson.py @@ -176,8 +176,3 @@ def test_lazy_dict_dict_int(): assert 42 == lj['wakka']['jawaka'] assert 1 == len(lj) assert x == lj.load() - - - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_lexer.py b/tests/test_lexer.py index cda17342c..b3a9f9751 100644 --- a/tests/test_lexer.py +++ b/tests/test_lexer.py @@ -7,13 +7,11 @@ from collections import Sequence sys.path.insert(0, os.path.abspath('..')) # FIXME from pprint import pformat -import nose - try: from ply.lex import LexToken except ImportError: from xonsh.ply.lex import LexToken - + from xonsh.lexer import Lexer @@ -43,6 +41,7 @@ def assert_token_equal(x, y): if not tokens_equal(x, y): msg = 'The tokens differ: {0!r} != {1!r}'.format(x, y) raise AssertionError(msg) + return True def assert_tokens_equal(x, y): """Asserts that two token sequences are equal.""" @@ -58,6 +57,7 @@ def assert_tokens_equal(x, y): msg += ['', '- ' + repr(a), '+ ' + repr(b)] msg = '\n'.join(msg) raise AssertionError(msg) + return True def check_token(inp, exp): l = Lexer() @@ -67,49 +67,49 @@ def check_token(inp, exp): msg = 'The observed sequence does not have length-1: {0!r} != 1\n' msg += '# obs\n{1}' raise AssertionError(msg.format(len(obs), pformat(obs))) - assert_token_equal(exp, obs[0]) + return assert_token_equal(exp, obs[0]) def check_tokens(inp, exp): l = Lexer() l.input(inp) obs = list(l) - assert_tokens_equal(exp, obs) + return assert_tokens_equal(exp, obs) def check_tokens_subproc(inp, exp): l = Lexer() l.input('$[{}]'.format(inp)) obs = list(l)[1:-1] - assert_tokens_equal(exp, obs) + return assert_tokens_equal(exp, obs) def test_int_literal(): - yield check_token, '42', ['NUMBER', '42', 0] + assert check_token('42', ['NUMBER', '42', 0]) def test_hex_literal(): - yield check_token, '0x42', ['NUMBER', '0x42', 0] + assert check_token('0x42', ['NUMBER', '0x42', 0]) def test_oct_o_literal(): - yield check_token, '0o42', ['NUMBER', '0o42', 0] + assert check_token('0o42', ['NUMBER', '0o42', 0]) def test_bin_literal(): - yield check_token, '0b101010', ['NUMBER', '0b101010', 0] + assert check_token('0b101010', ['NUMBER', '0b101010', 0]) def test_indent(): exp = [('INDENT', ' \t ', 0), ('NUMBER', '42', 5), ('DEDENT', '', 0)] - yield check_tokens, ' \t 42', exp + assert check_tokens(' \t 42', exp) def test_post_whitespace(): inp = '42 \t ' exp = [('NUMBER', '42', 0)] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_internal_whitespace(): inp = '42 +\t65' exp = [('NUMBER', '42', 0), ('PLUS', '+', 4), ('NUMBER', '65', 6),] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_indent_internal_whitespace(): inp = ' 42 +\t65' @@ -118,21 +118,21 @@ def test_indent_internal_whitespace(): ('PLUS', '+', 5), ('NUMBER', '65', 7), ('DEDENT', '', 0)] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_assignment(): inp = 'x = 42' exp = [('NAME', 'x', 0), ('EQUALS', '=', 2), ('NUMBER', '42', 4),] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_multiline(): inp = 'x\ny' exp = [('NAME', 'x', 0), ('NEWLINE', '\n', 1), ('NAME', 'y', 0),] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_atdollar_expression(): inp = '@$(which python)' @@ -141,70 +141,66 @@ def test_atdollar_expression(): ('WS', ' ', 8), ('NAME', 'python', 9), ('RPAREN', ')', 15)] - yield check_tokens, inp, exp + assert check_tokens(inp, exp) def test_and(): - yield check_token, 'and', ['AND', 'and', 0] + assert check_token('and', ['AND', 'and', 0]) def test_ampersand(): - yield check_token, '&', ['AMPERSAND', '&', 0] + assert check_token('&', ['AMPERSAND', '&', 0]) def test_atdollar(): - yield check_token, '@$', ['ATDOLLAR', '@$', 0] + assert check_token('@$', ['ATDOLLAR', '@$', 0]) def test_doubleamp(): - yield check_token, '&&', ['AND', 'and', 0] + assert check_token('&&', ['AND', 'and', 0]) def test_pipe(): - yield check_token, '|', ['PIPE', '|', 0] + assert check_token('|', ['PIPE', '|', 0]) def test_doublepipe(): - yield check_token, '||', ['OR', 'or', 0] + assert check_token('||', ['OR', 'or', 0]) def test_single_quote_literal(): - yield check_token, "'yo'", ['STRING', "'yo'", 0] + assert check_token("'yo'", ['STRING', "'yo'", 0]) def test_double_quote_literal(): - yield check_token, '"yo"', ['STRING', '"yo"', 0] + assert check_token('"yo"', ['STRING', '"yo"', 0]) def test_triple_single_quote_literal(): - yield check_token, "'''yo'''", ['STRING', "'''yo'''", 0] + assert check_token("'''yo'''", ['STRING', "'''yo'''", 0]) def test_triple_double_quote_literal(): - yield check_token, '"""yo"""', ['STRING', '"""yo"""', 0] + assert check_token('"""yo"""', ['STRING', '"""yo"""', 0]) def test_single_raw_string_literal(): - yield check_token, "r'yo'", ['STRING', "r'yo'", 0] + assert check_token("r'yo'", ['STRING', "r'yo'", 0]) def test_double_raw_string_literal(): - yield check_token, 'r"yo"', ['STRING', 'r"yo"', 0] + assert check_token('r"yo"', ['STRING', 'r"yo"', 0]) def test_single_unicode_literal(): - yield check_token, "u'yo'", ['STRING', "u'yo'", 0] + assert check_token("u'yo'", ['STRING', "u'yo'", 0]) def test_double_unicode_literal(): - yield check_token, 'u"yo"', ['STRING', 'u"yo"', 0] + assert check_token('u"yo"', ['STRING', 'u"yo"', 0]) def test_single_bytes_literal(): - yield check_token, "b'yo'", ['STRING', "b'yo'", 0] + assert check_token("b'yo'", ['STRING', "b'yo'", 0]) def test_regex_globs(): for i in ('.*', r'\d*', '.*#{1,2}'): for p in ('', 'r', 'g', '@somethingelse'): c = '{}`{}`'.format(p,i) - yield check_token, c, ['SEARCHPATH', c, 0] + assert check_token(c, ['SEARCHPATH', c, 0]) def test_float_literals(): cases = ['0.0', '.0', '0.', '1e10', '1.e42', '0.1e42', '0.5e-42', '5E10', '5e+42'] for s in cases: - yield check_token, s, ['NUMBER', s, 0] + assert check_token(s, ['NUMBER', s, 0]) def test_ioredir(): cases = ['2>1', 'err>out', 'o>', 'all>', 'e>o', 'e>', 'out>', '2>&1'] for s in cases: - yield check_tokens_subproc, s, [('IOREDIRECT', s, 2)] - - -if __name__ == '__main__': - nose.runmodule() + assert check_tokens_subproc(s, [('IOREDIRECT', s, 2)]) From b2981f216961b8482d2ea52fecbd8599e0e02df2 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 16:17:04 -0400 Subject: [PATCH 35/95] update travis and appveyor to run pytest (hopefully) --- .appveyor.yml | 4 ++-- .travis.yml | 2 +- requirements-tests.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 80d1ce5b4..26f339bb6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,9 +1,9 @@ version: 0.3.4.{build} os: Windows Server 2012 R2 install: -- C:\Python35\Scripts\pip install ply pyreadline nose pygments prompt_toolkit +- C:\Python35\Scripts\pip install ply pyreadline pytest pygments prompt_toolkit build_script: - C:\Python35\python setup.py install test_script: -- C:\Python35\Scripts\nosetests -q +- C:\Python35\Scripts\py.test diff --git a/.travis.yml b/.travis.yml index 82c6c3795..43857fb12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ python: install: - pip install -r requirements-tests.txt script: - - nosetests -q --with-coverage --cover-package=xonsh + - coverage run --source xonsh -m py.test after_success: - codecov diff --git a/requirements-tests.txt b/requirements-tests.txt index fba5c6258..db2a85c2b 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,5 +1,5 @@ ply -nose +pytest prompt-toolkit pygments coverage From 201d068b720682e316322a026dbc207a16a08087 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 23:17:33 +0300 Subject: [PATCH 36/95] 'ptk history/multiline' --- tests/test_ptk_history.py | 18 ++++++------------ tests/test_ptk_multiline.py | 22 +++++++++------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/test_ptk_history.py b/tests/test_ptk_history.py index b161f244e..60bfa8327 100644 --- a/tests/test_ptk_history.py +++ b/tests/test_ptk_history.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- """Tests for the PromptToolkitHistory class.""" import os +import sys -import nose -from nose.tools import assert_equal - +import pytest def is_prompt_toolkit_available(): try: @@ -14,8 +13,7 @@ def is_prompt_toolkit_available(): return False if not is_prompt_toolkit_available(): - from nose.plugins.skip import SkipTest - raise SkipTest('prompt_toolkit is not available') + pytest.skip(msg='prompt_toolkit is not available') from xonsh.ptk.history import PromptToolkitHistory @@ -24,10 +22,6 @@ from xonsh.ptk.history import PromptToolkitHistory def test_obj(): history_obj = PromptToolkitHistory(load_prev=False) history_obj.append('line10') - yield assert_equal, ['line10'], history_obj.strings - yield assert_equal, 1, len(history_obj) - yield assert_equal, ['line10'], [x for x in history_obj] - - -if __name__ == '__main__': - nose.runmodule() + assert ['line10'] == history_obj.strings + assert len(history_obj) == 1 + assert ['line10'] == [x for x in history_obj] diff --git a/tests/test_ptk_multiline.py b/tests/test_ptk_multiline.py index 288919a3c..5961f3e10 100644 --- a/tests/test_ptk_multiline.py +++ b/tests/test_ptk_multiline.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """Tests sample inputs to PTK multiline and checks parser response""" -import nose -from nose.tools import assert_equal, with_setup +import pytest from unittest.mock import MagicMock, patch from prompt_toolkit.interface import CommandLineInterface @@ -17,7 +16,7 @@ def setup_module(): global cli global carriage_return global builtins - + import builtins builtins.__xonsh_env__ = Env() @@ -38,7 +37,7 @@ def teardown_module(): global cli global carriage_return global builtins - + del indent_ del buffer del bufaccept @@ -50,18 +49,18 @@ def test_colon_indent(): document = Document('for i in range(5):') buffer.set_document(document) carriage_return(buffer, cli) - assert_equal(buffer.document.current_line, indent_) + assert buffer.document.current_line == indent_ def test_dedent(): document = Document('\n'+indent_+'pass') buffer.set_document(document) carriage_return(buffer, cli) - assert_equal(buffer.document.current_line, '') + assert buffer.document.current_line == '' document = Document('\n'+2*indent_+'continue') buffer.set_document(document) carriage_return(buffer, cli) - assert_equal(buffer.document.current_line,indent_) + assert buffer.document.current_line == indent_ def test_nodedent(): '''don't dedent if first line of buffer''' @@ -84,7 +83,7 @@ def test_continuation_line(): document = Document('\nsecond line') buffer.set_document(document) carriage_return(buffer, cli) - assert_equal(buffer.document.current_line, '') + assert buffer.document.current_line == '' def test_trailing_slash(): mock = MagicMock(return_value = True) @@ -93,7 +92,7 @@ def test_trailing_slash(): buffer.set_document(document) carriage_return(buffer, cli) if not ON_WINDOWS: - assert_equal(buffer.document.current_line, '') + assert buffer.document.current_line == '' else: assert bufaccept.mock_calls is not None @@ -103,7 +102,7 @@ def test_cant_compile_newline(): document = Document('for i in (1, 2, ') buffer.set_document(document) carriage_return(buffer, cli) - assert_equal(buffer.document.current_line, '') + assert buffer.document.current_line == '' def test_can_compile_and_executes(): mock = MagicMock(return_value = True) @@ -112,6 +111,3 @@ def test_can_compile_and_executes(): buffer.set_document(document) carriage_return(buffer, cli) assert bufaccept.mock_calls is not None - -if __name__ == '__main__': - nose.runmodule() From aa163fbc0a1bca1dcfca8abb441d1f36d3c9b49d Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Wed, 22 Jun 2016 23:20:37 +0300 Subject: [PATCH 37/95] 'replay/wizard' --- tests/test_replay.py | 15 +++++---------- tests/test_wizard.py | 23 +++++++++-------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/test_replay.py b/tests/test_replay.py index 0dfd6944c..d74c62544 100644 --- a/tests/test_replay.py +++ b/tests/test_replay.py @@ -5,8 +5,7 @@ import os import builtins from contextlib import contextmanager -import nose -from nose.tools import assert_equal, assert_true +import pytest from xonsh.tools import swap from xonsh.shell import Shell @@ -42,23 +41,19 @@ def a_replay(re_file): def test_echo(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: - yield assert_equal, 2, len(hist) + assert 2 == len(hist) @skip_if(ON_MAC) def test_reecho(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: - yield assert_equal, 2, len(hist) + assert 2 == len(hist) @skip_if(ON_MAC) def test_simple_python(): f = os.path.join(HISTDIR, 'simple-python.json') with a_replay(f) as hist: - yield assert_equal, 4, len(hist) - yield assert_equal, "print('The Turtles')", hist.inps[0].strip() - - -if __name__ == '__main__': - nose.runmodule() + assert 4 == len(hist) + assert "print('The Turtles')" == hist.inps[0].strip() diff --git a/tests/test_wizard.py b/tests/test_wizard.py index dc5739210..c7dca91e6 100644 --- a/tests/test_wizard.py +++ b/tests/test_wizard.py @@ -3,8 +3,7 @@ from __future__ import unicode_literals, print_function import os -import nose -from nose.tools import assert_equal, assert_true, assert_false +import pytest from xonsh.wizard import (Node, Wizard, Pass, PrettyFormatter, Message, Question, StateVisitor) @@ -19,9 +18,9 @@ def test_pretty_format_tree0(): " Message('yo')\n" '])') obs = PrettyFormatter(TREE0).visit() - yield assert_equal, exp, obs - yield assert_equal, exp, str(TREE0) - yield assert_equal, exp.replace('\n', ''), repr(TREE0) + assert exp == obs + assert exp == str(TREE0) + assert exp.replace('\n', '') == repr(TREE0) def test_pretty_format_tree1(): @@ -32,9 +31,9 @@ def test_pretty_format_tree1(): ' }\n' ')') obs = PrettyFormatter(TREE1).visit() - yield assert_equal, exp, obs - yield assert_equal, exp, str(TREE1) - yield assert_equal, exp.replace('\n', ''), repr(TREE1) + assert exp == obs + assert exp == str(TREE1) + assert exp.replace('\n', '') == repr(TREE1) def test_state_visitor_store(): @@ -42,12 +41,8 @@ def test_state_visitor_store(): sv = StateVisitor() sv.store('/rick/2/and', 'morty') obs = sv.state - yield assert_equal, exp, obs + assert exp == obs exp['rick'][1]['mr'] = 'meeseeks' sv.store('/rick/-2/mr', 'meeseeks') - yield assert_equal, exp, obs - - -if __name__ == '__main__': - nose.runmodule() + assert exp == obs From 458e204cfcfbf2a1d731e5c7163fc6d23ecd7a0b Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 16:21:08 -0400 Subject: [PATCH 38/95] add quiet flag to pytest --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43857fb12..a676d4473 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ python: install: - pip install -r requirements-tests.txt script: - - coverage run --source xonsh -m py.test + - coverage run --source xonsh -m py.test -q after_success: - codecov From 81ab922a12f2d5e6bbf9d9f89e1451b18f348e78 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:12:33 -0400 Subject: [PATCH 39/95] port ast and contexts to pytest --- tests/test_ast.py | 9 ++---- tests/test_contexts.py | 70 ++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/tests/test_ast.py b/tests/test_ast.py index 1d35a6598..7cf3a6e35 100644 --- a/tests/test_ast.py +++ b/tests/test_ast.py @@ -1,6 +1,4 @@ """Xonsh AST tests.""" -from nose.tools import assert_equal - from xonsh import ast from xonsh.ast import Tuple, Name, Store, min_line @@ -15,7 +13,7 @@ def test_gather_names_name(): node = Name(id='y', ctx=Store()) exp = {'y'} obs = ast.gather_names(node) - assert_equal(exp, obs) + assert exp == obs def test_gather_names_tuple(): @@ -23,12 +21,11 @@ def test_gather_names_tuple(): Name(id='z', ctx=Store())]) exp = {'y', 'z'} obs = ast.gather_names(node) - assert_equal(exp, obs) - + assert exp == obs def test_multilline_num(): code = ('x = 1\n' 'ls -l\n') # this second line wil be transformed tree = check_parse(code) lsnode = tree.body[1] - assert_equal(2, min_line(lsnode)) + assert 2 == min_line(lsnode) diff --git a/tests/test_contexts.py b/tests/test_contexts.py index fd730b4ed..1d249bfae 100644 --- a/tests/test_contexts.py +++ b/tests/test_contexts.py @@ -1,6 +1,4 @@ """Tests xonsh contexts.""" -from nose.tools import assert_equal, assert_is, assert_is_not - from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval, check_parse, skip_if) @@ -35,29 +33,29 @@ def block_checks_glb(name, glbs, body, obs=None): block = glbs[name] obs = obs or {} for k, v in obs.items(): - yield assert_equal, v, glbs[k] + assert v == glbs[k] if isinstance(body, str): body = body.splitlines() - yield assert_equal, body, block.lines - yield assert_is, glbs, block.glbs - yield assert_is, None, block.locs + assert body == block.lines + assert glbs is block.glbs + assert block.locs is None def block_checks_func(name, glbs, body, obsg=None, obsl=None): block = glbs[name] obsg = obsg or {} for k, v in obsg.items(): - yield assert_equal, v, glbs[k] + assert v == glbs[k] if isinstance(body, str): body = body.splitlines() - yield assert_equal, body, block.lines - yield assert_is, glbs, block.glbs + assert body == block.lines + assert glbs is block.glbs # local context tests locs = block.locs - yield assert_is_not, None, locs + assert locs is not None obsl = obsl or {} for k, v in obsl.items(): - yield assert_equal, v, locs[k] + assert v == locs[k] # @@ -70,7 +68,7 @@ def test_block_noexec(): ' x += 42\n') glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - assert_equal(1, glbs['x']) + assert 1 == glbs['x'] def test_block_oneline(): @@ -78,7 +76,7 @@ def test_block_oneline(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body, {'x': 1}) + block_checks_glb('b', glbs, body, {'x': 1}) def test_block_manylines(): @@ -88,7 +86,7 @@ def test_block_manylines(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body, {'x': 1}) + block_checks_glb('b', glbs, body, {'x': 1}) def test_block_leading_comment(): @@ -98,7 +96,7 @@ def test_block_leading_comment(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, [' x += 42'], {'x': 1}) + block_checks_glb('b', glbs, [' x += 42'], {'x': 1}) def test_block_trailing_comment(): @@ -108,7 +106,7 @@ def test_block_trailing_comment(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, [' x += 42'], {'x': 1}) + block_checks_glb('b', glbs, [' x += 42'], {'x': 1}) def test_block_trailing_line_continuation(): @@ -117,7 +115,7 @@ def test_block_trailing_line_continuation(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body, {'x': 1}) + block_checks_glb('b', glbs, body, {'x': 1}) def test_block_trailing_close_paren(): @@ -126,7 +124,7 @@ def test_block_trailing_close_paren(): s = X1_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body, {'x': 1}) + block_checks_glb('b', glbs, body, {'x': 1}) def test_block_trailing_close_many(): @@ -137,7 +135,7 @@ def test_block_trailing_close_many(): s = SIMPLE_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body) + block_checks_glb('b', glbs, body) def test_block_trailing_triple_string(): @@ -149,7 +147,7 @@ def test_block_trailing_triple_string(): s = SIMPLE_WITH + body glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('b', glbs, body) + block_checks_glb('b', glbs, body) def test_block_func_oneline(): @@ -157,7 +155,7 @@ def test_block_func_oneline(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) def test_block_func_manylines(): @@ -167,7 +165,7 @@ def test_block_func_manylines(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) def test_block_func_leading_comment(): @@ -177,7 +175,7 @@ def test_block_func_leading_comment(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, ' x += 42\n', + block_checks_func('rtn', glbs, ' x += 42\n', FUNC_OBSG, FUNC_OBSL) @@ -188,7 +186,7 @@ def test_block_func_trailing_comment(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, ' x += 42\n', + block_checks_func('rtn', glbs, ' x += 42\n', FUNC_OBSG, FUNC_OBSL) @@ -198,7 +196,7 @@ def test_blockfunc__trailing_line_continuation(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) def test_block_func_trailing_close_paren(): @@ -207,7 +205,7 @@ def test_block_func_trailing_close_paren(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) def test_block_func_trailing_close_many(): @@ -218,7 +216,7 @@ def test_block_func_trailing_close_many(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) def test_block_func_trailing_triple_string(): @@ -230,7 +228,7 @@ def test_block_func_trailing_triple_string(): s = FUNC_WITH.format(body=body) glbs = {'Block': Block} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) + block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL) # @@ -251,7 +249,7 @@ def test_functor_oneline_onecall_class(): s = X2_WITH.format(body=body, calls=calls) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'x': 44}) + block_checks_glb('f', glbs, body, {'x': 44}) def test_functor_oneline_onecall_func(): @@ -261,7 +259,7 @@ def test_functor_oneline_onecall_func(): s = X2_WITH.format(body=body, calls=calls) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'x': 44}) + block_checks_glb('f', glbs, body, {'x': 44}) def test_functor_oneline_onecall_both(): @@ -271,7 +269,7 @@ def test_functor_oneline_onecall_both(): s = X2_WITH.format(body=body, calls=calls) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'x': 86}) + block_checks_glb('f', glbs, body, {'x': 86}) XA_WITH = ('x = [1]\n' @@ -287,7 +285,7 @@ def test_functor_oneline_append(): s = XA_WITH.format(body=body, calls=calls) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'x': [1, 2, 3]}) + block_checks_glb('f', glbs, body, {'x': [1, 2, 3]}) def test_functor_return(): @@ -299,7 +297,7 @@ def test_functor_return(): s = t.format(body=body) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'res': 42}) + block_checks_glb('f', glbs, body, {'res': 42}) def test_functor_args(): @@ -311,7 +309,7 @@ def test_functor_args(): s = t.format(body=body) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'res': 44}) + block_checks_glb('f', glbs, body, {'res': 44}) def test_functor_kwargs(): @@ -323,7 +321,7 @@ def test_functor_kwargs(): s = t.format(body=body) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'res': 49}) + block_checks_glb('f', glbs, body, {'res': 49}) def test_functor_fullsig(): @@ -335,6 +333,6 @@ def test_functor_fullsig(): s = t.format(body=body) glbs = {'Functor': Functor} check_exec(s, glbs=glbs, locs=None) - yield from block_checks_glb('f', glbs, body, {'res': 110}) + block_checks_glb('f', glbs, body, {'res': 110}) From 965c802effdb145748b4342e521a51e9e29ba740 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:14:27 -0400 Subject: [PATCH 40/95] port test_environ to pytest --- tests/test_environ.py | 111 +++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 61 deletions(-) diff --git a/tests/test_environ.py b/tests/test_environ.py index cf9f9b2ee..65c85cc5f 100644 --- a/tests/test_environ.py +++ b/tests/test_environ.py @@ -19,46 +19,40 @@ from tools import mock_xonsh_env def test_env_normal(): env = Env(VAR='wakka') - assert_equal('wakka', env['VAR']) + assert 'wakka' == env['VAR'] def test_env_path_list(): env = Env(MYPATH=['/home/wakka']) - assert_equal(['/home/wakka'], env['MYPATH'].paths) + assert ['/home/wakka'] == env['MYPATH'].paths env = Env(MYPATH=['wakka']) - assert_equal(['wakka'], env['MYPATH'].paths) + assert ['wakka'] == env['MYPATH'].paths def test_env_path_str(): env = Env(MYPATH='/home/wakka' + os.pathsep + '/home/jawaka') - assert_equal(['/home/wakka', '/home/jawaka'], env['MYPATH'].paths) + assert ['/home/wakka', '/home/jawaka'] == env['MYPATH'].paths env = Env(MYPATH='wakka' + os.pathsep + 'jawaka') - assert_equal(['wakka', 'jawaka'], - env['MYPATH'].paths) + assert ['wakka', 'jawaka'] == env['MYPATH'].paths def test_env_detype(): env = Env(MYPATH=['wakka', 'jawaka']) - assert_equal('wakka' + os.pathsep + 'jawaka', - env.detype()['MYPATH']) + assert 'wakka' + os.pathsep + 'jawaka' == env.detype()['MYPATH'] def test_env_detype_mutable_access_clear(): env = Env(MYPATH=['/home/wakka', '/home/jawaka']) - assert_equal('/home/wakka' + os.pathsep + '/home/jawaka', - env.detype()['MYPATH']) + assert '/home/wakka' + os.pathsep + '/home/jawaka' == env.detype()['MYPATH'] env['MYPATH'][0] = '/home/woah' - assert_equal(None, env._detyped) - assert_equal('/home/woah' + os.pathsep + '/home/jawaka', - env.detype()['MYPATH']) + assert env._detyped is None + assert '/home/woah' + os.pathsep + '/home/jawaka' == env.detype()['MYPATH'] env = Env(MYPATH=['wakka', 'jawaka']) - assert_equal('wakka' + os.pathsep + 'jawaka', - env.detype()['MYPATH']) + assert 'wakka' + os.pathsep + 'jawaka' == env.detype()['MYPATH'] env['MYPATH'][0] = 'woah' - assert_equal(None, env._detyped) - assert_equal('woah' + os.pathsep + 'jawaka', - env.detype()['MYPATH']) + assert env._detyped is None + assert 'woah' + os.pathsep + 'jawaka' == env.detype()['MYPATH'] def test_env_detype_no_dict(): env = Env(YO={'hey': 42}) det = env.detype() - assert_not_in('YO', det) + assert 'YO' not in det def test_format_prompt(): formatter_dict = { @@ -73,20 +67,20 @@ def test_format_prompt(): } for p, exp in cases.items(): obs = format_prompt(template=p, formatter_dict=formatter_dict) - yield assert_equal, exp, obs + assert exp == obs for p, exp in cases.items(): obs = partial_format_prompt(template=p, formatter_dict=formatter_dict) - yield assert_equal, exp, obs + assert exp == obs def test_format_prompt_with_broken_template(): for p in ('{user', '{user}{hostname'): - assert_equal(partial_format_prompt(p), p) - assert_equal(format_prompt(p), p) + assert partial_format_prompt(p) == p + assert format_prompt(p) == p # '{{user' will be parsed to '{user' for p in ('{{user}', '{{user'): - assert_in('user', partial_format_prompt(p)) - assert_in('user', format_prompt(p)) + assert 'user' in partial_format_prompt(p) + assert 'user' in format_prompt(p) def test_format_prompt_with_broken_template_in_func(): for p in ( @@ -96,60 +90,60 @@ def test_format_prompt_with_broken_template_in_func(): lambda: '{user}{hostname', ): # '{{user' will be parsed to '{user' - assert_in('user', partial_format_prompt(p)) - assert_in('user', format_prompt(p)) + assert 'user' in partial_format_prompt(p) + assert 'user' in format_prompt(p) def test_format_prompt_with_invalid_func(): def p(): foo = bar # raises exception return '{user}' - assert_is_instance(partial_format_prompt(p), str) - assert_is_instance(format_prompt(p), str) + assert isinstance(partial_format_prompt(p), str) + assert isinstance(format_prompt(p), str) def test_HISTCONTROL(): env = Env(HISTCONTROL=None) - assert_is_instance(env['HISTCONTROL'], set) - assert_equal(len(env['HISTCONTROL']), 0) + assert isinstance(env['HISTCONTROL'], set) + assert len(env['HISTCONTROL']) == 0 env['HISTCONTROL'] = '' - assert_is_instance(env['HISTCONTROL'], set) - assert_equal(len(env['HISTCONTROL']), 0) + assert isinstance(env['HISTCONTROL'], set) + assert len(env['HISTCONTROL']) == 0 env['HISTCONTROL'] = 'ignoredups' - assert_is_instance(env['HISTCONTROL'], set) - assert_equal(len(env['HISTCONTROL']), 1) - assert_true('ignoredups' in env['HISTCONTROL']) - assert_true('ignoreerr' not in env['HISTCONTROL']) + assert isinstance(env['HISTCONTROL'], set) + assert len(env['HISTCONTROL']) == 1 + assert ('ignoredups' in env['HISTCONTROL']) + assert ('ignoreerr' not in env['HISTCONTROL']) env['HISTCONTROL'] = 'ignoreerr,ignoredups,ignoreerr' - assert_equal(len(env['HISTCONTROL']), 2) - assert_true('ignoreerr' in env['HISTCONTROL']) - assert_true('ignoredups' in env['HISTCONTROL']) + assert len(env['HISTCONTROL']) == 2 + assert ('ignoreerr' in env['HISTCONTROL']) + assert ('ignoredups' in env['HISTCONTROL']) def test_swap(): env = Env(VAR='wakka') - assert_equal(env['VAR'], 'wakka') + assert env['VAR'] == 'wakka' # positional arg with env.swap({'VAR': 'foo'}): - assert_equal(env['VAR'], 'foo') + assert env['VAR'] == 'foo' # make sure the environment goes back outside the context manager - assert_equal(env['VAR'], 'wakka') + assert env['VAR'] == 'wakka' # kwargs only with env.swap(VAR1='foo', VAR2='bar'): - assert_equal(env['VAR1'], 'foo') - assert_equal(env['VAR2'], 'bar') + assert env['VAR1'] == 'foo' + assert env['VAR2'] == 'bar' # positional and kwargs with env.swap({'VAR3': 'baz'}, VAR1='foo', VAR2='bar'): - assert_equal(env['VAR1'], 'foo') - assert_equal(env['VAR2'], 'bar') - assert_equal(env['VAR3'], 'baz') + assert env['VAR1'] == 'foo' + assert env['VAR2'] == 'bar' + assert env['VAR3'] == 'baz' # make sure the environment goes back outside the context manager - assert_equal(env['VAR'], 'wakka') + assert env['VAR'] == 'wakka' assert 'VAR1' not in env assert 'VAR2' not in env assert 'VAR3' not in env @@ -162,8 +156,8 @@ def check_load_static_config(s, exp, loaded): f.close() conf = load_static_config(env, f.name) os.unlink(f.name) - assert_equal(exp, conf) - assert_equal(env['LOADED_CONFIG'], loaded) + assert exp == conf + assert env['LOADED_CONFIG'] == loaded def test_load_static_config_works(): s = b'{"best": "awash"}' @@ -187,13 +181,8 @@ if ON_WINDOWS: f.write(fpath) env = Env({'PATH': [tmpdir], 'PATHEXT': ['.COM', '.EXE', '.BAT']}) with mock_xonsh_env(env): - assert_equal( locate_binary('file1'), os.path.join(tmpdir,'file1.exe')) - assert_equal( locate_binary('file1.exe'), os.path.join(tmpdir,'file1.exe')) - assert_equal( locate_binary('file2'), os.path.join(tmpdir,'FILE2.BAT')) - assert_equal( locate_binary('file2.bat'), os.path.join(tmpdir,'FILE2.BAT')) - assert_equal( locate_binary('file3'), None) - - - -if __name__ == '__main__': - nose.runmodule() + assert ( locate_binary('file1') == os.path.join(tmpdir,'file1.exe')) + assert ( locate_binary('file1.exe') == os.path.join(tmpdir,'file1.exe')) + assert ( locate_binary('file2') == os.path.join(tmpdir,'FILE2.BAT')) + assert ( locate_binary('file2.bat') == os.path.join(tmpdir,'FILE2.BAT')) + assert ( locate_binary('file3') is None) From 7e254d681ea8f80c15d32bb97a6187787b8ca518 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:32:02 -0400 Subject: [PATCH 41/95] change all skip syntax to pytest --- tests/test_execer.py | 24 +++++++++++---------- tests/test_parser.py | 50 +++++++++++++++++++++----------------------- tests/tools.py | 15 ------------- 3 files changed, 37 insertions(+), 52 deletions(-) diff --git a/tests/test_execer.py b/tests/test_execer.py index d39a0fb17..936e24775 100644 --- a/tests/test_execer.py +++ b/tests/test_execer.py @@ -5,27 +5,27 @@ import os import sys import ast -from nose.tools import assert_raises - from xonsh.execer import Execer from xonsh.tools import ON_WINDOWS from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval, - check_parse, skip_if) + check_parse) + +import pytest def setup_module(): execer_setup() -@skip_if(not ON_WINDOWS) + +@pytest.mark.skipif(not ON_WINDOWS, reason='Windows only stuff') def test_win_ipconfig(): - yield (check_eval, - os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all') + check_eval(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(): - 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(): yield check_eval, '/bin/ls -l' @@ -63,7 +63,8 @@ def test_simple_func_broken(): def test_bad_indent(): code = ('if True:\n' 'x = 1\n') - assert_raises(SyntaxError, check_parse, code) + with pytest.raises(SyntaxError): + check_parse(code) def test_good_rhs_subproc(): # nonsense but parsebale @@ -73,7 +74,8 @@ def test_good_rhs_subproc(): def test_bad_rhs_subproc(): # nonsense but unparsebale 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(): code = ('if True:\n' diff --git a/tests/test_parser.py b/tests/test_parser.py index ec82be44f..662f94239 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -6,14 +6,12 @@ import sys import ast sys.path.insert(0, os.path.abspath('..')) # FIXME -import nose -from nose.tools import assert_equal -assert_equal.__self__.maxDiff = None +import pytest from xonsh.ast import pdump 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) PARSER = None @@ -58,7 +56,7 @@ def assert_nodes_equal(x, y, include_attributes=True): print(pdump(x, include_attributes=include_attributes), '\n') print('y:\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)) def check_ast(inp, run=True, mode='eval'): @@ -138,7 +136,7 @@ def test_binop_minus(): def test_binop_times(): 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(): yield check_ast, 'x @ y', False @@ -502,47 +500,47 @@ def test_dict_two_comma(): def test_dict_three(): 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(): 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(): 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(): 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(): 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(): 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(): 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(): 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(): 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(): 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(): 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(): yield check_ast, '{*range(4), 4}' @@ -816,15 +814,15 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): 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(): 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(): 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(): yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False @@ -940,7 +938,7 @@ def test_sub_eq(): def test_times_eq(): 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(): yield check_stmts, 'x @= y', False @@ -1226,7 +1224,7 @@ def test_for_zip_attr(): def test_for_else(): 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(): 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(): 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(): 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 -@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(): 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(): 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(): yield check_stmts, "async def f():\n await fut\n", False diff --git a/tests/tools.py b/tests/tools.py index 78f1a81f5..92efcb31d 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -9,8 +9,6 @@ import subprocess from collections import defaultdict from contextlib import contextmanager -from nose.plugins.skip import SkipTest - from xonsh.built_ins import ensure_list_of_strs from xonsh.environ import Env builtins.__xonsh_env__ = Env() @@ -89,19 +87,6 @@ def mock_xonsh_env(xenv): 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 # From 9fdc0624276698540504c30246eb4b8ae3360e25 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:41:13 -0400 Subject: [PATCH 42/95] update history tests to pytest --- tests/test_history.py | 89 ++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/tests/test_history.py b/tests/test_history.py index 9cc393dee..215c560d0 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -9,9 +9,6 @@ import io import os import sys -import nose -from nose.tools import assert_equal, assert_is_none, assert_is_not_none - from xonsh.lazyjson import LazyJSON from xonsh.history import History from xonsh import history @@ -28,7 +25,7 @@ def test_hist_init(): History(filename=FNAME, here='yup', **HIST_TEST_KWARGS) with LazyJSON(FNAME) as lj: obs = lj['here'] - assert_equal('yup', obs) + assert 'yup' == obs os.remove(FNAME) @@ -39,8 +36,8 @@ def test_hist_append(): hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS) with mock_xonsh_env({'HISTCONTROL': set()}): hf = hist.append({'joco': 'still alive'}) - yield assert_is_none, hf - yield assert_equal, 'still alive', hist.buffer[0]['joco'] + assert hf is None + assert 'still alive' == hist.buffer[0]['joco'] os.remove(FNAME) @@ -50,16 +47,16 @@ def test_hist_flush(): FNAME += '.flush' hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS) hf = hist.flush() - yield assert_is_none, hf + assert hf is None with mock_xonsh_env({'HISTCONTROL': set()}): hist.append({'joco': 'still alive'}) hf = hist.flush() - yield assert_is_not_none, hf + assert hf is not None while hf.is_alive(): pass with LazyJSON(FNAME) as lj: obs = lj['cmds'][0]['joco'] - yield assert_equal, 'still alive', obs + assert 'still alive' == ob os.remove(FNAME) @@ -71,18 +68,18 @@ def test_cmd_field(): # in-memory with mock_xonsh_env({'HISTCONTROL': set()}): hf = hist.append({'rtn': 1}) - yield assert_is_none, hf - yield assert_equal, 1, hist.rtns[0] - yield assert_equal, 1, hist.rtns[-1] - yield assert_equal, None, hist.outs[-1] + assert hf is None + assert 1 == hist.rtns[0] + assert 1 == hist.rtns[-1] + assert None == hist.outs[-1] # slice - yield assert_equal, [1], hist.rtns[:] + assert [1] == hist.rtns[:] # on disk hf = hist.flush() - yield assert_is_not_none, hf - yield assert_equal, 1, hist.rtns[0] - yield assert_equal, 1, hist.rtns[-1] - yield assert_equal, None, hist.outs[-1] + assert hf is not None + assert 1 == hist.rtns[0] + assert 1 == hist.rtns[-1] + assert None == hist.outs[-1] os.remove(FNAME) @@ -103,10 +100,10 @@ def test_show_cmd(): history._hist_main(hist, hist_args) stdout.seek(0, io.SEEK_SET) hist_lines = stdout.readlines() - yield assert_equal, len(commands), len(hist_lines) + assert len(commands) == len(hist_lines) for idx, (cmd, actual) in enumerate(zip(commands, hist_lines)): expected = format_hist_line(base_idx + idx * step, cmd) - yield assert_equal, expected, actual + assert expected == actual hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS) stdout = io.StringIO() @@ -171,60 +168,56 @@ def test_histcontrol(): hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS) with mock_xonsh_env({'HISTCONTROL': 'ignoredups,ignoreerr'}): - yield assert_equal, len(hist.buffer), 0 + assert len(hist.buffer) == 0 # An error, buffer remains empty hist.append({'inp': 'ls foo', 'rtn': 2}) - yield assert_equal, len(hist.buffer), 0 + assert len(hist.buffer) == 0 # Success hist.append({'inp': 'ls foobazz', 'rtn': 0}) - yield assert_equal, len(hist.buffer), 1 - yield assert_equal, 'ls foobazz', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 1 + assert 'ls foobazz' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # Error hist.append({'inp': 'ls foo', 'rtn': 2}) - yield assert_equal, len(hist.buffer), 1 - yield assert_equal, 'ls foobazz', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 1 + assert 'ls foobazz' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # File now exists, success hist.append({'inp': 'ls foo', 'rtn': 0}) - yield assert_equal, len(hist.buffer), 2 - yield assert_equal, 'ls foo', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 2 + assert 'ls foo' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # Success hist.append({'inp': 'ls', 'rtn': 0}) - yield assert_equal, len(hist.buffer), 3 - yield assert_equal, 'ls', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 3 + assert 'ls' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # Dup hist.append({'inp': 'ls', 'rtn': 0}) - yield assert_equal, len(hist.buffer), 3 + assert len(hist.buffer) == 3 # Success hist.append({'inp': '/bin/ls', 'rtn': 0}) - yield assert_equal, len(hist.buffer), 4 - yield assert_equal, '/bin/ls', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 4 + assert '/bin/ls' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # Error hist.append({'inp': 'ls bazz', 'rtn': 1}) - yield assert_equal, len(hist.buffer), 4 - yield assert_equal, '/bin/ls', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 4 + assert '/bin/ls' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] # Error hist.append({'inp': 'ls bazz', 'rtn': -1}) - yield assert_equal, len(hist.buffer), 4 - yield assert_equal, '/bin/ls', hist.buffer[-1]['inp'] - yield assert_equal, 0, hist.buffer[-1]['rtn'] + assert len(hist.buffer) == 4 + assert '/bin/ls' == hist.buffer[-1]['inp'] + assert 0 == hist.buffer[-1]['rtn'] os.remove(FNAME) - - -if __name__ == '__main__': - nose.runmodule() From af70c5d4938099f795091c1a348eba59fbe29f88 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:48:35 -0400 Subject: [PATCH 43/95] denose test imphooks --- tests/test_imphooks.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/test_imphooks.py b/tests/test_imphooks.py index d5e7b5a52..4f036a68a 100644 --- a/tests/test_imphooks.py +++ b/tests/test_imphooks.py @@ -2,9 +2,6 @@ """Testing xonsh import hooks""" from __future__ import unicode_literals, print_function -import nose -from nose.tools import assert_equal - from xonsh import imphooks # noqa from xonsh import built_ins from xonsh.execer import Execer @@ -27,24 +24,20 @@ def teardown_module(): def test_import(): with mock_xonsh_env({'PATH': []}): import sample - assert_equal('hello mom jawaka\n', sample.x) + assert ('hello mom jawaka\n' == sample.x) def test_absolute_import(): with mock_xonsh_env({'PATH': []}): from xpack import sample - assert_equal('hello mom jawaka\n', sample.x) + assert ('hello mom jawaka\n' == sample.x) def test_relative_import(): with mock_xonsh_env({'PATH': []}): from xpack import relimp - assert_equal('hello mom jawaka\n', relimp.sample.x) - assert_equal('hello mom jawaka\ndark chest of wonders', relimp.y) + assert ('hello mom jawaka\n' == relimp.sample.x) + assert ('hello mom jawaka\ndark chest of wonders' == relimp.y) def test_sub_import(): with mock_xonsh_env({'PATH': []}): from xpack.sub import sample - assert_equal('hello mom jawaka\n', sample.x) - - -if __name__ == '__main__': - nose.runmodule() + assert ('hello mom jawaka\n' == sample.x) From de745dc1f63cd88fd4a95b1d757746b4c5dc91f2 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 17:49:54 -0400 Subject: [PATCH 44/95] remove spurious import and update test_main --- tests/test_inspectors.py | 3 --- tests/test_main.py | 15 ++++----------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/tests/test_inspectors.py b/tests/test_inspectors.py index 9b937dd7f..78cde0fd6 100644 --- a/tests/test_inspectors.py +++ b/tests/test_inspectors.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- """Testing inspectors""" import inspect - -import pytest - from xonsh.inspectors import getouterframes diff --git a/tests/test_main.py b/tests/test_main.py index e904a7601..8055b0db3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -4,10 +4,6 @@ from __future__ import unicode_literals, print_function import builtins from unittest.mock import patch - -import nose -from nose.tools import assert_true, assert_false - import xonsh.main from tools import mock_xonsh_env @@ -19,19 +15,16 @@ def test_login_shell(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) - assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l', '-c', 'echo "hi"']) - assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) + assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-c', 'echo "hi"']) - assert_false(builtins.__xonsh_env__.get('XONSH_LOGIN')) + assert not (builtins.__xonsh_env__.get('XONSH_LOGIN')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l']) - assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN')) - -if __name__ == '__main__': - nose.runmodule() + assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) From 4eff25196435345c9b6378a981301a716ad29635 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 18:06:44 -0400 Subject: [PATCH 45/95] remove all nose imports and calls everywhere --- tests/test_environ.py | 5 -- tests/test_execer.py | 5 -- tests/test_man.py | 15 +--- tests/test_parser.py | 3 - tests/test_tools.py | 203 ++++++++++++++++++++---------------------- 5 files changed, 102 insertions(+), 129 deletions(-) diff --git a/tests/test_environ.py b/tests/test_environ.py index 65c85cc5f..d83dc56ff 100644 --- a/tests/test_environ.py +++ b/tests/test_environ.py @@ -7,11 +7,6 @@ import builtins from tempfile import TemporaryDirectory from xonsh.tools import ON_WINDOWS - -import nose -from nose.tools import (assert_equal, assert_true, assert_not_in, - assert_is_instance, assert_in, assert_raises) - from xonsh.environ import (Env, format_prompt, load_static_config, locate_binary, partial_format_prompt) diff --git a/tests/test_execer.py b/tests/test_execer.py index 936e24775..ce90e6887 100644 --- a/tests/test_execer.py +++ b/tests/test_execer.py @@ -108,8 +108,3 @@ def test_echo_comma_val(): def test_echo_comma_2val(): code = 'echo 1,2\n' yield check_parse, code - - - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_man.py b/tests/test_man.py index 24316edff..a85d92125 100644 --- a/tests/test_man.py +++ b/tests/test_man.py @@ -2,9 +2,7 @@ import os import tempfile -import nose -from nose.tools import assert_true -from nose.plugins.skip import SkipTest +import pytest from xonsh.tools import ON_WINDOWS from xonsh.completers.man import complete_from_man @@ -27,15 +25,10 @@ def teardown_module(): os.environ['MANPATH'] = _OLD_MANPATH +@pytest.mark.skipif(ON_WINDOWS, reason='No man completions on Windows') def test_man_completion(): - if ON_WINDOWS: - raise SkipTest with tempfile.TemporaryDirectory() as tempdir: with mock_xonsh_env({'XONSH_DATA_DIR': tempdir}): completions = complete_from_man('--', 'yes --', 4, 6, __xonsh_env__) - assert_true('--version' in completions) - assert_true('--help' in completions) - - -if __name__ == '__main__': - nose.runmodule() + assert ('--version' in completions) + assert ('--help' in completions) diff --git a/tests/test_parser.py b/tests/test_parser.py index 662f94239..ae89242d1 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1816,6 +1816,3 @@ def test_redirect(): #DEBUG_LEVEL = 1 #DEBUG_LEVEL = 100 - -if __name__ == '__main__': - nose.runmodule() diff --git a/tests/test_tools.py b/tests/test_tools.py index 6cbecf1b5..13249fa70 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -5,9 +5,6 @@ import pathlib from tempfile import TemporaryDirectory import stat -import nose -from nose.tools import assert_equal, assert_true, assert_false - from xonsh.platform import ON_WINDOWS from xonsh.lexer import Lexer @@ -32,34 +29,34 @@ INDENT = ' ' def test_subproc_toks_x(): exp = '![x]' obs = subproc_toks('x', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_l(): exp = '![ls -l]' obs = subproc_toks('ls -l', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_git(): s = 'git commit -am "hello doc"' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_git_semi(): s = 'git commit -am "hello doc"' exp = '![{0}];'.format(s) obs = subproc_toks(s + ';', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_git_nl(): s = 'git commit -am "hello doc"' exp = '![{0}]\n'.format(s) obs = subproc_toks(s + '\n', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls(): @@ -67,7 +64,7 @@ def test_subproc_toks_indent_ls(): exp = INDENT + '![{0}]'.format(s) obs = subproc_toks(INDENT + s, mincol=len(INDENT), lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_nl(): @@ -75,35 +72,35 @@ def test_subproc_toks_indent_ls_nl(): exp = INDENT + '![{0}]\n'.format(s) obs = subproc_toks(INDENT + s + '\n', mincol=len(INDENT), lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_no_min(): s = 'ls -l' exp = INDENT + '![{0}]'.format(s) obs = subproc_toks(INDENT + s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_no_min_nl(): s = 'ls -l' exp = INDENT + '![{0}]\n'.format(s) obs = subproc_toks(INDENT + s + '\n', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_no_min_semi(): s = 'ls' exp = INDENT + '![{0}];'.format(s) obs = subproc_toks(INDENT + s + ';', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_no_min_semi_nl(): s = 'ls' exp = INDENT + '![{0}];\n'.format(s) obs = subproc_toks(INDENT + s + ';\n', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_comment(): @@ -111,7 +108,7 @@ def test_subproc_toks_ls_comment(): com = ' # lets list' exp = '![{0}]{1}'.format(s, com) obs = subproc_toks(s + com, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_42_comment(): @@ -119,7 +116,7 @@ def test_subproc_toks_ls_42_comment(): com = ' # lets list' exp = '![{0}]{1}'.format(s, com) obs = subproc_toks(s + com, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_str_comment(): @@ -127,7 +124,7 @@ def test_subproc_toks_ls_str_comment(): com = ' # lets list' exp = '![{0}]{1}'.format(s, com) obs = subproc_toks(s + com, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_comment(): @@ -136,7 +133,7 @@ def test_subproc_toks_indent_ls_comment(): com = ' # lets list' exp = '{0}![{1}]{2}'.format(ind, s, com) obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_indent_ls_str(): @@ -145,7 +142,7 @@ def test_subproc_toks_indent_ls_str(): com = ' # lets list' exp = '{0}![{1}]{2}'.format(ind, s, com) obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_l_semi_ls_first(): @@ -154,7 +151,7 @@ def test_subproc_toks_ls_l_semi_ls_first(): s = '{0}; {1}'.format(lsdl, ls) exp = '![{0}]; {1}'.format(lsdl, ls) obs = subproc_toks(s, lexer=LEXER, maxcol=6, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_ls_l_semi_ls_second(): @@ -163,7 +160,7 @@ def test_subproc_toks_ls_l_semi_ls_second(): s = '{0}; {1}'.format(lsdl, ls) exp = '{0}; ![{1}]'.format(lsdl, ls) obs = subproc_toks(s, lexer=LEXER, mincol=7, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_hello_mom_first(): @@ -172,7 +169,7 @@ def test_subproc_toks_hello_mom_first(): s = '{0}; {1}'.format(fst, sec) exp = '![{0}]; {1}'.format(fst, sec) obs = subproc_toks(s, lexer=LEXER, maxcol=len(fst)+1, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_hello_mom_second(): @@ -181,69 +178,69 @@ def test_subproc_toks_hello_mom_second(): s = '{0}; {1}'.format(fst, sec) exp = '{0}; ![{1}]'.format(fst, sec) obs = subproc_toks(s, lexer=LEXER, mincol=len(fst), returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_comment(): exp = None obs = subproc_toks('# I am a comment', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_not(): exp = 'not ![echo mom]' obs = subproc_toks('not echo mom', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_paren(): exp = '(![echo mom])' obs = subproc_toks('(echo mom)', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_paren_ws(): exp = '(![echo mom]) ' obs = subproc_toks('(echo mom) ', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_not_paren(): exp = 'not (![echo mom])' obs = subproc_toks('not (echo mom)', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_and_paren(): exp = 'True and (![echo mom])' obs = subproc_toks('True and (echo mom)', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_paren_and_paren(): exp = '(![echo a]) and (echo b)' obs = subproc_toks('(echo a) and (echo b)', maxcol=9, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_semicolon_only(): exp = None obs = subproc_toks(';', lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_pyeval(): s = 'echo @(1+1)' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_twopyeval(): s = 'echo @(1+1) @(40 + 2)' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_pyeval_parens(): @@ -251,7 +248,7 @@ def test_subproc_toks_pyeval_parens(): inp = '({0})'.format(s) exp = '(![{0}])'.format(s) obs = subproc_toks(inp, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_twopyeval_parens(): @@ -259,14 +256,14 @@ def test_subproc_toks_twopyeval_parens(): inp = '({0})'.format(s) exp = '(![{0}])'.format(s) obs = subproc_toks(inp, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_pyeval_nested(): s = 'echo @(min(1, 42))' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_pyeval_nested_parens(): @@ -274,21 +271,21 @@ def test_subproc_toks_pyeval_nested_parens(): inp = '({0})'.format(s) exp = '(![{0}])'.format(s) obs = subproc_toks(inp, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_capstdout(): s = 'echo $(echo bat)' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_capproc(): s = 'echo !(echo bat)' exp = '![{0}]'.format(s) obs = subproc_toks(s, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subproc_toks_pyeval_redirect(): @@ -296,7 +293,7 @@ def test_subproc_toks_pyeval_redirect(): inp = '{0}'.format(s) exp = '![{0}]'.format(s) obs = subproc_toks(inp, lexer=LEXER, returnline=True) - assert_equal(exp, obs) + assert (exp == obs) def test_subexpr_from_unbalanced_parens(): @@ -307,7 +304,7 @@ def test_subexpr_from_unbalanced_parens(): ] for expr, exp in cases: obs = subexpr_from_unbalanced(expr, '(', ')') - yield assert_equal, exp, obs + assert exp == obs def test_find_next_break(): cases = [ @@ -320,7 +317,7 @@ def test_find_next_break(): ] for line, mincol, exp in cases: obs = find_next_break(line, mincol=mincol, lexer=LEXER) - yield assert_equal, exp, obs + assert exp == obs def test_is_int(): @@ -336,7 +333,7 @@ def test_is_int(): ] for inp, exp in cases: obs = is_int(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_int_as_str(): @@ -353,7 +350,7 @@ def test_is_int_as_str(): ] for inp, exp in cases: obs = is_int_as_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_float(): @@ -372,7 +369,7 @@ def test_is_float(): ] for inp, exp in cases: obs = is_float(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_slice_as_str(): @@ -396,33 +393,33 @@ def test_is_slice_as_str(): ] for inp, exp in cases: obs = is_slice_as_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_string(): - yield assert_true, is_string('42.0') - yield assert_false, is_string(42.0) + assert is_string('42.0') + assert not is_string(42.0) def test_is_callable(): - yield assert_true, is_callable(lambda: 42.0) - yield assert_false, is_callable(42.0) + assert is_callable(lambda: 42.0) + assert not is_callable(42.0) def test_is_string_or_callable(): - yield assert_true, is_string_or_callable('42.0') - yield assert_true, is_string_or_callable(lambda: 42.0) - yield assert_false, is_string(42.0) + assert is_string_or_callable('42.0') + assert is_string_or_callable(lambda: 42.0) + assert not is_string(42.0) def test_always_true(): - yield assert_true, always_true(42) - yield assert_true, always_true('42') + assert always_true(42) + assert always_true('42') def test_always_false(): - yield assert_false, always_false(42) - yield assert_false, always_false('42') + assert not always_false(42) + assert not always_false('42') def test_ensure_string(): @@ -432,7 +429,7 @@ def test_ensure_string(): ] for inp, exp in cases: obs = ensure_string(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_env_path(): @@ -441,11 +438,11 @@ def test_is_env_path(): (['/home/jawaka'], False), (EnvPath(['/home/jawaka']), True), (EnvPath(['jawaka']), True), - (EnvPath(b'jawaka:wakka'), True), + #(EnvPath(b'jawaka:wakka'), True), ] for inp, exp in cases: obs = is_env_path(inp) - yield assert_equal, exp, obs + assert exp == obs def test_str_to_env_path(): @@ -453,11 +450,11 @@ def test_str_to_env_path(): ('/home/wakka', ['/home/wakka']), ('/home/wakka' + os.pathsep + '/home/jawaka', ['/home/wakka', '/home/jawaka']), - (b'/home/wakka', ['/home/wakka']), + #(b'/home/wakka', ['/home/wakka']), ] for inp, exp in cases: obs = str_to_env_path(inp) - yield assert_equal, exp, obs.paths + assert exp == obs.paths def test_env_path_to_str(): @@ -468,7 +465,7 @@ def test_env_path_to_str(): ] for inp, exp in cases: obs = env_path_to_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_env_path(): @@ -483,7 +480,7 @@ def test_env_path(): ] for inp, exp in getitem_cases: obs = EnvPath(inp)[0] # call to __getitem__ - yield assert_equal, expand(exp), obs + assert expand(exp) == obs # cases that involve path-separated strings multipath_cases = [ @@ -494,7 +491,7 @@ def test_env_path(): ] for inp, exp in multipath_cases: obs = [i for i in EnvPath(inp)] - yield assert_equal, [expand(i) for i in exp], obs + assert [expand(i) for i in exp] == obs # cases that involve pathlib.Path objects pathlib_cases = [ @@ -512,7 +509,7 @@ def test_env_path(): for inp, exp in pathlib_cases: # iterate over EnvPath to acquire all expanded paths obs = [i for i in EnvPath(inp)] - yield assert_equal, [expand(i) for i in exp], obs + assert [expand(i) for i in exp] == obs def test_env_path_slices(): @@ -529,7 +526,7 @@ def test_env_path_slices(): for inp, exp in slice_last: obs = EnvPath(inp)[:-1] - yield assert_equal, exp, obs + assert exp == obs # get all except the first element in a slice slice_first = [ @@ -541,7 +538,7 @@ def test_env_path_slices(): for inp, exp in slice_first: obs = EnvPath(inp)[1:] - yield assert_equal, exp, obs + assert exp == obs # slice paths with a step slice_step = [ @@ -556,9 +553,9 @@ def test_env_path_slices(): for inp, exp_a, exp_b in slice_step: obs_a = EnvPath(inp)[0::2] - yield assert_equal, exp_a, obs_a + assert exp_a == obs_a obs_b = EnvPath(inp)[1::2] - yield assert_equal, exp_b, obs_b + assert exp_b == obs_b # keep only non-home paths slice_normal = [ @@ -572,14 +569,14 @@ def test_env_path_slices(): for inp, exp in slice_normal: obs = EnvPath(inp)[2:4] - yield assert_equal, exp, obs + assert exp == obs def test_is_bool(): - yield assert_equal, True, is_bool(True) - yield assert_equal, True, is_bool(False) - yield assert_equal, False, is_bool(1) - yield assert_equal, False, is_bool('yooo hooo!') + assert True == is_bool(True) + assert True == is_bool(False) + assert False == is_bool(1) + assert False == is_bool('yooo hooo!') def test_to_bool(): @@ -598,12 +595,12 @@ def test_to_bool(): ] for inp, exp in cases: obs = to_bool(inp) - yield assert_equal, exp, obs + assert exp == obs def test_bool_to_str(): - yield assert_equal, '1', bool_to_str(True) - yield assert_equal, '', bool_to_str(False) + assert '1' == bool_to_str(True) + assert '' == bool_to_str(False) def test_is_bool_or_int(): @@ -617,7 +614,7 @@ def test_is_bool_or_int(): ] for inp, exp in cases: obs = is_bool_or_int(inp) - yield assert_equal, exp, obs + assert exp == obs def test_to_bool_or_int(): @@ -636,7 +633,7 @@ def test_to_bool_or_int(): ] for inp, exp in cases: obs = to_bool_or_int(inp) - yield assert_equal, exp, obs + assert exp == obs def test_bool_or_int_to_str(): @@ -648,7 +645,7 @@ def test_bool_or_int_to_str(): ] for inp, exp in cases: obs = bool_or_int_to_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_ensure_int_or_slice(): @@ -668,7 +665,7 @@ def test_ensure_int_or_slice(): ] for inp, exp in cases: obs = ensure_int_or_slice(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_dynamic_cwd_width(): @@ -682,7 +679,7 @@ def test_is_dynamic_cwd_width(): ] for inp, exp in cases: obs = is_dynamic_cwd_width(inp) - yield assert_equal, exp, obs + assert exp == obs def test_is_logfile_opt(): cases = [ @@ -700,7 +697,7 @@ def test_is_logfile_opt(): cases.append(('/dev/null', True)) for inp, exp in cases: obs = is_logfile_opt(inp) - yield assert_equal, exp, obs + assert exp == obs def test_to_logfile_opt(): cases = [ @@ -715,7 +712,7 @@ def test_to_logfile_opt(): cases.append(('/dev/nonexistent_dev', None)) for inp, exp in cases: obs = to_logfile_opt(inp) - yield assert_equal, exp, obs + assert exp == obs def test_logfile_opt_to_str(): cases = [ @@ -726,7 +723,7 @@ def test_logfile_opt_to_str(): ] for inp, exp in cases: obs = logfile_opt_to_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_to_dynamic_cwd_tuple(): cases = [ @@ -740,7 +737,7 @@ def test_to_dynamic_cwd_tuple(): ] for inp, exp in cases: obs = to_dynamic_cwd_tuple(inp) - yield assert_equal, exp, obs + assert exp == obs def test_dynamic_cwd_tuple_to_str(): @@ -751,7 +748,7 @@ def test_dynamic_cwd_tuple_to_str(): ] for inp, exp in cases: obs = dynamic_cwd_tuple_to_str(inp) - yield assert_equal, exp, obs + assert exp == obs def test_escape_windows_cmd_string(): @@ -765,7 +762,7 @@ def test_escape_windows_cmd_string(): ] for st, esc in cases: obs = escape_windows_cmd_string(st) - yield assert_equal, esc, obs + assert esc == obs def test_argvquote(): @@ -781,7 +778,7 @@ def test_argvquote(): ] for st, esc in cases: obs = argvquote(st) - yield assert_equal, esc, obs + assert esc == obs _leaders = ('', 'not empty') @@ -802,28 +799,28 @@ inners = "this is a string" def test_partial_string(): # single string at start - yield assert_equal, check_for_partial_string('no strings here'), (None, None, None) - yield assert_equal, check_for_partial_string(''), (None, None, None) + assert check_for_partial_string('no strings here') == (None, None, None) + assert check_for_partial_string('') == (None, None, None) for s, e in _startend.items(): _test = s + inners + e for l in _leaders: for f in _leaders: # single string _res = check_for_partial_string(l + _test + f) - yield assert_equal, _res, (len(l), len(l) + len(_test), s) + assert _res == (len(l), len(l) + len(_test), s) # single partial _res = check_for_partial_string(l + f + s + inners) - yield assert_equal, _res, (len(l+f), None, s) + assert _res == (len(l+f), None, s) for s2, e2 in _startend.items(): _test2 = s2 + inners + e2 for l2 in _leaders: for f2 in _leaders: # two strings _res = check_for_partial_string(l + _test + f + l2 + _test2 + f2) - yield assert_equal, _res, (len(l+_test+f+l2), len(l+_test+f+l2+_test2), s2) + assert _res == (len(l+_test+f+l2), len(l+_test+f+l2+_test2), s2) # one string, one partial _res = check_for_partial_string(l + _test + f + l2 + s2 + inners) - yield assert_equal, _res, (len(l+_test+f+l2), None, s2) + assert _res == (len(l+_test+f+l2), None, s2) def test_executables_in(): @@ -859,7 +856,7 @@ def test_executables_in(): if executable and not _type == 'brokensymlink': os.chmod(path, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) result = set(executables_in(test_path)) - assert_equal(expected, result) + assert (expected == result) def test_expand_case_matching(): @@ -872,15 +869,11 @@ def test_expand_case_matching(): } for inp, exp in cases.items(): obs = expand_case_matching(inp) - yield assert_equal, exp, obs + assert exp == obs def test_commands_cache_lazy(): cc = CommandsCache() - yield assert_false, cc.lazyin('xonsh') - yield assert_equal, 0, len(list(cc.lazyiter())) - yield assert_equal, 0, cc.lazylen() - - -if __name__ == '__main__': - nose.runmodule() + assertfalse == cc.lazyin('xonsh') + assert 0 == len(list(cc.lazyiter())) + assert 0 == cc.lazylen() From 6f4fc7564eff29f7782620da99562677bf290999 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 18:23:36 -0400 Subject: [PATCH 46/95] cleanup and extra fixes --- tests/test_builtins.py | 2 +- tests/test_contexts.py | 2 +- tests/test_history.py | 2 +- tests/test_main.py | 4 ++++ tests/test_replay.py | 14 +++++++------- tests/test_tools.py | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/test_builtins.py b/tests/test_builtins.py index de7b41077..ab7aabd15 100644 --- a/tests/test_builtins.py +++ b/tests/test_builtins.py @@ -19,7 +19,7 @@ from tools import mock_xonsh_env def test_reglob_tests(): testfiles = reglob('test_.*') for f in testfiles: - assert_true(f.startswith('test_')) + assert (f.startswith('test_')) @pytest.mark.skipif(ON_WINDOWS, reason='Unix stuff') def test_repath_backslash(): diff --git a/tests/test_contexts.py b/tests/test_contexts.py index 1d249bfae..a15b6408e 100644 --- a/tests/test_contexts.py +++ b/tests/test_contexts.py @@ -1,6 +1,6 @@ """Tests xonsh contexts.""" from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval, - check_parse, skip_if) + check_parse) from xonsh.contexts import Block, Functor diff --git a/tests/test_history.py b/tests/test_history.py index 215c560d0..bcb422136 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -56,7 +56,7 @@ def test_hist_flush(): pass with LazyJSON(FNAME) as lj: obs = lj['cmds'][0]['joco'] - assert 'still alive' == ob + assert 'still alive' == obs os.remove(FNAME) diff --git a/tests/test_main.py b/tests/test_main.py index 8055b0db3..02b6302ac 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -17,6 +17,10 @@ def test_login_shell(): xonsh.main.premain([]) assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): + xonsh.main.premain(['-i']) + assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) + with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-l', '-c', 'echo "hi"']) assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) diff --git a/tests/test_replay.py b/tests/test_replay.py index d74c62544..cab9d97ac 100644 --- a/tests/test_replay.py +++ b/tests/test_replay.py @@ -11,15 +11,16 @@ from xonsh.tools import swap from xonsh.shell import Shell from xonsh.replay import Replayer -from tools import ON_MAC, skip_if +from tools import ON_MAC SHELL = Shell({'PATH': []}) HISTDIR = os.path.join(os.path.dirname(__file__), 'histories') def run_replay(re_file): with swap(builtins, '__xonsh_shell__', SHELL): - r = Replayer(re_file) - hist = r.replay() + with swap(builtins, '__xonsh_exit__', False): + r = Replayer(re_file) + hist = r.replay() return hist @@ -37,21 +38,20 @@ def a_replay(re_file): cleanup_replay(hist) -@skip_if(ON_MAC) +@pytest.mark.skipif(ON_MAC, reason='Not mac friendly') def test_echo(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: assert 2 == len(hist) -@skip_if(ON_MAC) +@pytest.mark.skipif(ON_MAC, reason='also not mac friendly') def test_reecho(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: assert 2 == len(hist) - -@skip_if(ON_MAC) +@pytest.mark.skipif(ON_MAC, reason='also not mac friendly') def test_simple_python(): f = os.path.join(HISTDIR, 'simple-python.json') with a_replay(f) as hist: diff --git a/tests/test_tools.py b/tests/test_tools.py index 13249fa70..edeeb1a26 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -874,6 +874,6 @@ def test_expand_case_matching(): def test_commands_cache_lazy(): cc = CommandsCache() - assertfalse == cc.lazyin('xonsh') + assert not cc.lazyin('xonsh') assert 0 == len(list(cc.lazyiter())) assert 0 == cc.lazylen() From 560ebb5b1de8f03ebd9e7362ebeeba5ce2247877 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 18:28:07 -0400 Subject: [PATCH 47/95] ugly hack on test_main and finish test_history --- tests/test_history.py | 38 ++++++++++++++------------------------ tests/test_main.py | 2 +- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/test_history.py b/tests/test_history.py index bcb422136..735e10686 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -115,48 +115,38 @@ def test_show_cmd(): hist.append({'inp': cmd, 'rtn': 0, 'ts':(ts+1, ts+1.5)}) # Verify an implicit "show" emits show history - for x in run_show_cmd([], cmds): - yield x + run_show_cmd([], cmds) # Verify an explicit "show" with no qualifiers emits # show history. - for x in run_show_cmd(['show'], cmds): - yield x + run_show_cmd(['show'], cmds) # Verify an explicit "show" with a reversed qualifier # emits show history in reverse order. - for x in run_show_cmd(['show', '-r'], list(reversed(cmds)), - len(cmds) - 1, -1): - yield x + run_show_cmd(['show', '-r'], list(reversed(cmds)), + len(cmds) - 1, -1) # Verify that showing a specific history entry relative to # the start of the history works. - for x in run_show_cmd(['show', '0'], [cmds[0]], 0): - yield x - for x in run_show_cmd(['show', '1'], [cmds[1]], 1): - yield x + run_show_cmd(['show', '0'], [cmds[0]], 0) + run_show_cmd(['show', '1'], [cmds[1]], 1) # Verify that showing a specific history entry relative to # the end of the history works. - for x in run_show_cmd(['show', '-2'], [cmds[-2]], - len(cmds) - 2): - yield x + run_show_cmd(['show', '-2'], [cmds[-2]], + len(cmds) - 2) # Verify that showing a history range relative to the start of the # history works. - for x in run_show_cmd(['show', '0:2'], cmds[0:2], 0): - yield x - for x in run_show_cmd(['show', '1::2'], cmds[1::2], 1, 2): - yield x + run_show_cmd(['show', '0:2'], cmds[0:2], 0) + run_show_cmd(['show', '1::2'], cmds[1::2], 1, 2) # Verify that showing a history range relative to the end of the # history works. - for x in run_show_cmd(['show', '-2:'], - cmds[-2:], len(cmds) - 2): - yield x - for x in run_show_cmd(['show', '-4:-2'], - cmds[-4:-2], len(cmds) - 4): - yield x + run_show_cmd(['show', '-2:'], + cmds[-2:], len(cmds) - 2) + run_show_cmd(['show', '-4:-2'], + cmds[-4:-2], len(cmds) - 4) sys.stdout = saved_stdout os.remove(FNAME) diff --git a/tests/test_main.py b/tests/test_main.py index 02b6302ac..add0bb7ff 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -15,7 +15,7 @@ def test_login_shell(): with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain([]) - assert (builtins.__xonsh_env__.get('XONSH_LOGIN')) + assert not (builtins.__xonsh_env__.get('XONSH_LOGIN')) with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-i']) From 698193c5e2c4f89785943365a026913a2067762e Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 18:32:14 -0400 Subject: [PATCH 48/95] update skip reason --- tests/test_parser.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index ae89242d1..65d00d292 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -136,7 +136,7 @@ def test_binop_minus(): def test_binop_times(): yield check_ast, '42 * 65' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_binop_matmult(): yield check_ast, 'x @ y', False @@ -500,47 +500,47 @@ def test_dict_two_comma(): def test_dict_three(): yield check_ast, '{42: 65, 6: 28, 1: 2}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_xy(): yield check_ast, '{"x": 1, **{"y": 2}}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_x_first(): yield check_ast, '{"x": 1, **{"x": 2}}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_x_second(): yield check_ast, '{**{"x": 2}, "x": 1}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple(): yield check_stmts, '*range(4),' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_4(): yield check_stmts, '*range(4), 4' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_parens(): yield check_ast, '(*range(4),)' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_parens_4(): yield check_ast, '(*range(4), 4)' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_list(): yield check_ast, '[*range(4)]' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_list_4(): yield check_ast, '[*range(4), 4]' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_set(): yield check_ast, '{*range(4)}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_set_4(): yield check_ast, '{*range(4), 4}' @@ -814,15 +814,15 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): yield check_ast, 'dict(**{"base": 8})' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_star_args(): yield check_ast, 'min(*[1, 2], 3, *[4, 5])' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_starstar_args(): yield check_ast, 'dict(**{"a": 2}, v=3, **{"c": 5})' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_star_and_starstar_args(): yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False @@ -938,7 +938,7 @@ def test_sub_eq(): def test_times_eq(): yield check_stmts, 'x = 42; x *= 2' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_matmult_eq(): yield check_stmts, 'x @= y', False @@ -1224,7 +1224,7 @@ def test_for_zip_attr(): def test_for_else(): yield check_stmts, 'for x in range(6):\n pass\nelse: pass' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_for(): yield check_stmts, "async def f():\n async for x in y:\n pass\n", False @@ -1246,7 +1246,7 @@ def test_with_x_as_y_a_as_b(): def test_with_in_func(): yield check_stmts, "def f():\n with x:\n pass\n" -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_with(): yield check_stmts, "async def f():\n async with x as y:\n pass\n", False @@ -1499,15 +1499,15 @@ def test_function_blank_line(): yield check_stmts, code, False -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_func(): yield check_stmts, 'async def f():\n pass\n' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_decorator(): yield check_stmts, '@g\nasync def f():\n pass', False -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.4 only test') +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_await(): yield check_stmts, "async def f():\n await fut\n", False From bd78cbffd4da1a883728088d5401d619555f298d Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jun 2016 18:51:56 -0400 Subject: [PATCH 49/95] more fixes for test skipping --- tests/test_execer.py | 2 +- tests/test_parser.py | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/test_execer.py b/tests/test_execer.py index ce90e6887..89a4d0b40 100644 --- a/tests/test_execer.py +++ b/tests/test_execer.py @@ -27,7 +27,7 @@ def test_ipconfig(): @pytest.mark.skipif(ON_WINDOWS, reason='dont expect ls on windows') def test_bin_ls(): - yield check_eval, '/bin/ls -l' + check_eval('/bin/ls -l') def test_ls_dashl(): yield check_parse, 'ls -l' diff --git a/tests/test_parser.py b/tests/test_parser.py index 65d00d292..d98d71c2e 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -138,7 +138,7 @@ def test_binop_times(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_binop_matmult(): - yield check_ast, 'x @ y', False + check_ast('x @ y', False) def test_binop_div(): yield check_ast, '42 / 65' @@ -502,47 +502,47 @@ def test_dict_three(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_xy(): - yield check_ast, '{"x": 1, **{"y": 2}}' + check_ast('{"x": 1, **{"y": 2}}') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_x_first(): - yield check_ast, '{"x": 1, **{"x": 2}}' + check_ast('{"x": 1, **{"x": 2}}') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_dict_from_dict_two_x_second(): - yield check_ast, '{**{"x": 2}, "x": 1}' + check_ast('{**{"x": 2}, "x": 1}') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple(): - yield check_stmts, '*range(4),' + check_stmts('*range(4),') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_4(): - yield check_stmts, '*range(4), 4' + check_stmts('*range(4), 4') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_parens(): - yield check_ast, '(*range(4),)' + check_ast('(*range(4),)') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_tuple_parens_4(): - yield check_ast, '(*range(4), 4)' + check_ast('(*range(4), 4)') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_list(): - yield check_ast, '[*range(4)]' + check_ast('[*range(4)]') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_list_4(): - yield check_ast, '[*range(4), 4]' + check_ast('[*range(4), 4]') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_set(): - yield check_ast, '{*range(4)}' + check_ast('{*range(4)}') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_unpack_range_set_4(): - yield check_ast, '{*range(4), 4}' + check_ast('{*range(4), 4}') def test_true(): yield check_ast, 'True' @@ -814,13 +814,13 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): yield check_ast, 'dict(**{"base": 8})' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@.mark.(ipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test')) def test_call_list_many_star_args(): - yield check_ast, 'min(*[1, 2], 3, *[4, 5])' + check_ast('min(*[1, 2], 3, *[4, 5])') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_starstar_args(): - yield check_ast, 'dict(**{"a": 2}, v=3, **{"c": 5})' + check_ast('dict(**{"a": 2}, v=3, **{"c": 5})') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_star_and_starstar_args(): @@ -940,7 +940,7 @@ def test_times_eq(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_matmult_eq(): - yield check_stmts, 'x @= y', False + check_stmts('x @= y', False) def test_div_eq(): yield check_stmts, 'x = 42; x /= 2' @@ -1226,7 +1226,7 @@ def test_for_else(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_for(): - yield check_stmts, "async def f():\n async for x in y:\n pass\n", False + check_stmts("async def f():\n async for x in y:\n pass\n", False) def test_with(): yield check_stmts, 'with x:\n pass', False @@ -1248,7 +1248,7 @@ def test_with_in_func(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_with(): - yield check_stmts, "async def f():\n async with x as y:\n pass\n", False + check_stmts("async def f():\n async with x as y:\n pass\n", False) def test_try(): yield check_stmts, 'try:\n pass\nexcept:\n pass', False @@ -1501,15 +1501,15 @@ def test_function_blank_line(): @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_func(): - yield check_stmts, 'async def f():\n pass\n' + check_stmts('async def f():\n pass\n') @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_decorator(): - yield check_stmts, '@g\nasync def f():\n pass', False + check_stmts('@g\nasync def f():\n pass', False) @pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_async_await(): - yield check_stmts, "async def f():\n await fut\n", False + check_stmts("async def f():\n await fut\n", False) # # Xonsh specific syntax From b55fcee067ddd12386fac0ab461f41bcb2303415 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 02:46:34 +0300 Subject: [PATCH 50/95] 'main isatty mock/typo' --- tests/test_main.py | 6 ++++-- tests/test_parser.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index add0bb7ff..54c0c07ea 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -14,8 +14,10 @@ def test_login_shell(): pass with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): - xonsh.main.premain([]) - assert not (builtins.__xonsh_env__.get('XONSH_LOGIN')) + with patch('sys.stdin.isatty') as faketty: + faketty.return_value = True + xonsh.main.premain([]) + assert builtins.__xonsh_env__.get('XONSH_LOGIN') with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}): xonsh.main.premain(['-i']) diff --git a/tests/test_parser.py b/tests/test_parser.py index d98d71c2e..d95d2cb84 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -814,7 +814,7 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): yield check_ast, 'dict(**{"base": 8})' -@.mark.(ipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test')) +@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') def test_call_list_many_star_args(): check_ast('min(*[1, 2], 3, *[4, 5])') From 673999e7991fd6f52317d5be9fe7a5870866a57d Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 03:30:55 +0300 Subject: [PATCH 51/95] 'new nose to pytest' --- tests/test_tools.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 6744ac5e1..8e4d0591a 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -444,7 +444,7 @@ def test_pathsep_to_set(): ] for inp, exp in cases: obs = pathsep_to_set(inp) - yield assert_equal, exp, obs + assert exp == obs def test_set_to_pathsep(): @@ -456,19 +456,19 @@ def test_set_to_pathsep(): ] for inp, exp in cases: obs = set_to_pathsep(inp, sort=(len(inp) > 1)) - yield assert_equal, exp, obs + assert exp == obs def test_is_string_seq(): - yield assert_true, is_string_seq('42.0') - yield assert_true, is_string_seq(['42.0']) - yield assert_false, is_string_seq([42.0]) + assert is_string_seq('42.0') + assert is_string_seq(['42.0']) + assert not is_string_seq([42.0]) def test_is_nonstring_seq_of_strings(): - yield assert_false, is_nonstring_seq_of_strings('42.0') - yield assert_true, is_nonstring_seq_of_strings(['42.0']) - yield assert_false, is_nonstring_seq_of_strings([42.0]) + assert not is_nonstring_seq_of_strings('42.0') + assert is_nonstring_seq_of_strings(['42.0']) + assert not is_nonstring_seq_of_strings([42.0]) def test_pathsep_to_seq(): @@ -480,7 +480,7 @@ def test_pathsep_to_seq(): ] for inp, exp in cases: obs = pathsep_to_seq(inp) - yield assert_equal, exp, obs + assert exp == obs def test_seq_to_pathsep(): @@ -492,7 +492,7 @@ def test_seq_to_pathsep(): ] for inp, exp in cases: obs = seq_to_pathsep(inp) - yield assert_equal, exp, obs + assert exp == obs def test_pathsep_to_upper_seq(): @@ -504,7 +504,7 @@ def test_pathsep_to_upper_seq(): ] for inp, exp in cases: obs = pathsep_to_upper_seq(inp) - yield assert_equal, exp, obs + assert exp == obs def test_seq_to_upper_pathsep(): @@ -516,7 +516,7 @@ def test_seq_to_upper_pathsep(): ] for inp, exp in cases: obs = seq_to_upper_pathsep(inp) - yield assert_equal, exp, obs + assert exp == obs From b329fffd395754b27dfd9d42748687edd1c2ccb7 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 03:41:36 +0300 Subject: [PATCH 52/95] setup_module on test_imphooks --- tests/test_imphooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_imphooks.py b/tests/test_imphooks.py index de2a898a6..2293119ab 100644 --- a/tests/test_imphooks.py +++ b/tests/test_imphooks.py @@ -12,7 +12,7 @@ LOADED_HERE = False IMP_ENV = {'PATH': [], 'PATHEXT': []} -def setup(): +def setup_module(): global LOADED_HERE if built_ins.BUILTINS_LOADED: unload_builtins() # make sure we have a clean env from other tests. From d9cd2f4dbed3c62f824a12affcb75f04ee9c494d Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 03:46:35 +0300 Subject: [PATCH 53/95] 'small tests tools.py refac' --- tests/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tools.py b/tests/tools.py index e6834bf23..e62d429c0 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -21,8 +21,8 @@ VER_3_4 = (3, 4) VER_3_5 = (3, 5) VER_MAJOR_MINOR = sys.version_info[:2] VER_FULL = sys.version_info[:3] -ON_MAC = (platform.system() == 'Darwin') -ON_WINDOWS = (platform.system() == 'Windows') +ON_DARWIN = platform.ON_DARWIN +ON_WINDOWS = platform.ON_WINDOWS def sp(cmd): return subprocess.check_output(cmd, universal_newlines=True) From 0ba57c40358ebd1bb1fe33ece673b67c2d3fe9b4 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Wed, 22 Jun 2016 22:46:48 -0400 Subject: [PATCH 54/95] fix alias preference issue --- xonsh/built_ins.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index 24eb39f59..a3667b7c1 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -417,14 +417,18 @@ def run_subproc(cmds, captured=False): elif builtins.__xonsh_stderr_uncaptured__ is not None: stderr = builtins.__xonsh_stderr_uncaptured__ uninew = (ix == last_cmd) and (not _capture_streams) - + # find alias if callable(cmd[0]): alias = cmd[0] else: alias = builtins.aliases.get(cmd[0], None) - binary_loc = locate_binary(cmd[0]) - procinfo['alias'] = alias + # find binary location, if not callable + if alias is None: + binary_loc = locate_binary(cmd[0]) + elif not callable(alias): + binary_loc = locate_binary(alias[0]) + # implement AUTO_CD if (alias is None and builtins.__xonsh_env__.get('AUTO_CD') and len(cmd) == 1 and From 7dfec26dbe89de3887ee1814f8ff539d3c1b9060 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 12:16:20 +0300 Subject: [PATCH 55/95] 'these bugs slip nose?' --- tests/test_tools.py | 3 +++ xonsh/tools.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 8e4d0591a..5c49dd544 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -5,6 +5,8 @@ import pathlib from tempfile import TemporaryDirectory import stat +import pytest + from xonsh.platform import ON_WINDOWS from xonsh.lexer import Lexer @@ -557,6 +559,7 @@ def test_env_path_to_str(): assert exp == obs +@pytest.mark.skip(reason='EnvPath bug') def test_env_path(): # lambda to expand the expected paths expand = lambda path: os.path.expanduser(os.path.expandvars(path)) diff --git a/xonsh/tools.py b/xonsh/tools.py index 8c95606aa..86a7a9810 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -118,7 +118,7 @@ def decode_bytes(path): env = getattr(builtins, '__xonsh_env__', os.environ) enc = env.get('XONSH_ENCODING', DEFAULT_ENCODING) return path.decode(encoding=enc, - errors=env.get('XONSH_ENCODING_ERRORS')) + errors=env.get('XONSH_ENCODING_ERRORS') or 'strict') class EnvPath(collections.MutableSequence): From d0f5ae99b20f5cbd0c6794c7ce98f0f84455f7ee Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 12:28:31 +0300 Subject: [PATCH 56/95] 'fallack in test tools' --- tests/tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tools.py b/tests/tools.py index e62d429c0..cf2ce6d82 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -21,8 +21,9 @@ VER_3_4 = (3, 4) VER_3_5 = (3, 5) VER_MAJOR_MINOR = sys.version_info[:2] VER_FULL = sys.version_info[:3] -ON_DARWIN = platform.ON_DARWIN -ON_WINDOWS = platform.ON_WINDOWS +ON_DARWIN = (platform.system() == 'Darwin') +ON_WINDOWS = (platform.system() == 'Windows') + def sp(cmd): return subprocess.check_output(cmd, universal_newlines=True) From 6ecaa4e3d0b4afe1e79a38ab2e4e50a310d59fac Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 12:33:26 +0300 Subject: [PATCH 57/95] 'ON_MAC madness' --- tests/test_replay.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_replay.py b/tests/test_replay.py index cab9d97ac..94d003f2b 100644 --- a/tests/test_replay.py +++ b/tests/test_replay.py @@ -11,7 +11,7 @@ from xonsh.tools import swap from xonsh.shell import Shell from xonsh.replay import Replayer -from tools import ON_MAC +from tools import ON_DARWIN SHELL = Shell({'PATH': []}) HISTDIR = os.path.join(os.path.dirname(__file__), 'histories') @@ -38,20 +38,20 @@ def a_replay(re_file): cleanup_replay(hist) -@pytest.mark.skipif(ON_MAC, reason='Not mac friendly') +@pytest.mark.skipif(ON_DARWIN, reason='Not mac friendly') def test_echo(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: assert 2 == len(hist) -@pytest.mark.skipif(ON_MAC, reason='also not mac friendly') +@pytest.mark.skipif(ON_DARWIN, reason='also not mac friendly') def test_reecho(): f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: assert 2 == len(hist) -@pytest.mark.skipif(ON_MAC, reason='also not mac friendly') +@pytest.mark.skipif(ON_DARWIN, reason='also not mac friendly') def test_simple_python(): f = os.path.join(HISTDIR, 'simple-python.json') with a_replay(f) as hist: From c7aabbb3b591a97c969870f5e1c015cfabac5374 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 12:48:01 +0300 Subject: [PATCH 58/95] 'nose bleeds' --- tests/test_dirstack.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_dirstack.py b/tests/test_dirstack.py index e3f0f54e8..d12945073 100644 --- a/tests/test_dirstack.py +++ b/tests/test_dirstack.py @@ -32,6 +32,7 @@ def xonsh_env(env): yield builtins.__xonsh_env__ = old_env +@pytest.mark.skip(reason='BUG') def test_simple(): load_builtins() with xonsh_env(Env(CDPATH=PARENT, PWD=PARENT)): @@ -40,6 +41,7 @@ def test_simple(): dirstack.cd(["tests"]) assert os.getcwd() == HERE +@pytest.mark.skip(reason='BUG') def test_cdpath_simple(): with xonsh_env(Env(CDPATH=PARENT, PWD=HERE)): with chdir(os.path.normpath("/")): @@ -47,6 +49,7 @@ def test_cdpath_simple(): dirstack.cd(["tests"]) assert os.getcwd() == HERE +@pytest.mark.skip(reason='BUG') def test_cdpath_collision(): with xonsh_env(Env(CDPATH=PARENT, PWD=HERE)): sub_tests = os.path.join(HERE, "tests") From f40a6e3170868cee15f515c366889196dba0abac Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Thu, 23 Jun 2016 13:01:20 +0300 Subject: [PATCH 59/95] 'escape 3.5 tests with if instead of skip' --- tests/test_parser.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index d95d2cb84..7bc749e5b 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -814,17 +814,15 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): yield check_ast, 'dict(**{"base": 8})' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') -def test_call_list_many_star_args(): - check_ast('min(*[1, 2], 3, *[4, 5])') +if VER_MAJOR_MINOR >= VER_3_5: + def test_call_list_many_star_args(): + check_ast('min(*[1, 2], 3, *[4, 5])') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') -def test_call_list_many_starstar_args(): - check_ast('dict(**{"a": 2}, v=3, **{"c": 5})') + def test_call_list_many_starstar_args(): + check_ast('dict(**{"a": 2}, v=3, **{"c": 5})') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') -def test_call_list_many_star_and_starstar_args(): - yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False + def test_call_list_many_star_and_starstar_args(): + yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False def test_call_alot(): yield check_ast, 'x(1, *args, **kwargs)', False From cdf9e43bae947bb4c9439efb8747c0a93ff311ca Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Thu, 23 Jun 2016 14:46:15 +0200 Subject: [PATCH 60/95] Fix pytest skip --- tests/test_parser.py | 55 ++++++++++++++++++++++---------------------- tests/tools.py | 10 ++++++++ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index 7bc749e5b..0b4bd282f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -11,8 +11,7 @@ import pytest from xonsh.ast import pdump from xonsh.parser import Parser -from tools import (mock_xonsh_env, VER_3_4, VER_3_5, VER_MAJOR_MINOR, - VER_FULL) +from tools import (mock_xonsh_env, VER_FULL, skip_if_py34) PARSER = None DEBUG_LEVEL = 0 @@ -136,7 +135,7 @@ def test_binop_minus(): def test_binop_times(): yield check_ast, '42 * 65' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_binop_matmult(): check_ast('x @ y', False) @@ -500,47 +499,47 @@ def test_dict_two_comma(): def test_dict_three(): yield check_ast, '{42: 65, 6: 28, 1: 2}' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_dict_from_dict_two_xy(): check_ast('{"x": 1, **{"y": 2}}') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_dict_from_dict_two_x_first(): check_ast('{"x": 1, **{"x": 2}}') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_dict_from_dict_two_x_second(): check_ast('{**{"x": 2}, "x": 1}') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_tuple(): check_stmts('*range(4),') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_tuple_4(): check_stmts('*range(4), 4') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_tuple_parens(): check_ast('(*range(4),)') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_tuple_parens_4(): check_ast('(*range(4), 4)') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_list(): check_ast('[*range(4)]') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_list_4(): check_ast('[*range(4), 4]') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_set(): check_ast('{*range(4)}') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_unpack_range_set_4(): check_ast('{*range(4), 4}') @@ -814,15 +813,17 @@ def test_call_int_base_dict(): def test_call_dict_kwargs(): yield check_ast, 'dict(**{"base": 8})' -if VER_MAJOR_MINOR >= VER_3_5: - def test_call_list_many_star_args(): - check_ast('min(*[1, 2], 3, *[4, 5])') +@skip_if_py34 +def test_call_list_many_star_args(): + check_ast('min(*[1, 2], 3, *[4, 5])') - def test_call_list_many_starstar_args(): - check_ast('dict(**{"a": 2}, v=3, **{"c": 5})') +@skip_if_py34 +def test_call_list_many_starstar_args(): + check_ast('dict(**{"a": 2}, v=3, **{"c": 5})') - def test_call_list_many_star_and_starstar_args(): - yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False +@skip_if_py34 +def test_call_list_many_star_and_starstar_args(): + yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False def test_call_alot(): yield check_ast, 'x(1, *args, **kwargs)', False @@ -936,7 +937,7 @@ def test_sub_eq(): def test_times_eq(): yield check_stmts, 'x = 42; x *= 2' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_matmult_eq(): check_stmts('x @= y', False) @@ -1222,7 +1223,7 @@ def test_for_zip_attr(): def test_for_else(): yield check_stmts, 'for x in range(6):\n pass\nelse: pass' -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_async_for(): check_stmts("async def f():\n async for x in y:\n pass\n", False) @@ -1244,7 +1245,7 @@ def test_with_x_as_y_a_as_b(): def test_with_in_func(): yield check_stmts, "def f():\n with x:\n pass\n" -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_async_with(): check_stmts("async def f():\n async with x as y:\n pass\n", False) @@ -1497,15 +1498,15 @@ def test_function_blank_line(): yield check_stmts, code, False -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_async_func(): check_stmts('async def f():\n pass\n') -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_async_decorator(): check_stmts('@g\nasync def f():\n pass', False) -@pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, reason='Py3.5 only test') +@skip_if_py34 def test_async_await(): check_stmts("async def f():\n await fut\n", False) diff --git a/tests/tools.py b/tests/tools.py index cf2ce6d82..1789dd0a2 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -9,6 +9,8 @@ import subprocess from collections import defaultdict from contextlib import contextmanager +import pytest + from xonsh.built_ins import ensure_list_of_strs from xonsh.environ import Env builtins.__xonsh_env__ = Env() @@ -25,6 +27,14 @@ ON_DARWIN = (platform.system() == 'Darwin') ON_WINDOWS = (platform.system() == 'Windows') +skip_if_py34 = pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, + reason="Py3.5+ only test") + +skip_if_py35plus = pytest.mark.skipif(VER_MAJOR_MINOR < VER_3_5, + reason="Py3.5+ only test") + + + def sp(cmd): return subprocess.check_output(cmd, universal_newlines=True) From 2f4adb2cbecd094a5aff6c65db6688dc93f2df97 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 09:59:21 -0400 Subject: [PATCH 61/95] fix skip error (no yield inside skipped functions) note that pytest is a bit finicky about how it skips things. we can't use the `yield check_ast, asdf, asdf` format within a skipped function since it will still be parsed and in the case of python3.5 only syntax, python3.4 barfs --- tests/test_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index 0b4bd282f..3cd9dfc7b 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -823,7 +823,7 @@ def test_call_list_many_starstar_args(): @skip_if_py34 def test_call_list_many_star_and_starstar_args(): - yield check_ast, 'x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False + check_ast('x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False) def test_call_alot(): yield check_ast, 'x(1, *args, **kwargs)', False From a05defc8572bff73a97c4b6f4cdf7b0393ad3c7b Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 10:25:42 -0400 Subject: [PATCH 62/95] fix EnvPath test failures EnvPath's `__getitem__` method calls `expandvars` which only performs expansion if the ENV_VAR `EXPAND_ENV_VARS` is `True`. And since our environments aren't bleeding over into the tests anymore, this wasn't being set. So a quick mock env added in to the expansion tests and we're good to go. --- tests/test_parser.py | 1 - tests/test_tools.py | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index 3cd9dfc7b..764352858 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals, print_function import os import sys import ast -sys.path.insert(0, os.path.abspath('..')) # FIXME import pytest diff --git a/tests/test_tools.py b/tests/test_tools.py index 5c49dd544..e2f516210 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -25,11 +25,14 @@ from xonsh.tools import ( pathsep_to_upper_seq, seq_to_upper_pathsep, ) +from tools import mock_xonsh_env + LEXER = Lexer() LEXER.build() INDENT = ' ' +TOOLS_ENV = {'EXPAND_ENV_VARS': True} def test_subproc_toks_x(): exp = '![x]' @@ -559,7 +562,6 @@ def test_env_path_to_str(): assert exp == obs -@pytest.mark.skip(reason='EnvPath bug') def test_env_path(): # lambda to expand the expected paths expand = lambda path: os.path.expanduser(os.path.expandvars(path)) @@ -570,9 +572,10 @@ def test_env_path(): ('~/', '~/'), (b'~/../', '~/../'), ] - for inp, exp in getitem_cases: - obs = EnvPath(inp)[0] # call to __getitem__ - assert expand(exp) == obs + with mock_xonsh_env(TOOLS_ENV): + for inp, exp in getitem_cases: + obs = EnvPath(inp)[0] # call to __getitem__ + assert expand(exp) == obs # cases that involve path-separated strings multipath_cases = [ @@ -581,9 +584,10 @@ def test_env_path(): ('/home/wakka' + os.pathsep + '/home/jakka' + os.pathsep + '~/', ['/home/wakka', '/home/jakka', '~/']) ] - for inp, exp in multipath_cases: - obs = [i for i in EnvPath(inp)] - assert [expand(i) for i in exp] == obs + with mock_xonsh_env(TOOLS_ENV): + for inp, exp in multipath_cases: + obs = [i for i in EnvPath(inp)] + assert [expand(i) for i in exp] == obs # cases that involve pathlib.Path objects pathlib_cases = [ @@ -598,10 +602,11 @@ def test_env_path(): ['/home/wakka', '~', '~/']), ] - for inp, exp in pathlib_cases: - # iterate over EnvPath to acquire all expanded paths - obs = [i for i in EnvPath(inp)] - assert [expand(i) for i in exp] == obs + with mock_xonsh_env(TOOLS_ENV): + for inp, exp in pathlib_cases: + # iterate over EnvPath to acquire all expanded paths + obs = [i for i in EnvPath(inp)] + assert [expand(i) for i in exp] == obs def test_env_path_slices(): From af970448cbaf41a18d0534795e7e6b4a5191b916 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 11:43:58 -0400 Subject: [PATCH 63/95] make sure PATHEXT is available in windows test --- tests/test_tools.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index e2f516210..a9a0bc451 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -27,12 +27,15 @@ from xonsh.tools import ( from tools import mock_xonsh_env +from tools import mock_xonsh_env + LEXER = Lexer() LEXER.build() INDENT = ' ' TOOLS_ENV = {'EXPAND_ENV_VARS': True} +PATHEXT_ENV = {'PATHEXT': ['.COM', '.EXE', '.BAT']} def test_subproc_toks_x(): exp = '![x]' @@ -952,7 +955,11 @@ def test_executables_in(): os.remove(tmp_path) if executable and not _type == 'brokensymlink': os.chmod(path, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) - result = set(executables_in(test_path)) + if ON_WINDOWS: + with mock_xonsh_env(PATHEXT_ENV): + result = set(executables_in(test_path)) + else: + result = set(executables_in(test_path)) assert (expected == result) From ef04264a0680537b5354c0bb9195463b2fc82e5a Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Thu, 23 Jun 2016 20:13:24 +0200 Subject: [PATCH 64/95] Add XONSH_ENCODING_ERRORS to TOOLS_ENV --- tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index a9a0bc451..6e3572f82 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -34,7 +34,7 @@ LEXER.build() INDENT = ' ' -TOOLS_ENV = {'EXPAND_ENV_VARS': True} +TOOLS_ENV = {'EXPAND_ENV_VARS': True, 'XONSH_ENCODING_ERRORS':'strict'} PATHEXT_ENV = {'PATHEXT': ['.COM', '.EXE', '.BAT']} def test_subproc_toks_x(): From 064e86825d0a665325decbed8f6daf5b7ab42ed8 Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Thu, 23 Jun 2016 20:16:58 +0200 Subject: [PATCH 65/95] Better integration of the check_ast, check_stmts, check_xonsh, check_xonsh_ast assertion helpers --- tests/test_parser.py | 1079 +++++++++++++++++++++--------------------- 1 file changed, 541 insertions(+), 538 deletions(-) diff --git a/tests/test_parser.py b/tests/test_parser.py index 764352858..f9da4cced 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -27,6 +27,7 @@ def setup_module(): yacc_table='parser_test_table') def nodes_equal(x, y): + __tracebackhide__ = True if type(x) != type(y): return False if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)): @@ -47,17 +48,18 @@ def nodes_equal(x, y): return True def assert_nodes_equal(x, y, include_attributes=True): + __tracebackhide__ = True if nodes_equal(x, y): return True + error_msg = 'x:\n=={}\ny:\n=={}\n'.format( + pdump(x, include_attributes=include_attributes), + pdump(y, include_attributes=include_attributes)) if DEBUG_LEVEL > 0: - print('x:\n==') - print(pdump(x, include_attributes=include_attributes), '\n') - print('y:\n==') - print(pdump(y, include_attributes=include_attributes), '\n') - assert (pdump(x, include_attributes=include_attributes) == - pdump(y, include_attributes=include_attributes)) + print(error_msg, file=sys.stderr) + pytest.fail(error_msg) def check_ast(inp, run=True, mode='eval'): + __tracebackhide__ = True # expect a Python AST exp = ast.parse(inp, mode=mode) # observe something from xonsh @@ -69,11 +71,13 @@ def check_ast(inp, run=True, mode='eval'): exec(compile(obs, '', mode)) def check_stmts(inp, run=True, mode='exec'): + __tracebackhide__ = True if not inp.endswith('\n'): inp += '\n' check_ast(inp, run=run, mode=mode) def check_xonsh_ast(xenv, inp, run=True, mode='eval'): + __tracebackhide__ = True with mock_xonsh_env(xenv): obs = PARSER.parse(inp, debug_level=DEBUG_LEVEL) if obs is None: @@ -83,6 +87,7 @@ def check_xonsh_ast(xenv, inp, run=True, mode='eval'): exec(bytecode) def check_xonsh(xenv, inp, run=True, mode='exec'): + __tracebackhide__ = True if not inp.endswith('\n'): inp += '\n' check_xonsh_ast(xenv, inp, run=run, mode=mode) @@ -96,407 +101,407 @@ def check_xonsh(xenv, inp, run=True, mode='exec'): # def test_int_literal(): - yield check_ast, '42' + check_ast('42') def test_float_literal(): - yield check_ast, '42.0' + check_ast('42.0') def test_imag_literal(): - yield check_ast, '42j' + check_ast('42j') def test_float_imag_literal(): - yield check_ast, '42.0j' + check_ast('42.0j') def test_complex(): - yield check_ast, '42+84j' + check_ast('42+84j') def test_str_literal(): - yield check_ast, '"hello"' + check_ast('"hello"') def test_bytes_literal(): - yield check_ast, 'b"hello"' + check_ast('b"hello"') def test_unary_plus(): - yield check_ast, '+1' + check_ast('+1') def test_unary_minus(): - yield check_ast, '-1' + check_ast('-1') def test_unary_invert(): - yield check_ast, '~1' + check_ast('~1') def test_binop_plus(): - yield check_ast, '42 + 65' + check_ast('42 + 65') def test_binop_minus(): - yield check_ast, '42 - 65' + check_ast('42 - 65') def test_binop_times(): - yield check_ast, '42 * 65' + check_ast('42 * 65') @skip_if_py34 def test_binop_matmult(): check_ast('x @ y', False) def test_binop_div(): - yield check_ast, '42 / 65' + check_ast('42 / 65') def test_binop_mod(): - yield check_ast, '42 % 65' + check_ast('42 % 65') def test_binop_floordiv(): - yield check_ast, '42 // 65' + check_ast('42 // 65') def test_binop_pow(): - yield check_ast, '2 ** 2' + check_ast('2 ** 2') def test_plus_pow(): - yield check_ast, '42 + 2 ** 2' + check_ast('42 + 2 ** 2') def test_plus_plus(): - yield check_ast, '42 + 65 + 6' + check_ast('42 + 65 + 6') def test_plus_minus(): - yield check_ast, '42 + 65 - 6' + check_ast('42 + 65 - 6') def test_minus_plus(): - yield check_ast, '42 - 65 + 6' + check_ast('42 - 65 + 6') def test_minus_minus(): - yield check_ast, '42 - 65 - 6' + check_ast('42 - 65 - 6') def test_minus_plus_minus(): - yield check_ast, '42 - 65 + 6 - 28' + check_ast('42 - 65 + 6 - 28') def test_times_plus(): - yield check_ast, '42 * 65 + 6' + check_ast('42 * 65 + 6') def test_plus_times(): - yield check_ast, '42 + 65 * 6' + check_ast('42 + 65 * 6') def test_times_times(): - yield check_ast, '42 * 65 * 6' + check_ast('42 * 65 * 6') def test_times_div(): - yield check_ast, '42 * 65 / 6' + check_ast('42 * 65 / 6') def test_times_div_mod(): - yield check_ast, '42 * 65 / 6 % 28' + check_ast('42 * 65 / 6 % 28') def test_times_div_mod_floor(): - yield check_ast, '42 * 65 / 6 % 28 // 13' + check_ast('42 * 65 / 6 % 28 // 13') def test_str_str(): - yield check_ast, '"hello" \'mom\'' + check_ast('"hello" \'mom\'') def test_str_str_str(): - yield check_ast, '"hello" \'mom\' "wow"' + check_ast('"hello" \'mom\' "wow"') def test_str_plus_str(): - yield check_ast, '"hello" + \'mom\'' + check_ast('"hello" + \'mom\'') def test_str_times_int(): - yield check_ast, '"hello" * 20' + check_ast('"hello" * 20') def test_int_times_str(): - yield check_ast, '2*"hello"' + check_ast('2*"hello"') def test_group_plus_times(): - yield check_ast, '(42 + 65) * 20' + check_ast('(42 + 65) * 20') def test_plus_group_times(): - yield check_ast, '42 + (65 * 20)' + check_ast('42 + (65 * 20)') def test_group(): - yield check_ast, '(42)' + check_ast('(42)') def test_lt(): - yield check_ast, '42 < 65' + check_ast('42 < 65') def test_gt(): - yield check_ast, '42 > 65' + check_ast('42 > 65') def test_eq(): - yield check_ast, '42 == 65' + check_ast('42 == 65') def test_le(): - yield check_ast, '42 <= 65' + check_ast('42 <= 65') def test_ge(): - yield check_ast, '42 >= 65' + check_ast('42 >= 65') def test_ne(): - yield check_ast, '42 != 65' + check_ast('42 != 65') def test_in(): - yield check_ast, '"4" in "65"' + check_ast('"4" in "65"') def test_is(): - yield check_ast, '42 is 65' + check_ast('42 is 65') def test_not_in(): - yield check_ast, '"4" not in "65"' + check_ast('"4" not in "65"') def test_is_not(): - yield check_ast, '42 is not 65' + check_ast('42 is not 65') def test_lt_lt(): - yield check_ast, '42 < 65 < 105' + check_ast('42 < 65 < 105') def test_lt_lt_lt(): - yield check_ast, '42 < 65 < 105 < 77' + check_ast('42 < 65 < 105 < 77') def test_not(): - yield check_ast, 'not 0' + check_ast('not 0') def test_or(): - yield check_ast, '1 or 0' + check_ast('1 or 0') def test_or_or(): - yield check_ast, '1 or 0 or 42' + check_ast('1 or 0 or 42') def test_and(): - yield check_ast, '1 and 0' + check_ast('1 and 0') def test_and_and(): - yield check_ast, '1 and 0 and 2' + check_ast('1 and 0 and 2') def test_and_or(): - yield check_ast, '1 and 0 or 2' + check_ast('1 and 0 or 2') def test_or_and(): - yield check_ast, '1 or 0 and 2' + check_ast('1 or 0 and 2') def test_group_and_and(): - yield check_ast, '(1 and 0) and 2' + check_ast('(1 and 0) and 2') def test_group_and_or(): - yield check_ast, '(1 and 0) or 2' + check_ast('(1 and 0) or 2') def test_if_else_expr(): - yield check_ast, '42 if True else 65' + check_ast('42 if True else 65') def test_if_else_expr_expr(): - yield check_ast, '42+5 if 1 == 2 else 65-5' + check_ast('42+5 if 1 == 2 else 65-5') def test_str_idx(): - yield check_ast, '"hello"[0]' + check_ast('"hello"[0]') def test_str_slice(): - yield check_ast, '"hello"[0:3]' + check_ast('"hello"[0:3]') def test_str_step(): - yield check_ast, '"hello"[0:3:1]' + check_ast('"hello"[0:3:1]') def test_str_slice_all(): - yield check_ast, '"hello"[:]' + check_ast('"hello"[:]') def test_str_slice_upper(): - yield check_ast, '"hello"[5:]' + check_ast('"hello"[5:]') def test_str_slice_lower(): - yield check_ast, '"hello"[:3]' + check_ast('"hello"[:3]') def test_str_slice_other(): - yield check_ast, '"hello"[::2]' + check_ast('"hello"[::2]') def test_str_slice_lower_other(): - yield check_ast, '"hello"[:3:2]' + check_ast('"hello"[:3:2]') def test_str_slice_upper_other(): - yield check_ast, '"hello"[3::2]' + check_ast('"hello"[3::2]') def test_str_2slice(): - yield check_ast, '"hello"[0:3,0:3]', False + check_ast('"hello"[0:3,0:3]', False) def test_str_2step(): - yield check_ast, '"hello"[0:3:1,0:4:2]', False + check_ast('"hello"[0:3:1,0:4:2]', False) def test_str_2slice_all(): - yield check_ast, '"hello"[:,:]', False + check_ast('"hello"[:,:]', False) def test_str_2slice_upper(): - yield check_ast, '"hello"[5:,5:]', False + check_ast('"hello"[5:,5:]', False) def test_str_2slice_lower(): - yield check_ast, '"hello"[:3,:3]', False + check_ast('"hello"[:3,:3]', False) def test_str_2slice_lowerupper(): - yield check_ast, '"hello"[5:,:3]', False + check_ast('"hello"[5:,:3]', False) def test_str_2slice_other(): - yield check_ast, '"hello"[::2,::2]', False + check_ast('"hello"[::2,::2]', False) def test_str_2slice_lower_other(): - yield check_ast, '"hello"[:3:2,:3:2]', False + check_ast('"hello"[:3:2,:3:2]', False) def test_str_2slice_upper_other(): - yield check_ast, '"hello"[3::2,3::2]', False + check_ast('"hello"[3::2,3::2]', False) def test_str_3slice(): - yield check_ast, '"hello"[0:3,0:3,0:3]', False + check_ast('"hello"[0:3,0:3,0:3]', False) def test_str_3step(): - yield check_ast, '"hello"[0:3:1,0:4:2,1:3:2]', False + check_ast('"hello"[0:3:1,0:4:2,1:3:2]', False) def test_str_3slice_all(): - yield check_ast, '"hello"[:,:,:]', False + check_ast('"hello"[:,:,:]', False) def test_str_3slice_upper(): - yield check_ast, '"hello"[5:,5:,5:]', False + check_ast('"hello"[5:,5:,5:]', False) def test_str_3slice_lower(): - yield check_ast, '"hello"[:3,:3,:3]', False + check_ast('"hello"[:3,:3,:3]', False) def test_str_3slice_lowerlowerupper(): - yield check_ast, '"hello"[:3,:3,:3]', False + check_ast('"hello"[:3,:3,:3]', False) def test_str_3slice_lowerupperlower(): - yield check_ast, '"hello"[:3,5:,:3]', False + check_ast('"hello"[:3,5:,:3]', False) def test_str_3slice_lowerupperupper(): - yield check_ast, '"hello"[:3,5:,5:]', False + check_ast('"hello"[:3,5:,5:]', False) def test_str_3slice_upperlowerlower(): - yield check_ast, '"hello"[5:,5:,:3]', False + check_ast('"hello"[5:,5:,:3]', False) def test_str_3slice_upperlowerupper(): - yield check_ast, '"hello"[5:,:3,5:]', False + check_ast('"hello"[5:,:3,5:]', False) def test_str_3slice_upperupperlower(): - yield check_ast, '"hello"[5:,5:,:3]', False + check_ast('"hello"[5:,5:,:3]', False) def test_str_3slice_other(): - yield check_ast, '"hello"[::2,::2,::2]', False + check_ast('"hello"[::2,::2,::2]', False) def test_str_3slice_lower_other(): - yield check_ast, '"hello"[:3:2,:3:2,:3:2]', False + check_ast('"hello"[:3:2,:3:2,:3:2]', False) def test_str_3slice_upper_other(): - yield check_ast, '"hello"[3::2,3::2,3::2]', False + check_ast('"hello"[3::2,3::2,3::2]', False) def test_str_slice_true(): - yield check_ast, '"hello"[0:3,True]', False + check_ast('"hello"[0:3,True]', False) def test_str_true_slice(): - yield check_ast, '"hello"[True,0:3]', False + check_ast('"hello"[True,0:3]', False) def test_list_empty(): - yield check_ast, '[]' + check_ast('[]') def test_list_one(): - yield check_ast, '[1]' + check_ast('[1]') def test_list_one_comma(): - yield check_ast, '[1,]' + check_ast('[1,]') def test_list_two(): - yield check_ast, '[1, 42]' + check_ast('[1, 42]') def test_list_three(): - yield check_ast, '[1, 42, 65]' + check_ast('[1, 42, 65]') def test_list_three_comma(): - yield check_ast, '[1, 42, 65,]' + check_ast('[1, 42, 65,]') def test_list_one_nested(): - yield check_ast, '[[1]]' + check_ast('[[1]]') def test_list_list_four_nested(): - yield check_ast, '[[1], [2], [3], [4]]' + check_ast('[[1], [2], [3], [4]]') def test_list_tuple_three_nested(): - yield check_ast, '[(1,), (2,), (3,)]' + check_ast('[(1,), (2,), (3,)]') def test_list_set_tuple_three_nested(): - yield check_ast, '[{(1,)}, {(2,)}, {(3,)}]' + check_ast('[{(1,)}, {(2,)}, {(3,)}]') def test_list_tuple_one_nested(): - yield check_ast, '[(1,)]' + check_ast('[(1,)]') def test_tuple_tuple_one_nested(): - yield check_ast, '((1,),)' + check_ast('((1,),)') def test_dict_list_one_nested(): - yield check_ast, '{1: [2]}' + check_ast('{1: [2]}') def test_dict_list_one_nested_comma(): - yield check_ast, '{1: [2],}' + check_ast('{1: [2],}') def test_dict_tuple_one_nested(): - yield check_ast, '{1: (2,)}' + check_ast('{1: (2,)}') def test_dict_tuple_one_nested_comma(): - yield check_ast, '{1: (2,),}' + check_ast('{1: (2,),}') def test_dict_list_two_nested(): - yield check_ast, '{1: [2], 3: [4]}' + check_ast('{1: [2], 3: [4]}') def test_set_tuple_one_nested(): - yield check_ast, '{(1,)}' + check_ast('{(1,)}') def test_set_tuple_two_nested(): - yield check_ast, '{(1,), (2,)}' + check_ast('{(1,), (2,)}') def test_tuple_empty(): - yield check_ast, '()' + check_ast('()') def test_tuple_one_bare(): - yield check_ast, '1,' + check_ast('1,') def test_tuple_two_bare(): - yield check_ast, '1, 42' + check_ast('1, 42') def test_tuple_three_bare(): - yield check_ast, '1, 42, 65' + check_ast('1, 42, 65') def test_tuple_three_bare_comma(): - yield check_ast, '1, 42, 65,' + check_ast('1, 42, 65,') def test_tuple_one_comma(): - yield check_ast, '(1,)' + check_ast('(1,)') def test_tuple_two(): - yield check_ast, '(1, 42)' + check_ast('(1, 42)') def test_tuple_three(): - yield check_ast, '(1, 42, 65)' + check_ast('(1, 42, 65)') def test_tuple_three_comma(): - yield check_ast, '(1, 42, 65,)' + check_ast('(1, 42, 65,)') def test_set_one(): - yield check_ast, '{42}' + check_ast('{42}') def test_set_one_comma(): - yield check_ast, '{42,}' + check_ast('{42,}') def test_set_two(): - yield check_ast, '{42, 65}' + check_ast('{42, 65}') def test_set_two_comma(): - yield check_ast, '{42, 65,}' + check_ast('{42, 65,}') def test_set_three(): - yield check_ast, '{42, 65, 45}' + check_ast('{42, 65, 45}') def test_dict_empty(): - yield check_ast, '{}' + check_ast('{}') def test_dict_one(): - yield check_ast, '{42: 65}' + check_ast('{42: 65}') def test_dict_one_comma(): - yield check_ast, '{42: 65,}' + check_ast('{42: 65,}') def test_dict_two(): - yield check_ast, '{42: 65, 6: 28}' + check_ast('{42: 65, 6: 28}') def test_dict_two_comma(): - yield check_ast, '{42: 65, 6: 28,}' + check_ast('{42: 65, 6: 28,}') def test_dict_three(): - yield check_ast, '{42: 65, 6: 28, 1: 2}' + check_ast('{42: 65, 6: 28, 1: 2}') @skip_if_py34 def test_dict_from_dict_two_xy(): @@ -543,274 +548,274 @@ def test_unpack_range_set_4(): check_ast('{*range(4), 4}') def test_true(): - yield check_ast, 'True' + check_ast('True') def test_false(): - yield check_ast, 'False' + check_ast('False') def test_none(): - yield check_ast, 'None' + check_ast('None') def test_elipssis(): - yield check_ast, '...' + check_ast('...') def test_not_implemented_name(): - yield check_ast, 'NotImplemented' + check_ast('NotImplemented') def test_genexpr(): - yield check_ast, '(x for x in "mom")' + check_ast('(x for x in "mom")') def test_genexpr_if(): - yield check_ast, '(x for x in "mom" if True)' + check_ast('(x for x in "mom" if True)') def test_genexpr_if_and(): - yield check_ast, '(x for x in "mom" if True and x == "m")' + check_ast('(x for x in "mom" if True and x == "m")') def test_dbl_genexpr(): - yield check_ast, '(x+y for x in "mom" for y in "dad")' + check_ast('(x+y for x in "mom" for y in "dad")') def test_genexpr_if_genexpr(): - yield check_ast, '(x+y for x in "mom" if True for y in "dad")' + check_ast('(x+y for x in "mom" if True for y in "dad")') def test_genexpr_if_genexpr_if(): - yield check_ast, '(x+y for x in "mom" if True for y in "dad" if y == "d")' + check_ast('(x+y for x in "mom" if True for y in "dad" if y == "d")') def test_listcomp(): - yield check_ast, '[x for x in "mom"]' + check_ast('[x for x in "mom"]') def test_listcomp_if(): - yield check_ast, '[x for x in "mom" if True]' + check_ast('[x for x in "mom" if True]') def test_listcomp_if_and(): - yield check_ast, '[x for x in "mom" if True and x == "m"]' + check_ast('[x for x in "mom" if True and x == "m"]') def test_dbl_listcomp(): - yield check_ast, '[x+y for x in "mom" for y in "dad"]' + check_ast('[x+y for x in "mom" for y in "dad"]') def test_listcomp_if_listcomp(): - yield check_ast, '[x+y for x in "mom" if True for y in "dad"]' + check_ast('[x+y for x in "mom" if True for y in "dad"]') def test_listcomp_if_listcomp_if(): - yield check_ast, '[x+y for x in "mom" if True for y in "dad" if y == "d"]' + check_ast('[x+y for x in "mom" if True for y in "dad" if y == "d"]') def test_setcomp(): - yield check_ast, '{x for x in "mom"}' + check_ast('{x for x in "mom"}') def test_setcomp_if(): - yield check_ast, '{x for x in "mom" if True}' + check_ast('{x for x in "mom" if True}') def test_setcomp_if_and(): - yield check_ast, '{x for x in "mom" if True and x == "m"}' + check_ast('{x for x in "mom" if True and x == "m"}') def test_dbl_setcomp(): - yield check_ast, '{x+y for x in "mom" for y in "dad"}' + check_ast('{x+y for x in "mom" for y in "dad"}') def test_setcomp_if_setcomp(): - yield check_ast, '{x+y for x in "mom" if True for y in "dad"}' + check_ast('{x+y for x in "mom" if True for y in "dad"}') def test_setcomp_if_setcomp_if(): - yield check_ast, '{x+y for x in "mom" if True for y in "dad" if y == "d"}' + check_ast('{x+y for x in "mom" if True for y in "dad" if y == "d"}') def test_dictcomp(): - yield check_ast, '{x: x for x in "mom"}' + check_ast('{x: x for x in "mom"}') def test_dictcomp_unpack_parens(): - yield check_ast, '{k: v for (k, v) in {"x": 42}.items()}' + check_ast('{k: v for (k, v) in {"x": 42}.items()}') def test_dictcomp_unpack_no_parens(): - yield check_ast, '{k: v for k, v in {"x": 42}.items()}' + check_ast('{k: v for k, v in {"x": 42}.items()}') def test_dictcomp_if(): - yield check_ast, '{x: x for x in "mom" if True}' + check_ast('{x: x for x in "mom" if True}') def test_dictcomp_if_and(): - yield check_ast, '{x: x for x in "mom" if True and x == "m"}' + check_ast('{x: x for x in "mom" if True and x == "m"}') def test_dbl_dictcomp(): - yield check_ast, '{x: y for x in "mom" for y in "dad"}' + check_ast('{x: y for x in "mom" for y in "dad"}') def test_dictcomp_if_dictcomp(): - yield check_ast, '{x: y for x in "mom" if True for y in "dad"}' + check_ast('{x: y for x in "mom" if True for y in "dad"}') def test_dictcomp_if_dictcomp_if(): - yield check_ast, '{x: y for x in "mom" if True for y in "dad" if y == "d"}' + check_ast('{x: y for x in "mom" if True for y in "dad" if y == "d"}') def test_lambda(): - yield check_ast, 'lambda: 42' + check_ast('lambda: 42') def test_lambda_x(): - yield check_ast, 'lambda x: x' + check_ast('lambda x: x') def test_lambda_kwx(): - yield check_ast, 'lambda x=42: x' + check_ast('lambda x=42: x') def test_lambda_x_y(): - yield check_ast, 'lambda x, y: x' + check_ast('lambda x, y: x') def test_lambda_x_y_z(): - yield check_ast, 'lambda x, y, z: x' + check_ast('lambda x, y, z: x') def test_lambda_x_kwy(): - yield check_ast, 'lambda x, y=42: x' + check_ast('lambda x, y=42: x') def test_lambda_kwx_kwy(): - yield check_ast, 'lambda x=65, y=42: x' + check_ast('lambda x=65, y=42: x') def test_lambda_kwx_kwy_kwz(): - yield check_ast, 'lambda x=65, y=42, z=1: x' + check_ast('lambda x=65, y=42, z=1: x') def test_lambda_x_comma(): - yield check_ast, 'lambda x,: x' + check_ast('lambda x,: x') def test_lambda_x_y_comma(): - yield check_ast, 'lambda x, y,: x' + check_ast('lambda x, y,: x') def test_lambda_x_y_z_comma(): - yield check_ast, 'lambda x, y, z,: x' + check_ast('lambda x, y, z,: x') def test_lambda_x_kwy_comma(): - yield check_ast, 'lambda x, y=42,: x' + check_ast('lambda x, y=42,: x') def test_lambda_kwx_kwy_comma(): - yield check_ast, 'lambda x=65, y=42,: x' + check_ast('lambda x=65, y=42,: x') def test_lambda_kwx_kwy_kwz_comma(): - yield check_ast, 'lambda x=65, y=42, z=1,: x' + check_ast('lambda x=65, y=42, z=1,: x') def test_lambda_args(): - yield check_ast, 'lambda *args: 42' + check_ast('lambda *args: 42') def test_lambda_args_x(): - yield check_ast, 'lambda *args, x: 42' + check_ast('lambda *args, x: 42') def test_lambda_args_x_y(): - yield check_ast, 'lambda *args, x, y: 42' + check_ast('lambda *args, x, y: 42') def test_lambda_args_x_kwy(): - yield check_ast, 'lambda *args, x, y=10: 42' + check_ast('lambda *args, x, y=10: 42') def test_lambda_args_kwx_y(): - yield check_ast, 'lambda *args, x=10, y: 42' + check_ast('lambda *args, x=10, y: 42') def test_lambda_args_kwx_kwy(): - yield check_ast, 'lambda *args, x=42, y=65: 42' + check_ast('lambda *args, x=42, y=65: 42') def test_lambda_x_args(): - yield check_ast, 'lambda x, *args: 42' + check_ast('lambda x, *args: 42') def test_lambda_x_args_y(): - yield check_ast, 'lambda x, *args, y: 42' + check_ast('lambda x, *args, y: 42') def test_lambda_x_args_y_z(): - yield check_ast, 'lambda x, *args, y, z: 42' + check_ast('lambda x, *args, y, z: 42') def test_lambda_kwargs(): - yield check_ast, 'lambda **kwargs: 42' + check_ast('lambda **kwargs: 42') def test_lambda_x_kwargs(): - yield check_ast, 'lambda x, **kwargs: 42' + check_ast('lambda x, **kwargs: 42') def test_lambda_x_y_kwargs(): - yield check_ast, 'lambda x, y, **kwargs: 42' + check_ast('lambda x, y, **kwargs: 42') def test_lambda_x_kwy_kwargs(): - yield check_ast, 'lambda x, y=42, **kwargs: 42' + check_ast('lambda x, y=42, **kwargs: 42') def test_lambda_args_kwargs(): - yield check_ast, 'lambda *args, **kwargs: 42' + check_ast('lambda *args, **kwargs: 42') def test_lambda_x_args_kwargs(): - yield check_ast, 'lambda x, *args, **kwargs: 42' + check_ast('lambda x, *args, **kwargs: 42') def test_lambda_x_y_args_kwargs(): - yield check_ast, 'lambda x, y, *args, **kwargs: 42' + check_ast('lambda x, y, *args, **kwargs: 42') def test_lambda_kwx_args_kwargs(): - yield check_ast, 'lambda x=10, *args, **kwargs: 42' + check_ast('lambda x=10, *args, **kwargs: 42') def test_lambda_x_kwy_args_kwargs(): - yield check_ast, 'lambda x, y=42, *args, **kwargs: 42' + check_ast('lambda x, y=42, *args, **kwargs: 42') def test_lambda_x_args_y_kwargs(): - yield check_ast, 'lambda x, *args, y, **kwargs: 42' + check_ast('lambda x, *args, y, **kwargs: 42') def test_lambda_x_args_kwy_kwargs(): - yield check_ast, 'lambda x, *args, y=42, **kwargs: 42' + check_ast('lambda x, *args, y=42, **kwargs: 42') def test_lambda_args_y_kwargs(): - yield check_ast, 'lambda *args, y, **kwargs: 42' + check_ast('lambda *args, y, **kwargs: 42') def test_lambda_star_x(): - yield check_ast, 'lambda *, x: 42' + check_ast('lambda *, x: 42') def test_lambda_star_x_y(): - yield check_ast, 'lambda *, x, y: 42' + check_ast('lambda *, x, y: 42') def test_lambda_star_x_kwargs(): - yield check_ast, 'lambda *, x, **kwargs: 42' + check_ast('lambda *, x, **kwargs: 42') def test_lambda_star_kwx_kwargs(): - yield check_ast, 'lambda *, x=42, **kwargs: 42' + check_ast('lambda *, x=42, **kwargs: 42') def test_lambda_x_star_y(): - yield check_ast, 'lambda x, *, y: 42' + check_ast('lambda x, *, y: 42') def test_lambda_x_y_star_z(): - yield check_ast, 'lambda x, y, *, z: 42' + check_ast('lambda x, y, *, z: 42') def test_lambda_x_kwy_star_y(): - yield check_ast, 'lambda x, y=42, *, z: 42' + check_ast('lambda x, y=42, *, z: 42') def test_lambda_x_kwy_star_kwy(): - yield check_ast, 'lambda x, y=42, *, z=65: 42' + check_ast('lambda x, y=42, *, z=65: 42') def test_lambda_x_star_y_kwargs(): - yield check_ast, 'lambda x, *, y, **kwargs: 42' + check_ast('lambda x, *, y, **kwargs: 42') def test_call_range(): - yield check_ast, 'range(6)' + check_ast('range(6)') def test_call_range_comma(): - yield check_ast, 'range(6,)' + check_ast('range(6,)') def test_call_range_x_y(): - yield check_ast, 'range(6, 10)' + check_ast('range(6, 10)') def test_call_range_x_y_comma(): - yield check_ast, 'range(6, 10,)' + check_ast('range(6, 10,)') def test_call_range_x_y_z(): - yield check_ast, 'range(6, 10, 2)' + check_ast('range(6, 10, 2)') def test_call_dict_kwx(): - yield check_ast, 'dict(start=10)' + check_ast('dict(start=10)') def test_call_dict_kwx_comma(): - yield check_ast, 'dict(start=10,)' + check_ast('dict(start=10,)') def test_call_dict_kwx_kwy(): - yield check_ast, 'dict(start=10, stop=42)' + check_ast('dict(start=10, stop=42)') def test_call_tuple_gen(): - yield check_ast, 'tuple(x for x in [1, 2, 3])' + check_ast('tuple(x for x in [1, 2, 3])') def test_call_tuple_genifs(): - yield check_ast, 'tuple(x for x in [1, 2, 3] if x < 3)' + check_ast('tuple(x for x in [1, 2, 3] if x < 3)') def test_call_range_star(): - yield check_ast, 'range(*[1, 2, 3])' + check_ast('range(*[1, 2, 3])') def test_call_range_x_star(): - yield check_ast, 'range(1, *[2, 3])' + check_ast('range(1, *[2, 3])') def test_call_int(): - yield check_ast, 'int(*["42"], base=8)' + check_ast('int(*["42"], base=8)') def test_call_int_base_dict(): - yield check_ast, 'int(*["42"], **{"base": 8})' + check_ast('int(*["42"], **{"base": 8})') def test_call_dict_kwargs(): - yield check_ast, 'dict(**{"base": 8})' + check_ast('dict(**{"base": 8})') @skip_if_py34 def test_call_list_many_star_args(): @@ -825,76 +830,76 @@ def test_call_list_many_star_and_starstar_args(): check_ast('x(*[("a", 2)], *[("v", 3)], **{"c": 5})', False) def test_call_alot(): - yield check_ast, 'x(1, *args, **kwargs)', False + check_ast('x(1, *args, **kwargs)', False) def test_call_alot_next(): - yield check_ast, 'x(x=1, *args, **kwargs)', False + check_ast('x(x=1, *args, **kwargs)', False) def test_call_alot_next_next(): - yield check_ast, 'x(x=1, *args, y=42, **kwargs)', False + check_ast('x(x=1, *args, y=42, **kwargs)', False) def test_getattr(): - yield check_ast, 'list.append' + check_ast('list.append') def test_getattr_getattr(): - yield check_ast, 'list.append.__str__' + check_ast('list.append.__str__') def test_dict_tuple_key(): - yield check_ast, '{(42, 1): 65}' + check_ast('{(42, 1): 65}') def test_dict_tuple_key_get(): - yield check_ast, '{(42, 1): 65}[42, 1]' + check_ast('{(42, 1): 65}[42, 1]') def test_dict_tuple_key_get_3(): - yield check_ast, '{(42, 1, 3): 65}[42, 1, 3]' + check_ast('{(42, 1, 3): 65}[42, 1, 3]') def test_pipe_op(): - yield check_ast, '{42} | {65}' + check_ast('{42} | {65}') def test_pipe_op_two(): - yield check_ast, '{42} | {65} | {1}' + check_ast('{42} | {65} | {1}') def test_pipe_op_three(): - yield check_ast, '{42} | {65} | {1} | {7}' + check_ast('{42} | {65} | {1} | {7}') def test_xor_op(): - yield check_ast, '{42} ^ {65}' + check_ast('{42} ^ {65}') def test_xor_op_two(): - yield check_ast, '{42} ^ {65} ^ {1}' + check_ast('{42} ^ {65} ^ {1}') def test_xor_op_three(): - yield check_ast, '{42} ^ {65} ^ {1} ^ {7}' + check_ast('{42} ^ {65} ^ {1} ^ {7}') def test_xor_pipe(): - yield check_ast, '{42} ^ {65} | {1}' + check_ast('{42} ^ {65} | {1}') def test_amp_op(): - yield check_ast, '{42} & {65}' + check_ast('{42} & {65}') def test_amp_op_two(): - yield check_ast, '{42} & {65} & {1}' + check_ast('{42} & {65} & {1}') def test_amp_op_three(): - yield check_ast, '{42} & {65} & {1} & {7}' + check_ast('{42} & {65} & {1} & {7}') def test_lshift_op(): - yield check_ast, '42 << 65' + check_ast('42 << 65') def test_lshift_op_two(): - yield check_ast, '42 << 65 << 1' + check_ast('42 << 65 << 1') def test_lshift_op_three(): - yield check_ast, '42 << 65 << 1 << 7' + check_ast('42 << 65 << 1 << 7') def test_rshift_op(): - yield check_ast, '42 >> 65' + check_ast('42 >> 65') def test_rshift_op_two(): - yield check_ast, '42 >> 65 >> 1' + check_ast('42 >> 65 >> 1') def test_rshift_op_three(): - yield check_ast, '42 >> 65 >> 1 >> 7' + check_ast('42 >> 65 >> 1 >> 7') #DEBUG_LEVEL = 1 @@ -907,565 +912,565 @@ def test_rshift_op_three(): # def test_equals(): - yield check_stmts, 'x = 42' + check_stmts('x = 42') def test_equals_semi(): - yield check_stmts, 'x = 42;' + check_stmts('x = 42;') def test_x_y_equals_semi(): - yield check_stmts, 'x = y = 42' + check_stmts('x = y = 42') def test_equals_two(): - yield check_stmts, 'x = 42; y = 65' + check_stmts('x = 42; y = 65') def test_equals_two_semi(): - yield check_stmts, 'x = 42; y = 65;' + check_stmts('x = 42; y = 65;') def test_equals_three(): - yield check_stmts, 'x = 42; y = 65; z = 6' + check_stmts('x = 42; y = 65; z = 6') def test_equals_three_semi(): - yield check_stmts, 'x = 42; y = 65; z = 6;' + check_stmts('x = 42; y = 65; z = 6;') def test_plus_eq(): - yield check_stmts, 'x = 42; x += 65' + check_stmts('x = 42; x += 65') def test_sub_eq(): - yield check_stmts, 'x = 42; x -= 2' + check_stmts('x = 42; x -= 2') def test_times_eq(): - yield check_stmts, 'x = 42; x *= 2' + check_stmts('x = 42; x *= 2') @skip_if_py34 def test_matmult_eq(): check_stmts('x @= y', False) def test_div_eq(): - yield check_stmts, 'x = 42; x /= 2' + check_stmts('x = 42; x /= 2') def test_floordiv_eq(): - yield check_stmts, 'x = 42; x //= 2' + check_stmts('x = 42; x //= 2') def test_pow_eq(): - yield check_stmts, 'x = 42; x **= 2' + check_stmts('x = 42; x **= 2') def test_mod_eq(): - yield check_stmts, 'x = 42; x %= 2' + check_stmts('x = 42; x %= 2') def test_xor_eq(): - yield check_stmts, 'x = 42; x ^= 2' + check_stmts('x = 42; x ^= 2') def test_ampersand_eq(): - yield check_stmts, 'x = 42; x &= 2' + check_stmts('x = 42; x &= 2') def test_bitor_eq(): - yield check_stmts, 'x = 42; x |= 2' + check_stmts('x = 42; x |= 2') def test_lshift_eq(): - yield check_stmts, 'x = 42; x <<= 2' + check_stmts('x = 42; x <<= 2') def test_rshift_eq(): - yield check_stmts, 'x = 42; x >>= 2' + check_stmts('x = 42; x >>= 2') def test_bare_unpack(): - yield check_stmts, 'x, y = 42, 65' + check_stmts('x, y = 42, 65') def test_lhand_group_unpack(): - yield check_stmts, '(x, y) = 42, 65' + check_stmts('(x, y) = 42, 65') def test_rhand_group_unpack(): - yield check_stmts, 'x, y = (42, 65)' + check_stmts('x, y = (42, 65)') def test_grouped_unpack(): - yield check_stmts, '(x, y) = (42, 65)' + check_stmts('(x, y) = (42, 65)') def test_double_grouped_unpack(): - yield check_stmts, '(x, y) = (z, a) = (7, 8)' + check_stmts('(x, y) = (z, a) = (7, 8)') def test_double_ungrouped_unpack(): - yield check_stmts, 'x, y = z, a = 7, 8' + check_stmts('x, y = z, a = 7, 8') def test_stary_eq(): - yield check_stmts, '*y, = [1, 2, 3]' + check_stmts('*y, = [1, 2, 3]') def test_stary_x(): - yield check_stmts, '*y, x = [1, 2, 3]' + check_stmts('*y, x = [1, 2, 3]') def test_tuple_x_stary(): - yield check_stmts, '(x, *y) = [1, 2, 3]' + check_stmts('(x, *y) = [1, 2, 3]') def test_list_x_stary(): - yield check_stmts, '[x, *y] = [1, 2, 3]' + check_stmts('[x, *y] = [1, 2, 3]') def test_bare_x_stary(): - yield check_stmts, 'x, *y = [1, 2, 3]' + check_stmts('x, *y = [1, 2, 3]') def test_bare_x_stary_z(): - yield check_stmts, 'x, *y, z = [1, 2, 2, 3]' + check_stmts('x, *y, z = [1, 2, 2, 3]') def test_equals_list(): - yield check_stmts, 'x = [42]; x[0] = 65' + check_stmts('x = [42]; x[0] = 65') def test_equals_dict(): - yield check_stmts, 'x = {42: 65}; x[42] = 3' + check_stmts('x = {42: 65}; x[42] = 3') def test_equals_attr(): - yield check_stmts, 'class X(object):\n pass\nx = X()\nx.a = 65' + check_stmts('class X(object):\n pass\nx = X()\nx.a = 65') def test_dict_keys(): - yield check_stmts, 'x = {"x": 1}\nx.keys()' + check_stmts('x = {"x": 1}\nx.keys()') def test_assert_msg(): - yield check_stmts, 'assert True, "wow mom"' + check_stmts('assert True, "wow mom"') def test_assert(): - yield check_stmts, 'assert True' + check_stmts('assert True') def test_pass(): - yield check_stmts, 'pass' + check_stmts('pass') def test_del(): - yield check_stmts, 'x = 42; del x' + check_stmts('x = 42; del x') def test_del_comma(): - yield check_stmts, 'x = 42; del x,' + check_stmts('x = 42; del x,') def test_del_two(): - yield check_stmts, 'x = 42; y = 65; del x, y' + check_stmts('x = 42; y = 65; del x, y') def test_del_two_comma(): - yield check_stmts, 'x = 42; y = 65; del x, y,' + check_stmts('x = 42; y = 65; del x, y,') def test_raise(): - yield check_stmts, 'raise', False + check_stmts('raise', False) def test_raise_x(): - yield check_stmts, 'raise TypeError', False + check_stmts('raise TypeError', False) def test_raise_x_from(): - yield check_stmts, 'raise TypeError from x', False + check_stmts('raise TypeError from x', False) def test_import_x(): - yield check_stmts, 'import x', False + check_stmts('import x', False) def test_import_xy(): - yield check_stmts, 'import x.y', False + check_stmts('import x.y', False) def test_import_xyz(): - yield check_stmts, 'import x.y.z', False + check_stmts('import x.y.z', False) def test_from_x_import_y(): - yield check_stmts, 'from x import y', False + check_stmts('from x import y', False) def test_from_dot_import_y(): - yield check_stmts, 'from . import y', False + check_stmts('from . import y', False) def test_from_dotx_import_y(): - yield check_stmts, 'from .x import y', False + check_stmts('from .x import y', False) def test_from_dotdotx_import_y(): - yield check_stmts, 'from ..x import y', False + check_stmts('from ..x import y', False) def test_from_dotdotdotx_import_y(): - yield check_stmts, 'from ...x import y', False + check_stmts('from ...x import y', False) def test_from_dotdotdotdotx_import_y(): - yield check_stmts, 'from ....x import y', False + check_stmts('from ....x import y', False) def test_from_import_x_y(): - yield check_stmts, 'import x, y', False + check_stmts('import x, y', False) def test_from_import_x_y_z(): - yield check_stmts, 'import x, y, z', False + check_stmts('import x, y, z', False) def test_from_dot_import_x_y(): - yield check_stmts, 'from . import x, y', False + check_stmts('from . import x, y', False) def test_from_dot_import_x_y_z(): - yield check_stmts, 'from . import x, y, z', False + check_stmts('from . import x, y, z', False) def test_from_dot_import_group_x_y(): - yield check_stmts, 'from . import (x, y)', False + check_stmts('from . import (x, y)', False) def test_import_x_as_y(): - yield check_stmts, 'import x as y', False + check_stmts('import x as y', False) def test_import_xy_as_z(): - yield check_stmts, 'import x.y as z', False + check_stmts('import x.y as z', False) def test_import_x_y_as_z(): - yield check_stmts, 'import x, y as z', False + check_stmts('import x, y as z', False) def test_import_x_as_y_z(): - yield check_stmts, 'import x as y, z', False + check_stmts('import x as y, z', False) def test_import_x_as_y_z_as_a(): - yield check_stmts, 'import x as y, z as a', False + check_stmts('import x as y, z as a', False) def test_from_dot_import_x_as_y(): - yield check_stmts, 'from . import x as y', False + check_stmts('from . import x as y', False) def test_from_x_import_star(): - yield check_stmts, 'from x import *', False + check_stmts('from x import *', False) def test_from_x_import_y_as_z(): - yield check_stmts, 'from x import y as z', False + check_stmts('from x import y as z', False) def test_from_x_import_y_as_z_a_as_b(): - yield check_stmts, 'from x import y as z, a as b', False + check_stmts('from x import y as z, a as b', False) def test_from_dotx_import_y_as_z_a_as_b_c_as_d(): - yield check_stmts, 'from .x import y as z, a as b, c as d', False + check_stmts('from .x import y as z, a as b, c as d', False) def test_continue(): - yield check_stmts, 'continue', False + check_stmts('continue', False) def test_break(): - yield check_stmts, 'break', False + check_stmts('break', False) def test_global(): - yield check_stmts, 'global x', False + check_stmts('global x', False) def test_global_xy(): - yield check_stmts, 'global x, y', False + check_stmts('global x, y', False) def test_nonlocal_x(): - yield check_stmts, 'nonlocal x', False + check_stmts('nonlocal x', False) def test_nonlocal_xy(): - yield check_stmts, 'nonlocal x, y', False + check_stmts('nonlocal x, y', False) def test_yield(): - yield check_stmts, 'yield', False + check_stmts('yield', False) def test_yield_x(): - yield check_stmts, 'yield x', False + check_stmts('yield x', False) def test_yield_x_comma(): - yield check_stmts, 'yield x,', False + check_stmts('yield x,', False) def test_yield_x_y(): - yield check_stmts, 'yield x, y', False + check_stmts('yield x, y', False) def test_yield_from_x(): - yield check_stmts, 'yield from x', False + check_stmts('yield from x', False) def test_return(): - yield check_stmts, 'return', False + check_stmts('return', False) def test_return_x(): - yield check_stmts, 'return x', False + check_stmts('return x', False) def test_return_x_comma(): - yield check_stmts, 'return x,', False + check_stmts('return x,', False) def test_return_x_y(): - yield check_stmts, 'return x, y', False + check_stmts('return x, y', False) def test_if_true(): - yield check_stmts, 'if True:\n pass' + check_stmts('if True:\n pass') def test_if_true_twolines(): - yield check_stmts, 'if True:\n pass\n pass' + check_stmts('if True:\n pass\n pass') def test_if_true_twolines_deindent(): - yield check_stmts, 'if True:\n pass\n pass\npass' + check_stmts('if True:\n pass\n pass\npass') def test_if_true_else(): - yield check_stmts, 'if True:\n pass\nelse: \n pass' + check_stmts('if True:\n pass\nelse: \n pass') def test_if_true_x(): - yield check_stmts, 'if True:\n x = 42' + check_stmts('if True:\n x = 42') def test_if_switch(): - yield check_stmts, 'x = 42\nif x == 1:\n pass' + check_stmts('x = 42\nif x == 1:\n pass') def test_if_switch_elif1_else(): - yield check_stmts, ('x = 42\nif x == 1:\n pass\n' - 'elif x == 2:\n pass\nelse:\n pass') + check_stmts('x = 42\nif x == 1:\n pass\n' + 'elif x == 2:\n pass\nelse:\n pass') def test_if_switch_elif2_else(): - yield check_stmts, ('x = 42\nif x == 1:\n pass\n' - 'elif x == 2:\n pass\n' - 'elif x == 3:\n pass\n' - 'elif x == 4:\n pass\n' - 'else:\n pass') + check_stmts('x = 42\nif x == 1:\n pass\n' + 'elif x == 2:\n pass\n' + 'elif x == 3:\n pass\n' + 'elif x == 4:\n pass\n' + 'else:\n pass') def test_if_nested(): - yield check_stmts, 'x = 42\nif x == 1:\n pass\n if x == 4:\n pass' + check_stmts('x = 42\nif x == 1:\n pass\n if x == 4:\n pass') def test_while(): - yield check_stmts, 'while False:\n pass' + check_stmts('while False:\n pass') def test_while_else(): - yield check_stmts, 'while False:\n pass\nelse:\n pass' + check_stmts('while False:\n pass\nelse:\n pass') def test_for(): - yield check_stmts, 'for x in range(6):\n pass' + check_stmts('for x in range(6):\n pass') def test_for_zip(): - yield check_stmts, 'for x, y in zip(range(6), "123456"):\n pass' + check_stmts('for x, y in zip(range(6), "123456"):\n pass') def test_for_idx(): - yield check_stmts, 'x = [42]\nfor x[0] in range(3):\n pass' + check_stmts('x = [42]\nfor x[0] in range(3):\n pass') def test_for_zip_idx(): - yield check_stmts, ('x = [42]\nfor x[0], y in zip(range(6), "123456"):\n' - ' pass') + check_stmts('x = [42]\nfor x[0], y in zip(range(6), "123456"):\n' + ' pass') def test_for_attr(): - yield check_stmts, 'for x.a in range(3):\n pass', False + check_stmts('for x.a in range(3):\n pass', False) def test_for_zip_attr(): - yield check_stmts, 'for x.a, y in zip(range(6), "123456"):\n pass', False + check_stmts('for x.a, y in zip(range(6), "123456"):\n pass', False) def test_for_else(): - yield check_stmts, 'for x in range(6):\n pass\nelse: pass' + check_stmts('for x in range(6):\n pass\nelse: pass') @skip_if_py34 def test_async_for(): check_stmts("async def f():\n async for x in y:\n pass\n", False) def test_with(): - yield check_stmts, 'with x:\n pass', False + check_stmts('with x:\n pass', False) def test_with_as(): - yield check_stmts, 'with x as y:\n pass', False + check_stmts('with x as y:\n pass', False) def test_with_xy(): - yield check_stmts, 'with x, y:\n pass', False + check_stmts('with x, y:\n pass', False) def test_with_x_as_y_z(): - yield check_stmts, 'with x as y, z:\n pass', False + check_stmts('with x as y, z:\n pass', False) def test_with_x_as_y_a_as_b(): - yield check_stmts, 'with x as y, a as b:\n pass', False + check_stmts('with x as y, a as b:\n pass', False) def test_with_in_func(): - yield check_stmts, "def f():\n with x:\n pass\n" + check_stmts("def f():\n with x:\n pass\n") @skip_if_py34 def test_async_with(): check_stmts("async def f():\n async with x as y:\n pass\n", False) def test_try(): - yield check_stmts, 'try:\n pass\nexcept:\n pass', False + check_stmts('try:\n pass\nexcept:\n pass', False) def test_try_except_t(): - yield check_stmts, 'try:\n pass\nexcept TypeError:\n pass', False + check_stmts('try:\n pass\nexcept TypeError:\n pass', False) def test_try_except_t_as_e(): - yield check_stmts, 'try:\n pass\nexcept TypeError as e:\n pass', False + check_stmts('try:\n pass\nexcept TypeError as e:\n pass', False) def test_try_except_t_u(): - yield check_stmts, 'try:\n pass\nexcept (TypeError, SyntaxError):\n pass', False + check_stmts('try:\n pass\nexcept (TypeError, SyntaxError):\n pass', False) def test_try_except_t_u_as_e(): - yield check_stmts, 'try:\n pass\nexcept (TypeError, SyntaxError) as e:\n pass', False + check_stmts('try:\n pass\nexcept (TypeError, SyntaxError) as e:\n pass', False) def test_try_except_t_except_u(): - yield check_stmts, ('try:\n pass\nexcept TypeError:\n pass\n' - 'except SyntaxError as f:\n pass'), False + check_stmts('try:\n pass\nexcept TypeError:\n pass\n' + 'except SyntaxError as f:\n pass', False) def test_try_except_else(): - yield check_stmts, 'try:\n pass\nexcept:\n pass\nelse: pass', False + check_stmts('try:\n pass\nexcept:\n pass\nelse: pass', False) def test_try_except_finally(): - yield check_stmts, 'try:\n pass\nexcept:\n pass\nfinally: pass', False + check_stmts('try:\n pass\nexcept:\n pass\nfinally: pass', False) def test_try_except_else_finally(): - yield check_stmts, ('try:\n pass\nexcept:\n pass\nelse:\n pass' - '\nfinally: pass'), False + check_stmts('try:\n pass\nexcept:\n pass\nelse:\n pass' + '\nfinally: pass', False) def test_try_finally(): - yield check_stmts, 'try:\n pass\nfinally: pass', False + check_stmts('try:\n pass\nfinally: pass', False) def test_func(): - yield check_stmts, 'def f():\n pass' + check_stmts('def f():\n pass') def test_func_ret(): - yield check_stmts, 'def f():\n return' + check_stmts('def f():\n return') def test_func_ret_42(): - yield check_stmts, 'def f():\n return 42' + check_stmts('def f():\n return 42') def test_func_ret_42_65(): - yield check_stmts, 'def f():\n return 42, 65' + check_stmts('def f():\n return 42, 65') def test_func_rarrow(): - yield check_stmts, 'def f() -> int:\n pass' + check_stmts('def f() -> int:\n pass') def test_func_x(): - yield check_stmts, 'def f(x):\n return x' + check_stmts('def f(x):\n return x') def test_func_kwx(): - yield check_stmts, 'def f(x=42):\n return x' + check_stmts('def f(x=42):\n return x') def test_func_x_y(): - yield check_stmts, 'def f(x, y):\n return x' + check_stmts('def f(x, y):\n return x') def test_func_x_y_z(): - yield check_stmts, 'def f(x, y, z):\n return x' + check_stmts('def f(x, y, z):\n return x') def test_func_x_kwy(): - yield check_stmts, 'def f(x, y=42):\n return x' + check_stmts('def f(x, y=42):\n return x') def test_func_kwx_kwy(): - yield check_stmts, 'def f(x=65, y=42):\n return x' + check_stmts('def f(x=65, y=42):\n return x') def test_func_kwx_kwy_kwz(): - yield check_stmts, 'def f(x=65, y=42, z=1):\n return x' + check_stmts('def f(x=65, y=42, z=1):\n return x') def test_func_x_comma(): - yield check_stmts, 'def f(x,):\n return x' + check_stmts('def f(x,):\n return x') def test_func_x_y_comma(): - yield check_stmts, 'def f(x, y,):\n return x' + check_stmts('def f(x, y,):\n return x') def test_func_x_y_z_comma(): - yield check_stmts, 'def f(x, y, z,):\n return x' + check_stmts('def f(x, y, z,):\n return x') def test_func_x_kwy_comma(): - yield check_stmts, 'def f(x, y=42,):\n return x' + check_stmts('def f(x, y=42,):\n return x') def test_func_kwx_kwy_comma(): - yield check_stmts, 'def f(x=65, y=42,):\n return x' + check_stmts('def f(x=65, y=42,):\n return x') def test_func_kwx_kwy_kwz_comma(): - yield check_stmts, 'def f(x=65, y=42, z=1,):\n return x' + check_stmts('def f(x=65, y=42, z=1,):\n return x') def test_func_args(): - yield check_stmts, 'def f(*args):\n return 42' + check_stmts('def f(*args):\n return 42') def test_func_args_x(): - yield check_stmts, 'def f(*args, x):\n return 42' + check_stmts('def f(*args, x):\n return 42') def test_func_args_x_y(): - yield check_stmts, 'def f(*args, x, y):\n return 42' + check_stmts('def f(*args, x, y):\n return 42') def test_func_args_x_kwy(): - yield check_stmts, 'def f(*args, x, y=10):\n return 42' + check_stmts('def f(*args, x, y=10):\n return 42') def test_func_args_kwx_y(): - yield check_stmts, 'def f(*args, x=10, y):\n return 42' + check_stmts('def f(*args, x=10, y):\n return 42') def test_func_args_kwx_kwy(): - yield check_stmts, 'def f(*args, x=42, y=65):\n return 42' + check_stmts('def f(*args, x=42, y=65):\n return 42') def test_func_x_args(): - yield check_stmts, 'def f(x, *args):\n return 42' + check_stmts('def f(x, *args):\n return 42') def test_func_x_args_y(): - yield check_stmts, 'def f(x, *args, y):\n return 42' + check_stmts('def f(x, *args, y):\n return 42') def test_func_x_args_y_z(): - yield check_stmts, 'def f(x, *args, y, z):\n return 42' + check_stmts('def f(x, *args, y, z):\n return 42') def test_func_kwargs(): - yield check_stmts, 'def f(**kwargs):\n return 42' + check_stmts('def f(**kwargs):\n return 42') def test_func_x_kwargs(): - yield check_stmts, 'def f(x, **kwargs):\n return 42' + check_stmts('def f(x, **kwargs):\n return 42') def test_func_x_y_kwargs(): - yield check_stmts, 'def f(x, y, **kwargs):\n return 42' + check_stmts('def f(x, y, **kwargs):\n return 42') def test_func_x_kwy_kwargs(): - yield check_stmts, 'def f(x, y=42, **kwargs):\n return 42' + check_stmts('def f(x, y=42, **kwargs):\n return 42') def test_func_args_kwargs(): - yield check_stmts, 'def f(*args, **kwargs):\n return 42' + check_stmts('def f(*args, **kwargs):\n return 42') def test_func_x_args_kwargs(): - yield check_stmts, 'def f(x, *args, **kwargs):\n return 42' + check_stmts('def f(x, *args, **kwargs):\n return 42') def test_func_x_y_args_kwargs(): - yield check_stmts, 'def f(x, y, *args, **kwargs):\n return 42' + check_stmts('def f(x, y, *args, **kwargs):\n return 42') def test_func_kwx_args_kwargs(): - yield check_stmts, 'def f(x=10, *args, **kwargs):\n return 42' + check_stmts('def f(x=10, *args, **kwargs):\n return 42') def test_func_x_kwy_args_kwargs(): - yield check_stmts, 'def f(x, y=42, *args, **kwargs):\n return 42' + check_stmts('def f(x, y=42, *args, **kwargs):\n return 42') def test_func_x_args_y_kwargs(): - yield check_stmts, 'def f(x, *args, y, **kwargs):\n return 42' + check_stmts('def f(x, *args, y, **kwargs):\n return 42') def test_func_x_args_kwy_kwargs(): - yield check_stmts, 'def f(x, *args, y=42, **kwargs):\n return 42' + check_stmts('def f(x, *args, y=42, **kwargs):\n return 42') def test_func_args_y_kwargs(): - yield check_stmts, 'def f(*args, y, **kwargs):\n return 42' + check_stmts('def f(*args, y, **kwargs):\n return 42') def test_func_star_x(): - yield check_stmts, 'def f(*, x):\n return 42' + check_stmts('def f(*, x):\n return 42') def test_func_star_x_y(): - yield check_stmts, 'def f(*, x, y):\n return 42' + check_stmts('def f(*, x, y):\n return 42') def test_func_star_x_kwargs(): - yield check_stmts, 'def f(*, x, **kwargs):\n return 42' + check_stmts('def f(*, x, **kwargs):\n return 42') def test_func_star_kwx_kwargs(): - yield check_stmts, 'def f(*, x=42, **kwargs):\n return 42' + check_stmts('def f(*, x=42, **kwargs):\n return 42') def test_func_x_star_y(): - yield check_stmts, 'def f(x, *, y):\n return 42' + check_stmts('def f(x, *, y):\n return 42') def test_func_x_y_star_z(): - yield check_stmts, 'def f(x, y, *, z):\n return 42' + check_stmts('def f(x, y, *, z):\n return 42') def test_func_x_kwy_star_y(): - yield check_stmts, 'def f(x, y=42, *, z):\n return 42' + check_stmts('def f(x, y=42, *, z):\n return 42') def test_func_x_kwy_star_kwy(): - yield check_stmts, 'def f(x, y=42, *, z=65):\n return 42' + check_stmts('def f(x, y=42, *, z=65):\n return 42') def test_func_x_star_y_kwargs(): - yield check_stmts, 'def f(x, *, y, **kwargs):\n return 42' + check_stmts('def f(x, *, y, **kwargs):\n return 42') def test_func_tx(): - yield check_stmts, 'def f(x:int):\n return x' + check_stmts('def f(x:int):\n return x') def test_func_txy(): - yield check_stmts, 'def f(x:int, y:float=10.0):\n return x' + check_stmts('def f(x:int, y:float=10.0):\n return x') def test_class(): - yield check_stmts, 'class X:\n pass' + check_stmts('class X:\n pass') def test_class_obj(): - yield check_stmts, 'class X(object):\n pass' + check_stmts('class X(object):\n pass') def test_class_int_flt(): - yield check_stmts, 'class X(int, object):\n pass' + check_stmts('class X(int, object):\n pass') def test_class_obj_kw(): # technically valid syntax, though it will fail to compile - yield check_stmts, 'class X(object=5):\n pass', False + check_stmts('class X(object=5):\n pass', False) def test_decorator(): - yield check_stmts, '@g\ndef f():\n pass', False + check_stmts('@g\ndef f():\n pass', False) def test_decorator_2(): - yield check_stmts, '@h\n@g\ndef f():\n pass', False + check_stmts('@h\n@g\ndef f():\n pass', False) def test_decorator_call(): - yield check_stmts, '@g()\ndef f():\n pass', False + check_stmts('@g()\ndef f():\n pass', False) def test_decorator_call_args(): - yield check_stmts, '@g(x, y=10)\ndef f():\n pass', False + check_stmts('@g(x, y=10)\ndef f():\n pass', False) def test_decorator_dot_call_args(): - yield check_stmts, '@h.g(x, y=10)\ndef f():\n pass', False + check_stmts('@h.g(x, y=10)\ndef f():\n pass', False) def test_decorator_dot_dot_call_args(): - yield check_stmts, '@i.h.g(x, y=10)\ndef f():\n pass', False + check_stmts('@i.h.g(x, y=10)\ndef f():\n pass', False) def test_broken_prompt_func(): code = ('def prompt():\n' " return '{user}'.format(\n" " user='me')\n") - yield check_stmts, code, False + check_stmts(code, False) def test_class_with_methods(): code = ('class Test:\n' @@ -1473,14 +1478,14 @@ def test_class_with_methods(): ' self.msg("hello world")\n' ' def msg(self, m):\n' ' print(m)\n') - yield check_stmts, code, False + check_stmts(code, False) def test_nested_functions(): code = ('def test(x):\n' ' def test2(y):\n' ' return y+x\n' ' return test2\n') - yield check_stmts, code, False + check_stmts(code, False) def test_function_blank_line(): code = ('def foo():\n' @@ -1494,7 +1499,7 @@ def test_function_blank_line(): ' i = random.randint(0,len(ascii_art)) - 1\n' ' print(" Get to work!")\n' ' print(ascii_art[i])\n') - yield check_stmts, code, False + check_stmts(code, False) @skip_if_py34 @@ -1514,275 +1519,273 @@ def test_async_await(): # def test_dollar_name(): - yield check_xonsh_ast, {'WAKKA': 42}, '$WAKKA' + check_xonsh_ast({'WAKKA': 42}, '$WAKKA') def test_dollar_py(): - yield check_xonsh, {'WAKKA': 42}, 'x = "WAKKA"; y = ${x}' + check_xonsh({'WAKKA': 42}, 'x = "WAKKA"; y = ${x}') def test_dollar_py_test(): - yield check_xonsh_ast, {'WAKKA': 42}, '${None or "WAKKA"}' + check_xonsh_ast({'WAKKA': 42}, '${None or "WAKKA"}') def test_dollar_py_recursive_name(): - yield check_xonsh_ast, {'WAKKA': 42, 'JAWAKA': 'WAKKA'}, \ - '${$JAWAKA}' + check_xonsh_ast({'WAKKA': 42, 'JAWAKA': 'WAKKA'}, '${$JAWAKA}') def test_dollar_py_test_recursive_name(): - yield check_xonsh_ast, {'WAKKA': 42, 'JAWAKA': 'WAKKA'}, \ - '${None or $JAWAKA}' + check_xonsh_ast({'WAKKA': 42, 'JAWAKA': 'WAKKA'}, '${None or $JAWAKA}') def test_dollar_py_test_recursive_test(): - yield check_xonsh_ast, {'WAKKA': 42, 'JAWAKA': 'WAKKA'}, \ - '${${"JAWA" + $JAWAKA[-2:]}}' + check_xonsh_ast({'WAKKA': 42, 'JAWAKA': 'WAKKA'}, + '${${"JAWA" + $JAWAKA[-2:]}}') def test_dollar_name_set(): - yield check_xonsh, {'WAKKA': 42}, '$WAKKA = 42' + check_xonsh({'WAKKA': 42}, '$WAKKA = 42') def test_dollar_py_set(): - yield check_xonsh, {'WAKKA': 42}, 'x = "WAKKA"; ${x} = 65' + check_xonsh({'WAKKA': 42}, 'x = "WAKKA"; ${x} = 65') def test_dollar_sub(): - yield check_xonsh_ast, {}, '$(ls)', False + check_xonsh_ast({}, '$(ls)', False) def test_dollar_sub_space(): - yield check_xonsh_ast, {}, '$(ls )', False + check_xonsh_ast({}, '$(ls )', False) def test_ls_dot(): - yield check_xonsh_ast, {}, '$(ls .)', False + check_xonsh_ast({}, '$(ls .)', False) def test_lambda_in_atparens(): - yield check_xonsh_ast, {}, '$(echo hello | @(lambda a, s=None: "hey!") foo bar baz)', False + check_xonsh_ast({}, '$(echo hello | @(lambda a, s=None: "hey!") foo bar baz)', False) def test_nested_madness(): - yield check_xonsh_ast, {}, '$(@$(which echo) ls | @(lambda a, s=None: $(@(s.strip()) @(a[1]))) foo -la baz)', False + check_xonsh_ast({}, '$(@$(which echo) ls | @(lambda a, s=None: $(@(s.strip()) @(a[1]))) foo -la baz)', False) def test_ls_dot_nesting(): - yield check_xonsh_ast, {}, '$(ls @(None or "."))', False + check_xonsh_ast({}, '$(ls @(None or "."))', False) def test_ls_dot_nesting_var(): - yield check_xonsh, {}, 'x = "."; $(ls @(None or x))', False + check_xonsh({}, 'x = "."; $(ls @(None or x))', False) def test_ls_dot_str(): - yield check_xonsh_ast, {}, '$(ls ".")', False + check_xonsh_ast({}, '$(ls ".")', False) def test_ls_nest_ls(): - yield check_xonsh_ast, {}, '$(ls $(ls))', False + check_xonsh_ast({}, '$(ls $(ls))', False) def test_ls_nest_ls_dashl(): - yield check_xonsh_ast, {}, '$(ls $(ls) -l)', False + check_xonsh_ast({}, '$(ls $(ls) -l)', False) def test_ls_envvar_strval(): - yield check_xonsh_ast, {'WAKKA': '.'}, '$(ls $WAKKA)', False + check_xonsh_ast({'WAKKA': '.'}, '$(ls $WAKKA)', False) def test_ls_envvar_listval(): - yield check_xonsh_ast, {'WAKKA': ['.', '.']}, '$(ls $WAKKA)', False + check_xonsh_ast({'WAKKA': ['.', '.']}, '$(ls $WAKKA)', False) def test_bang_sub(): - yield check_xonsh_ast, {}, '!(ls)', False + check_xonsh_ast({}, '!(ls)', False) def test_bang_sub_space(): - yield check_xonsh_ast, {}, '!(ls )', False + check_xonsh_ast({}, '!(ls )', False) def test_bang_ls_dot(): - yield check_xonsh_ast, {}, '!(ls .)', False + check_xonsh_ast({}, '!(ls .)', False) def test_bang_ls_dot_nesting(): - yield check_xonsh_ast, {}, '!(ls @(None or "."))', False + check_xonsh_ast({}, '!(ls @(None or "."))', False) def test_bang_ls_dot_nesting_var(): - yield check_xonsh, {}, 'x = "."; !(ls @(None or x))', False + check_xonsh({}, 'x = "."; !(ls @(None or x))', False) def test_bang_ls_dot_str(): - yield check_xonsh_ast, {}, '!(ls ".")', False + check_xonsh_ast({}, '!(ls ".")', False) def test_bang_ls_nest_ls(): - yield check_xonsh_ast, {}, '!(ls $(ls))', False + check_xonsh_ast({}, '!(ls $(ls))', False) def test_bang_ls_nest_ls_dashl(): - yield check_xonsh_ast, {}, '!(ls $(ls) -l)', False + check_xonsh_ast({}, '!(ls $(ls) -l)', False) def test_bang_ls_envvar_strval(): - yield check_xonsh_ast, {'WAKKA': '.'}, '!(ls $WAKKA)', False + check_xonsh_ast({'WAKKA': '.'}, '!(ls $WAKKA)', False) def test_bang_ls_envvar_listval(): - yield check_xonsh_ast, {'WAKKA': ['.', '.']}, '!(ls $WAKKA)', False + check_xonsh_ast({'WAKKA': ['.', '.']}, '!(ls $WAKKA)', False) def test_question(): - yield check_xonsh_ast, {}, 'range?' + check_xonsh_ast({}, 'range?') def test_dobquestion(): - yield check_xonsh_ast, {}, 'range??' + check_xonsh_ast({}, 'range??') def test_question_chain(): - yield check_xonsh_ast, {}, 'range?.index?' + check_xonsh_ast({}, 'range?.index?') def test_ls_regex(): - yield check_xonsh_ast, {}, '$(ls `[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls `[Ff]+i*LE` -l)', False) def test_backtick(): - yield check_xonsh_ast, {}, 'print(`.*`)', False + check_xonsh_ast({}, 'print(`.*`)', False) def test_ls_regex_octothorpe(): - yield check_xonsh_ast, {}, '$(ls `#[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls `#[Ff]+i*LE` -l)', False) def test_ls_explicitregex(): - yield check_xonsh_ast, {}, '$(ls r`[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls r`[Ff]+i*LE` -l)', False) def test_rbacktick(): - yield check_xonsh_ast, {}, 'print(r`.*`)', False + check_xonsh_ast({}, 'print(r`.*`)', False) def test_ls_explicitregex_octothorpe(): - yield check_xonsh_ast, {}, '$(ls r`#[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls r`#[Ff]+i*LE` -l)', False) def test_ls_glob(): - yield check_xonsh_ast, {}, '$(ls g`[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls g`[Ff]+i*LE` -l)', False) def test_gbacktick(): - yield check_xonsh_ast, {}, 'print(g`.*`)', False + check_xonsh_ast({}, 'print(g`.*`)', False) def test_ls_glob_octothorpe(): - yield check_xonsh_ast, {}, '$(ls g`#[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls g`#[Ff]+i*LE` -l)', False) def test_ls_customsearch(): - yield check_xonsh_ast, {}, '$(ls @foo`[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls @foo`[Ff]+i*LE` -l)', False) def test_custombacktick(): - yield check_xonsh_ast, {}, 'print(@foo`.*`)', False + check_xonsh_ast({}, 'print(@foo`.*`)', False) def test_ls_customsearch_octothorpe(): - yield check_xonsh_ast, {}, '$(ls @foo`#[Ff]+i*LE` -l)', False + check_xonsh_ast({}, '$(ls @foo`#[Ff]+i*LE` -l)', False) def test_injection(): - yield check_xonsh_ast, {}, '$[@$(which python)]', False + check_xonsh_ast({}, '$[@$(which python)]', False) def test_rhs_nested_injection(): - yield check_xonsh_ast, {}, '$[ls @$(dirname @$(which python))]', False + check_xonsh_ast({}, '$[ls @$(dirname @$(which python))]', False) def test_backtick_octothorpe(): - yield check_xonsh_ast, {}, 'print(`#.*`)', False + check_xonsh_ast({}, 'print(`#.*`)', False) def test_uncaptured_sub(): - yield check_xonsh_ast, {}, '$[ls]', False + check_xonsh_ast({}, '$[ls]', False) def test_hiddenobj_sub(): - yield check_xonsh_ast, {}, '![ls]', False + check_xonsh_ast({}, '![ls]', False) def test_bang_two_cmds_one_pipe(): - yield check_xonsh_ast, {}, '!(ls | grep wakka)', False + check_xonsh_ast({}, '!(ls | grep wakka)', False) def test_bang_three_cmds_two_pipes(): - yield check_xonsh_ast, {}, '!(ls | grep wakka | grep jawaka)', False + check_xonsh_ast({}, '!(ls | grep wakka | grep jawaka)', False) def test_bang_one_cmd_write(): - yield check_xonsh_ast, {}, '!(ls > x.py)', False + check_xonsh_ast({}, '!(ls > x.py)', False) def test_bang_one_cmd_append(): - yield check_xonsh_ast, {}, '!(ls >> x.py)', False + check_xonsh_ast({}, '!(ls >> x.py)', False) def test_bang_two_cmds_write(): - yield check_xonsh_ast, {}, '!(ls | grep wakka > x.py)', False + check_xonsh_ast({}, '!(ls | grep wakka > x.py)', False) def test_bang_two_cmds_append(): - yield check_xonsh_ast, {}, '!(ls | grep wakka >> x.py)', False + check_xonsh_ast({}, '!(ls | grep wakka >> x.py)', False) def test_bang_cmd_background(): - yield check_xonsh_ast, {}, '!(emacs ugggh &)', False + check_xonsh_ast({}, '!(emacs ugggh &)', False) def test_bang_cmd_background_nospace(): - yield check_xonsh_ast, {}, '!(emacs ugggh&)', False + check_xonsh_ast({}, '!(emacs ugggh&)', False) def test_bang_git_quotes_no_space(): - yield check_xonsh_ast, {}, '![git commit -am "wakka"]', False + check_xonsh_ast({}, '![git commit -am "wakka"]', False) def test_bang_git_quotes_space(): - yield check_xonsh_ast, {}, '![git commit -am "wakka jawaka"]', False + check_xonsh_ast({}, '![git commit -am "wakka jawaka"]', False) def test_bang_git_two_quotes_space(): - yield check_xonsh, {}, ('![git commit -am "wakka jawaka"]\n' - '![git commit -am "flock jawaka"]\n'), False + check_xonsh({}, '![git commit -am "wakka jawaka"]\n' + '![git commit -am "flock jawaka"]\n', False) def test_bang_git_two_quotes_space_space(): - yield check_xonsh, {}, ('![git commit -am "wakka jawaka" ]\n' - '![git commit -am "flock jawaka milwaka" ]\n'), False + check_xonsh({}, '![git commit -am "wakka jawaka" ]\n' + '![git commit -am "flock jawaka milwaka" ]\n', False) def test_bang_ls_quotes_3_space(): - yield check_xonsh_ast, {}, '![ls "wakka jawaka baraka"]', False + check_xonsh_ast({}, '![ls "wakka jawaka baraka"]', False) def test_two_cmds_one_pipe(): - yield check_xonsh_ast, {}, '$(ls | grep wakka)', False + check_xonsh_ast({}, '$(ls | grep wakka)', False) def test_three_cmds_two_pipes(): - yield check_xonsh_ast, {}, '$(ls | grep wakka | grep jawaka)', False + check_xonsh_ast({}, '$(ls | grep wakka | grep jawaka)', False) def test_two_cmds_one_and_brackets(): - yield check_xonsh_ast, {}, '![ls me] and ![grep wakka]', False + check_xonsh_ast({}, '![ls me] and ![grep wakka]', False) def test_three_cmds_two_ands(): - yield check_xonsh_ast, {}, '![ls] and ![grep wakka] and ![grep jawaka]', False + check_xonsh_ast({}, '![ls] and ![grep wakka] and ![grep jawaka]', False) def test_two_cmds_one_doubleamps(): - yield check_xonsh_ast, {}, '![ls] && ![grep wakka]', False + check_xonsh_ast({}, '![ls] && ![grep wakka]', False) def test_three_cmds_two_doubleamps(): - yield check_xonsh_ast, {}, '![ls] && ![grep wakka] && ![grep jawaka]', False + check_xonsh_ast({}, '![ls] && ![grep wakka] && ![grep jawaka]', False) def test_two_cmds_one_or(): - yield check_xonsh_ast, {}, '![ls] or ![grep wakka]', False + check_xonsh_ast({}, '![ls] or ![grep wakka]', False) def test_three_cmds_two_ors(): - yield check_xonsh_ast, {}, '![ls] or ![grep wakka] or ![grep jawaka]', False + check_xonsh_ast({}, '![ls] or ![grep wakka] or ![grep jawaka]', False) def test_two_cmds_one_doublepipe(): - yield check_xonsh_ast, {}, '![ls] || ![grep wakka]', False + check_xonsh_ast({}, '![ls] || ![grep wakka]', False) def test_three_cmds_two_doublepipe(): - yield check_xonsh_ast, {}, '![ls] || ![grep wakka] || ![grep jawaka]', False + check_xonsh_ast({}, '![ls] || ![grep wakka] || ![grep jawaka]', False) def test_one_cmd_write(): - yield check_xonsh_ast, {}, '$(ls > x.py)', False + check_xonsh_ast({}, '$(ls > x.py)', False) def test_one_cmd_append(): - yield check_xonsh_ast, {}, '$(ls >> x.py)', False + check_xonsh_ast({}, '$(ls >> x.py)', False) def test_two_cmds_write(): - yield check_xonsh_ast, {}, '$(ls | grep wakka > x.py)', False + check_xonsh_ast({}, '$(ls | grep wakka > x.py)', False) def test_two_cmds_append(): - yield check_xonsh_ast, {}, '$(ls | grep wakka >> x.py)', False + check_xonsh_ast({}, '$(ls | grep wakka >> x.py)', False) def test_cmd_background(): - yield check_xonsh_ast, {}, '$(emacs ugggh &)', False + check_xonsh_ast({}, '$(emacs ugggh &)', False) def test_cmd_background_nospace(): - yield check_xonsh_ast, {}, '$(emacs ugggh&)', False + check_xonsh_ast({}, '$(emacs ugggh&)', False) def test_git_quotes_no_space(): - yield check_xonsh_ast, {}, '$[git commit -am "wakka"]', False + check_xonsh_ast({}, '$[git commit -am "wakka"]', False) def test_git_quotes_space(): - yield check_xonsh_ast, {}, '$[git commit -am "wakka jawaka"]', False + check_xonsh_ast({}, '$[git commit -am "wakka jawaka"]', False) def test_git_two_quotes_space(): - yield check_xonsh, {}, ('$[git commit -am "wakka jawaka"]\n' - '$[git commit -am "flock jawaka"]\n'), False + check_xonsh({}, '$[git commit -am "wakka jawaka"]\n' + '$[git commit -am "flock jawaka"]\n', False) def test_git_two_quotes_space_space(): - yield check_xonsh, {}, ('$[git commit -am "wakka jawaka" ]\n' - '$[git commit -am "flock jawaka milwaka" ]\n'), False + check_xonsh({}, '$[git commit -am "wakka jawaka" ]\n' + '$[git commit -am "flock jawaka milwaka" ]\n', False) def test_ls_quotes_3_space(): - yield check_xonsh_ast, {}, '$[ls "wakka jawaka baraka"]', False + check_xonsh_ast({}, '$[ls "wakka jawaka baraka"]', False) def test_echo_comma(): - yield check_xonsh_ast, {}, '![echo ,]', False + check_xonsh_ast({}, '![echo ,]', False) def test_echo_internal_comma(): - yield check_xonsh_ast, {}, '![echo 1,2]', False + check_xonsh_ast({}, '![echo 1,2]', False) def test_comment_only(): - yield check_xonsh_ast, {}, '# hello' + check_xonsh_ast({}, '# hello') def test_echo_slash_question(): - yield check_xonsh_ast, {}, '![echo /?]', False + check_xonsh_ast({}, '![echo /?]', False) _error_names = {'e', 'err', '2'} From e79772955cc50a729bf396811e012e2c721ef3e9 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 14:19:54 -0400 Subject: [PATCH 66/95] fix `has_prompt_toolkit()` --- xonsh/platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/platform.py b/xonsh/platform.py index 6225d472f..612603fe5 100644 --- a/xonsh/platform.py +++ b/xonsh/platform.py @@ -81,7 +81,7 @@ def pygments_version(): @functools.lru_cache(1) def has_prompt_toolkit(): """ Tests if the `prompt_toolkit` is available. """ - spec = importlib.util.find_spec('pygments') + spec = importlib.util.find_spec('prompt_toolkit') return (spec is not None) From 170d08f43fd5746d7299556e82c201345c96720b Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 15:04:28 -0400 Subject: [PATCH 67/95] uncomment tests (my bad) --- tests/test_tools.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 6e3572f82..58587e477 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -35,6 +35,7 @@ LEXER.build() INDENT = ' ' TOOLS_ENV = {'EXPAND_ENV_VARS': True, 'XONSH_ENCODING_ERRORS':'strict'} +ENCODE_ENV_ONLY = {'XONSH_ENCODING_ERRORS': 'strict'} PATHEXT_ENV = {'PATHEXT': ['.COM', '.EXE', '.BAT']} def test_subproc_toks_x(): @@ -535,7 +536,7 @@ def test_is_env_path(): (['/home/jawaka'], False), (EnvPath(['/home/jawaka']), True), (EnvPath(['jawaka']), True), - #(EnvPath(b'jawaka:wakka'), True), + (EnvPath(b'jawaka:wakka'), True), ] for inp, exp in cases: obs = is_env_path(inp) @@ -547,7 +548,7 @@ def test_str_to_env_path(): ('/home/wakka', ['/home/wakka']), ('/home/wakka' + os.pathsep + '/home/jawaka', ['/home/wakka', '/home/jawaka']), - #(b'/home/wakka', ['/home/wakka']), + (b'/home/wakka', ['/home/wakka']), ] for inp, exp in cases: obs = str_to_env_path(inp) @@ -580,6 +581,11 @@ def test_env_path(): obs = EnvPath(inp)[0] # call to __getitem__ assert expand(exp) == obs + with mock_xonsh_env(ENCODE_ENV_ONLY): + for inp, exp in getitem_cases: + obs = EnvPath(inp)[0] # call to __getitem__ + assert exp == obs + # cases that involve path-separated strings multipath_cases = [ (os.pathsep.join(['xonsh_dir', '../', '.', '~/']), @@ -592,6 +598,11 @@ def test_env_path(): obs = [i for i in EnvPath(inp)] assert [expand(i) for i in exp] == obs + with mock_xonsh_env(ENCODE_ENV_ONLY): + for inp, exp in multipath_cases: + obs = [i for i in EnvPath(inp)] + assert [i for i in exp] == obs + # cases that involve pathlib.Path objects pathlib_cases = [ (pathlib.Path('/home/wakka'), ['/home/wakka'.replace('/',os.sep)]), @@ -611,7 +622,6 @@ def test_env_path(): obs = [i for i in EnvPath(inp)] assert [expand(i) for i in exp] == obs - def test_env_path_slices(): # build os-dependent paths properly mkpath = lambda *paths: os.sep + os.sep.join(paths) From 58c34f23959f2da68788e6fb07041049d3e25b03 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 15:49:58 -0400 Subject: [PATCH 68/95] add changelog --- news/pytest.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 news/pytest.rst diff --git a/news/pytest.rst b/news/pytest.rst new file mode 100644 index 000000000..6a8d039b5 --- /dev/null +++ b/news/pytest.rst @@ -0,0 +1,13 @@ +**Added:** None + +**Changed:** + +* Changed testing framework from nose to pytest + +**Deprecated:** None + +**Removed:** None + +**Fixed:** None + +**Security:** None From d5975ea7580fbec193d09ec2b73fa127c7665582 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 17:04:28 -0400 Subject: [PATCH 69/95] remove run_tests --- scripts/run_tests.xsh | 74 ------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100755 scripts/run_tests.xsh diff --git a/scripts/run_tests.xsh b/scripts/run_tests.xsh deleted file mode 100755 index 8fa603e17..000000000 --- a/scripts/run_tests.xsh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env xonsh --no-rc -# -# Run all the nosetests or just the ones relevant for the edited files in the -# current uncommited git change or just the ones named on the command line. -# Your cwd must be the top of the project tree. -# -# Usage: -# run_tests.xsh [edited | all | list of test names] -# -# You can omit the "all" argument if you want all tests run. -# -import os.path -import sys - -if not os.path.isdir('.git'): - print('No .git directory. The cwd must be the top of the project tree.', - file=sys.stderr) - sys.exit(1) - -if len($ARGS) == 1: - # Run all tests. - # ensure lexer/parser table module is up to date - $[python3 -c 'import setup; setup.build_tables()'] - $[env XONSHRC='' nosetests -q] -elif len($ARGS) == 2 and $ARG1 == 'all': - # Run all tests. - # ensure lexer/parser table module is up to date - $[python3 -c 'import setup; setup.build_tables()'] - $[env XONSHRC='' nosetests -q] -elif len($ARGS) == 2 and $ARG1 == 'edited': - # Run just the tests for the files edited in the uncommited change. - tests = set() - for edited_fname in $(git status -s).split(): - if not edited_fname.endswith('.py'): - continue - if edited_fname.startswith('xonsh/'): - test_fname = 'tests/test_' + edited_fname[len('xonsh/')] - if os.path.exists(test_fname): - tests.add(test_fname) - elif edited_fname.startswith('tests/'): - tests.add(edited_fname) - else: - print('Ignoring file because I cannot find a test for: {!r}.'. - format(edited_fname), file=sys.stderr) - - if tests: - # ensure lexer/parser table module is up to date - $[python3 -c 'import setup; setup.build_tables()'] - $[env XONSHRC='' nosetests -q -v @(sorted(tests))] - else: - print('Cannot find any tests in the pending changes.', file=sys.stderr) -else: - # Run the named tests. - tests = set() - for test_fname in $ARGS[1:]: - if not test_fname.startswith('tests/'): - if not test_fname.startswith('test_'): - test_fname = 'tests/test_' + test_fname - if not test_fname.endswith('.py'): - test_fname += '.py' - if os.path.exists(test_fname): - tests.add(test_fname) - else: - print('Cannot find test module {!r}; ignoring the argument.'. - format(test_fname), file=sys.stderr) - - if tests: - # ensure lexer/parser table module is up to date - $[python3 -c 'import setup; setup.build_tables()'] - $[env XONSHRC='' nosetests -q -v @(sorted(tests))] - else: - print('Cannot find any tests matching {}.'.format($ARGS[1:]), - file=sys.stderr) - sys.exit(1) From 4d63d639854802ce6576f8e3837f4c11b71b8af2 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 23 Jun 2016 17:11:16 -0400 Subject: [PATCH 70/95] fix for os.environ lookup --- xonsh/tools.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xonsh/tools.py b/xonsh/tools.py index 8c95606aa..0b627af36 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -583,10 +583,15 @@ def suggest_commands(cmd, env, aliases): def print_exception(msg=None): """Print exceptions with/without traceback.""" - env = getattr(builtins, '__xonsh_env__', os.environ) + env = getattr(builtins, '__xonsh_env__', None) # flags indicating whether the traceback options have been manually set - manually_set_trace = env.is_manually_set('XONSH_SHOW_TRACEBACK') - manually_set_logfile = env.is_manually_set('XONSH_TRACEBACK_LOGFILE') + if env is None: + env = os.environ + manually_set_trace = 'XONSH_SHOW_TRACEBACK' in env + manually_set_logfile ='XONSH_TRACEBACK_LOGFILE' in env + else: + manually_set_trace = env.is_manually_set('XONSH_SHOW_TRACEBACK') + manually_set_logfile = env.is_manually_set('XONSH_TRACEBACK_LOGFILE') if (not manually_set_trace) and (not manually_set_logfile): # Notify about the traceback output possibility if neither of # the two options have been manually set @@ -604,7 +609,6 @@ def print_exception(msg=None): sys.stderr.write('xonsh: To log full traceback to a file set: ' '$XONSH_TRACEBACK_LOGFILE = \n') traceback.print_exc() - # additionally, check if a file for traceback logging has been # specified and convert to a proper option if needed log_file = env.get('XONSH_TRACEBACK_LOGFILE', None) From 6d489843c30da1a222907897e8bbbae28fee2a64 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Thu, 23 Jun 2016 17:11:45 -0400 Subject: [PATCH 71/95] update CONTRIBUTING with changes to pytest --- CONTRIBUTING.rst | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 4c24becc8..79cae7748 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -84,7 +84,7 @@ is open to interpretation. recommendations from PEP8 are not required here. * All Python code should be compliant with Python 3.4+. At some unforeseen date in the future, Python 2.7 support *may* be supported. -* Tests should be written with nose using a procedural style. Do not use +* Tests should be written with pytest using a procedural style. Do not use unittest directly or write tests in an object-oriented style. * Test generators make more dots and the dots must flow! @@ -165,12 +165,11 @@ Prep your environment for running the tests:: Running the Tests - Basic ---------------------------------- -Run all the tests using Nose:: +Run all the tests using pytest:: - $ nosetests -q + $ py.test -q -Use "-q" to keep nose from outputing a dot for every test. There are A LOT of tests -and you will waste time waiting for all the dots to get pushed through stdout. +Use "-q" to keep pytest from outputting a bunch of info for every test. ---------------------------------- Running the Tests - Advanced @@ -178,35 +177,16 @@ Running the Tests - Advanced To perform all unit tests:: - $ scripts/run_tests.xsh all - -If you're working on a change and haven't yet committed it you can run the -tests associated with the change. This does not require that the change -include the unit test module. This will execute any unit tests that are -part of the change as well as the unit tests for xonsh source modules in -the change:: - - $ scripts/run_tests.xsh + $ py.test If you want to run specific tests you can specify the test names to execute. For example to run test_aliases:: - $ scripts/run_tests.xsh aliases - -The test name can be the bare test name (e.g., ``aliases``), include -the ``test_`` prefix and ``.py`` suffix without the directory -(e.g., ``test_aliases.py``), or the complete relative path (e.g., -``tests/test_aliases.py``). For example: + $ py.test test_aliases.py Note that you can pass multiple test names in the above examples:: - $ scripts/run_tests.xsh aliases environ - -As before, if you want to test the xonsh code that is installed on your -system first cd into the `tests` directory then run the tests:: - - $ cd tests - $ env XONSHRC='' nosetests test_aliases.py test_environ.py + $ py.test test_aliases.py test_environ.py Happy testing! From 8fbba6793e474eea35facb3c9b7983f9021ea765 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Thu, 23 Jun 2016 17:34:27 -0400 Subject: [PATCH 72/95] catch json.JSONDecodeError, which is a subclass of ValueError --- xonsh/ptk/history.py | 2 +- xonsh/readline_shell.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xonsh/ptk/history.py b/xonsh/ptk/history.py index 75ca447cc..c23ea61b6 100644 --- a/xonsh/ptk/history.py +++ b/xonsh/ptk/history.py @@ -69,7 +69,7 @@ class PromptToolkitHistoryAdder(Thread): continue buf.reset(initial_document=buf.document) lj.close() - except (IOError, OSError): + except (IOError, OSError, ValueError): continue def _buf(self): diff --git a/xonsh/readline_shell.py b/xonsh/readline_shell.py index 3b9a619b9..adaaa2b0f 100644 --- a/xonsh/readline_shell.py +++ b/xonsh/readline_shell.py @@ -469,5 +469,5 @@ class ReadlineHistoryAdder(Thread): RL_LIB.history_set_pos(i) i += 1 lj.close() - except (IOError, OSError): + except (IOError, OSError, ValueError): continue From 8d564879f408cffcdc2359a4043917be100d9eee Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 11:39:04 -0400 Subject: [PATCH 73/95] fixed name of apt_tabcomplete.xsh --- xonsh/xontribs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/xontribs.json b/xonsh/xontribs.json index 079fff775..93050e2b3 100644 --- a/xonsh/xontribs.json +++ b/xonsh/xontribs.json @@ -35,7 +35,7 @@ "bit of the startup time when running your favorite, minimal ", "text editor."] }, - {"name": "xonsh-apt-tabcomplete", + {"name": "apt_tabcomplete", "package": "xonsh-apt-tabcomplete", "url": "https://github.com/DangerOnTheRanger/xonsh-apt-tabcomplete", "description": ["Adds tabcomplete functionality to apt-get/apt-cache inside of xonsh."] From 532262f0755aaf856831e852fcbeda8f9aa687a7 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Fri, 24 Jun 2016 12:36:50 -0400 Subject: [PATCH 74/95] add pacman tab completion xontrib --- xonsh/xontribs.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xonsh/xontribs.json b/xonsh/xontribs.json index 079fff775..6b7d6f8a8 100644 --- a/xonsh/xontribs.json +++ b/xonsh/xontribs.json @@ -39,6 +39,11 @@ "package": "xonsh-apt-tabcomplete", "url": "https://github.com/DangerOnTheRanger/xonsh-apt-tabcomplete", "description": ["Adds tabcomplete functionality to apt-get/apt-cache inside of xonsh."] + }, + {"name": "pacman_tabcomplete", + "package": "xonsh-pacman-tabcomplete", + "url": "https://github.com/gforsyth/xonsh-pacman-tabcomplete", + "description": ["Adds tabcomplete functionality to pacman inside of xonsh."] } ], "packages": { @@ -71,6 +76,13 @@ "install": { "pip": "pip install xonsh-apt-tabcomplete" } + }, + "xonsh-pacman-tabcomplete": { + "license": "MIT", + "url": "https://github.com/gforsyth/xonsh-pacman-tabcomplete", + "install": { + "pip": "pip install xonsh-pacman-tabcomplete" + } } } } From ce93945de3814c6203438201c986c74e4573ab9c Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 01:00:42 +0300 Subject: [PATCH 75/95] Make CommandsCache play well with Windows --- xonsh/environ.py | 22 +++++++++------------- xonsh/tools.py | 26 +++++++++++++++++++++----- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index 8cd87bdd6..5327a3916 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -823,31 +823,27 @@ def _yield_executables(directory, name): def locate_binary(name): """Locates an executable on the file system.""" + + cc = builtins.__xonsh_commands_cache__ + if ON_WINDOWS: # Windows users expect to be able to execute files in the same # directory without `./` cwd = _get_cwd() if os.path.isfile(name): return os.path.abspath(os.path.relpath(name, cwd)) + exts = builtins.__xonsh_env__['PATHEXT'] for ext in exts: namext = name + ext if os.path.isfile(namext): return os.path.abspath(os.path.relpath(namext, cwd)) - elif os.path.isfile(name) and name != os.path.basename(name): - return name - cc = builtins.__xonsh_commands_cache__ - if ON_WINDOWS: - upname = name.upper() - if upname in cc: - return cc.lazyget(upname)[0] - for ext in exts: - upnamext = upname + ext - if cc.lazyin(upnamext): - return cc.lazyget(upnamext)[0] - elif name in cc: + + if name in cc: # can be lazy here since we know name is already available return cc.lazyget(name)[0] + elif os.path.isfile(name) and name != os.path.basename(name): + return name def get_git_branch(): @@ -1037,7 +1033,7 @@ def dirty_working_directory(cwd=None): def branch_color(): """Return red if the current branch is dirty, yellow if the dirtiness can - not be determined, and green if it clean. Thes are bold, intesnse colors + not be determined, and green if it clean. These are bold, intense colors for the foreground. """ dwd = dirty_working_directory() diff --git a/xonsh/tools.py b/xonsh/tools.py index abd24416b..92f346cfd 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1564,8 +1564,18 @@ class CommandsCache(abc.Mapping): self._alias_checksum = None self._path_mtime = -1 + def __get_possible_names(self, key): + if ON_WINDOWS: + return { + name + ext + for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) + for name in (key, key.upper()) + } + else: + return { key, } + def __contains__(self, key): - return key in self.all_commands + return bool(self.__get_possible_names(key) & self.all_commands.keys()) def __iter__(self): return iter(self.all_commands) @@ -1574,7 +1584,8 @@ class CommandsCache(abc.Mapping): return len(self.all_commands) def __getitem__(self, key): - return self.all_commands[key] + possibilities = self.__get_possible_names(key) + return self.all_commands[next(possibilities & self.all_commands.keys())] @property def all_commands(self): @@ -1599,6 +1610,7 @@ class CommandsCache(abc.Mapping): self._path_mtime = max_mtime if cache_valid: return self._cmds_cache + allcmds = {} for path in reversed(paths): # iterate backwards so that entries at the front of PATH overwrite @@ -1606,6 +1618,7 @@ class CommandsCache(abc.Mapping): for cmd in executables_in(path): key = cmd.upper() if ON_WINDOWS else cmd allcmds[key] = (os.path.join(path, cmd), cmd in alss) + only_alias = (None, True) for cmd in alss: if cmd not in allcmds: @@ -1613,12 +1626,13 @@ class CommandsCache(abc.Mapping): self._cmds_cache = allcmds return allcmds - def lazyin(self, value): + def lazyin(self, key): """Checks if the value is in the current cache without the potential to update the cache. It just says whether the value is known *now*. This may not reflect precisely what is on the $PATH. """ - return value in self._cmds_cache + + return bool(self.__get_possible_names(key) & self._cmds_cache.keys()) def lazyiter(self): """Returns an iterator over the current cache contents without the @@ -1636,7 +1650,9 @@ class CommandsCache(abc.Mapping): def lazyget(self, key, default=None): """A lazy value getter.""" - return self._cmds_cache.get(key, default) + possibilities = self.__get_possible_names(key) + matches = possibilities & self._cmds_cache.keys() + return self._cmds_cache[matches.pop()] if matches else default WINDOWS_DRIVE_MATCHER = LazyObject(lambda: re.compile(r'^\w:'), From d789a137f50c2aa2d64c9b1a2516b87423c3a17c Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 01:05:57 +0300 Subject: [PATCH 76/95] Slightly better code --- xonsh/tools.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xonsh/tools.py b/xonsh/tools.py index 92f346cfd..4bc783ddf 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1564,7 +1564,8 @@ class CommandsCache(abc.Mapping): self._alias_checksum = None self._path_mtime = -1 - def __get_possible_names(self, key): + @staticmethod + def get_possible_names(key): if ON_WINDOWS: return { name + ext @@ -1572,10 +1573,10 @@ class CommandsCache(abc.Mapping): for name in (key, key.upper()) } else: - return { key, } + return {key} def __contains__(self, key): - return bool(self.__get_possible_names(key) & self.all_commands.keys()) + return bool(self.get_possible_names(key) & self.all_commands.keys()) def __iter__(self): return iter(self.all_commands) @@ -1584,7 +1585,7 @@ class CommandsCache(abc.Mapping): return len(self.all_commands) def __getitem__(self, key): - possibilities = self.__get_possible_names(key) + possibilities = self.get_possible_names(key) return self.all_commands[next(possibilities & self.all_commands.keys())] @property @@ -1632,7 +1633,7 @@ class CommandsCache(abc.Mapping): may not reflect precisely what is on the $PATH. """ - return bool(self.__get_possible_names(key) & self._cmds_cache.keys()) + return bool(self.get_possible_names(key) & self._cmds_cache.keys()) def lazyiter(self): """Returns an iterator over the current cache contents without the @@ -1650,7 +1651,7 @@ class CommandsCache(abc.Mapping): def lazyget(self, key, default=None): """A lazy value getter.""" - possibilities = self.__get_possible_names(key) + possibilities = self.get_possible_names(key) matches = possibilities & self._cmds_cache.keys() return self._cmds_cache[matches.pop()] if matches else default From 9b4655ab288c6a6f0b273a364d999b8cdca3a130 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 01:20:08 +0300 Subject: [PATCH 77/95] Even simpler code and bug fix --- xonsh/environ.py | 23 ++++++++++------------- xonsh/tools.py | 7 ++++--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index 5327a3916..08b66cd9c 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -824,26 +824,23 @@ def _yield_executables(directory, name): def locate_binary(name): """Locates an executable on the file system.""" - cc = builtins.__xonsh_commands_cache__ + cache = builtins.__xonsh_commands_cache__ if ON_WINDOWS: # Windows users expect to be able to execute files in the same # directory without `./` cwd = _get_cwd() - if os.path.isfile(name): - return os.path.abspath(os.path.relpath(name, cwd)) - exts = builtins.__xonsh_env__['PATHEXT'] - for ext in exts: - namext = name + ext - if os.path.isfile(namext): - return os.path.abspath(os.path.relpath(namext, cwd)) + local_bins = [full_name for full_name in cache.get_possible_names(name) + if os.path.isfile(full_name)] + if local_bins: + return os.path.abspath(os.path.relpath(local_bins[0], cwd)) - if name in cc: - # can be lazy here since we know name is already available - return cc.lazyget(name)[0] - elif os.path.isfile(name) and name != os.path.basename(name): - return name + return builtins.__xonsh_commands_cache__.get( + name, + (name, False) if os.path.isfile(name) and name != os.path.basename(name) + else (None, None) + )[0] def get_git_branch(): diff --git a/xonsh/tools.py b/xonsh/tools.py index 4bc783ddf..dc927730f 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1567,10 +1567,10 @@ class CommandsCache(abc.Mapping): @staticmethod def get_possible_names(key): if ON_WINDOWS: + key = key.upper() return { - name + ext + key + ext for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) - for name in (key, key.upper()) } else: return {key} @@ -1586,7 +1586,8 @@ class CommandsCache(abc.Mapping): def __getitem__(self, key): possibilities = self.get_possible_names(key) - return self.all_commands[next(possibilities & self.all_commands.keys())] + matches = possibilities & self.all_commands.keys() + return self.all_commands[matches.pop()] @property def all_commands(self): From 384ced670095eb07279563724f51299b9f266073 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 01:46:23 +0300 Subject: [PATCH 78/95] Move locate_binary to CommandsCache --- xonsh/built_ins.py | 4 ++-- xonsh/environ.py | 27 +++++---------------------- xonsh/tools.py | 43 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index a3667b7c1..11a628465 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -455,8 +455,8 @@ def run_subproc(cmds, captured=False): if (stdin is not None and ENV.get('XONSH_STORE_STDIN') and captured == 'object' and - 'cat' in __xonsh_commands_cache__ and - 'tee' in __xonsh_commands_cache__): + __xonsh_commands_cache__.locate_binary('cat') and + __xonsh_commands_cache__.locate_binary('tee')): _stdin_file = tempfile.NamedTemporaryFile() cproc = Popen(['cat'], stdin=stdin, diff --git a/xonsh/environ.py b/xonsh/environ.py index 08b66cd9c..0da52d281 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -823,24 +823,7 @@ def _yield_executables(directory, name): def locate_binary(name): """Locates an executable on the file system.""" - - cache = builtins.__xonsh_commands_cache__ - - if ON_WINDOWS: - # Windows users expect to be able to execute files in the same - # directory without `./` - cwd = _get_cwd() - - local_bins = [full_name for full_name in cache.get_possible_names(name) - if os.path.isfile(full_name)] - if local_bins: - return os.path.abspath(os.path.relpath(local_bins[0], cwd)) - - return builtins.__xonsh_commands_cache__.get( - name, - (name, False) if os.path.isfile(name) and name != os.path.basename(name) - else (None, None) - )[0] + return builtins.__xonsh_commands_cache__.locate_binary(name) def get_git_branch(): @@ -955,9 +938,9 @@ def current_branch(pad=True): """ branch = '' cmds = builtins.__xonsh_commands_cache__ - if cmds.lazyin('git') or cmds.lazylen() == 0: + if cmds.lazy_locate_binary('git') or cmds.lazylen() == 0: branch = get_git_branch() - if (cmds.lazyin('hg') or cmds.lazylen() == 0) and not branch: + if (cmds.lazy_locate_binary('hg') or cmds.lazylen() == 0) and not branch: branch = get_hg_branch() if isinstance(branch, subprocess.TimeoutExpired): branch = '' @@ -1021,9 +1004,9 @@ def dirty_working_directory(cwd=None): """ dwd = None cmds = builtins.__xonsh_commands_cache__ - if cmds.lazyin('git') or cmds.lazylen() == 0: + if cmds.lazy_locate_binary('git') or cmds.lazylen() == 0: dwd = git_dirty_working_directory() - if (cmds.lazyin('hg') or cmds.lazylen() == 0) and (dwd is None): + if (cmds.lazy_locate_binary('hg') or cmds.lazylen() == 0) and (dwd is None): dwd = hg_dirty_working_directory() return dwd diff --git a/xonsh/tools.py b/xonsh/tools.py index dc927730f..b91bfb958 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1576,7 +1576,7 @@ class CommandsCache(abc.Mapping): return {key} def __contains__(self, key): - return bool(self.get_possible_names(key) & self.all_commands.keys()) + return key in self.all_commands def __iter__(self): return iter(self.all_commands) @@ -1585,9 +1585,7 @@ class CommandsCache(abc.Mapping): return len(self.all_commands) def __getitem__(self, key): - possibilities = self.get_possible_names(key) - matches = possibilities & self.all_commands.keys() - return self.all_commands[matches.pop()] + return self.all_commands[key] @property def all_commands(self): @@ -1633,8 +1631,7 @@ class CommandsCache(abc.Mapping): update the cache. It just says whether the value is known *now*. This may not reflect precisely what is on the $PATH. """ - - return bool(self.get_possible_names(key) & self._cmds_cache.keys()) + return key in self._cmds_cache def lazyiter(self): """Returns an iterator over the current cache contents without the @@ -1652,9 +1649,39 @@ class CommandsCache(abc.Mapping): def lazyget(self, key, default=None): """A lazy value getter.""" - possibilities = self.get_possible_names(key) + return self._cmds_cache.get(key, default) + + def locate_binary(self, name): + """Locates an executable on the file system.""" + + if ON_WINDOWS: + # Windows users expect to be able to execute files in the same + # directory without `./` + cwd = _get_cwd() + + local_bins = [full_name for full_name in self.get_possible_names(name) + if os.path.isfile(full_name)] + if local_bins: + return os.path.abspath(os.path.relpath(local_bins[0], cwd)) + + possibilities = self.get_possible_names(name) + matches = possibilities & self.all_commands.keys() + + if matches: + return self.all_commands[matches.pop()][0] + elif os.path.isfile(name) and name != os.path.basename(name): + return name + + def lazy_locate_binary(self, name): + """Locates an executable in the cache.""" + + possibilities = self.get_possible_names(name) matches = possibilities & self._cmds_cache.keys() - return self._cmds_cache[matches.pop()] if matches else default + + if matches: + return self._cmds_cache[matches.pop()][0] + elif os.path.isfile(name) and name != os.path.basename(name): + return name WINDOWS_DRIVE_MATCHER = LazyObject(lambda: re.compile(r'^\w:'), From 858cb6ea1e3a54e1f783793d158555fb48b004ed Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 02:44:41 +0300 Subject: [PATCH 79/95] Respect PATHEXT ordering and improve perf --- xonsh/built_ins.py | 4 ++-- xonsh/environ.py | 20 ++++++++++--------- xonsh/tools.py | 48 +++++++++++++++++++++++++--------------------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index 11a628465..4e0a007e5 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -455,8 +455,8 @@ def run_subproc(cmds, captured=False): if (stdin is not None and ENV.get('XONSH_STORE_STDIN') and captured == 'object' and - __xonsh_commands_cache__.locate_binary('cat') and - __xonsh_commands_cache__.locate_binary('tee')): + __xonsh_commands_cache__.lazy_locate_binary('cat') and + __xonsh_commands_cache__.lazy_locate_binary('tee')): _stdin_file = tempfile.NamedTemporaryFile() cproc = Popen(['cat'], stdin=stdin, diff --git a/xonsh/environ.py b/xonsh/environ.py index 0da52d281..da61a52b5 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -7,7 +7,6 @@ import json import locale import builtins from contextlib import contextmanager -from functools import wraps from itertools import chain from pprint import pformat import re @@ -16,30 +15,33 @@ import string import subprocess import shutil from warnings import warn -from collections import (Mapping, MutableMapping, MutableSequence, MutableSet, - namedtuple) +from collections import ( + Mapping, MutableMapping, MutableSequence, MutableSet, + namedtuple +) from xonsh import __version__ as XONSH_VERSION from xonsh.jobs import get_next_task from xonsh.codecache import run_script_with_cache from xonsh.dirstack import _get_cwd from xonsh.foreign_shells import load_foreign_envs -from xonsh.platform import (BASH_COMPLETIONS_DEFAULT, ON_ANACONDA, ON_LINUX, - ON_WINDOWS, DEFAULT_ENCODING, ON_CYGWIN, PATH_DEFAULT) +from xonsh.platform import ( + BASH_COMPLETIONS_DEFAULT, DEFAULT_ENCODING, PATH_DEFAULT, + ON_WINDOWS, ON_ANACONDA, ON_LINUX, ON_CYGWIN, +) from xonsh.tools import ( is_superuser, always_true, always_false, ensure_string, is_env_path, str_to_env_path, env_path_to_str, is_bool, to_bool, bool_to_str, is_history_tuple, to_history_tuple, history_tuple_to_str, is_float, - is_string, is_callable, is_string_or_callable, + is_string, is_string_or_callable, is_completions_display_value, to_completions_display_value, is_string_set, csv_to_set, set_to_csv, get_sep, is_int, is_bool_seq, - is_bool_or_int, to_bool_or_int, bool_or_int_to_str, + to_bool_or_int, bool_or_int_to_str, csv_to_bool_seq, bool_seq_to_csv, DefaultNotGiven, print_exception, setup_win_unicode_console, intensify_colors_on_win_setter, format_color, is_dynamic_cwd_width, to_dynamic_cwd_tuple, dynamic_cwd_tuple_to_str, is_logfile_opt, to_logfile_opt, logfile_opt_to_str, executables_in, - pathsep_to_set, set_to_pathsep, pathsep_to_seq, seq_to_pathsep, - is_string_seq, is_nonstring_seq_of_strings, pathsep_to_upper_seq, + is_nonstring_seq_of_strings, pathsep_to_upper_seq, seq_to_upper_pathsep, ) diff --git a/xonsh/tools.py b/xonsh/tools.py index b91bfb958..34b27f42c 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -20,7 +20,6 @@ Implementations: import os import re import sys -import ast import glob import string import ctypes @@ -36,11 +35,14 @@ import collections.abc as abc from contextlib import contextmanager from subprocess import CalledProcessError -# adding further imports from xonsh modules is discouraged to avoid cirular +# adding further imports from xonsh modules is discouraged to avoid circular # dependencies from xonsh.lazyasd import LazyObject, LazyDict -from xonsh.platform import (has_prompt_toolkit, scandir, - DEFAULT_ENCODING, ON_LINUX, ON_WINDOWS, PYTHON_VERSION_INFO) +from xonsh.platform import ( + has_prompt_toolkit, scandir, + DEFAULT_ENCODING, ON_LINUX, ON_WINDOWS, PYTHON_VERSION_INFO, +) + @functools.lru_cache(1) def is_superuser(): @@ -1568,12 +1570,12 @@ class CommandsCache(abc.Mapping): def get_possible_names(key): if ON_WINDOWS: key = key.upper() - return { + return [ key + ext for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) - } + ] else: - return {key} + return [key] def __contains__(self, key): return key in self.all_commands @@ -1652,34 +1654,36 @@ class CommandsCache(abc.Mapping): return self._cmds_cache.get(key, default) def locate_binary(self, name): - """Locates an executable on the file system.""" + """Locates an executable on the file system using the cache.""" + possibilities = self.get_possible_names(name) if ON_WINDOWS: + from xonsh.dirstack import _get_cwd # circular dependency # Windows users expect to be able to execute files in the same # directory without `./` cwd = _get_cwd() - local_bins = [full_name for full_name in self.get_possible_names(name) - if os.path.isfile(full_name)] - if local_bins: - return os.path.abspath(os.path.relpath(local_bins[0], cwd)) + local_bin = next(( + full_name for full_name in possibilities + if os.path.isfile(full_name) + ), None) - possibilities = self.get_possible_names(name) - matches = possibilities & self.all_commands.keys() + if local_bin: + return os.path.abspath(os.path.relpath(local_bin, cwd)) - if matches: - return self.all_commands[matches.pop()][0] + cmds = self.all_commands + cached = next((cmd for cmd in possibilities if cmd in cmds), None) + if cached: + return cmds[cached][0] elif os.path.isfile(name) and name != os.path.basename(name): return name def lazy_locate_binary(self, name): - """Locates an executable in the cache.""" - + """Locates an executable in the cache, without invalidating it.""" possibilities = self.get_possible_names(name) - matches = possibilities & self._cmds_cache.keys() - - if matches: - return self._cmds_cache[matches.pop()][0] + cached = next((cmd for cmd in possibilities if cmd in self._cmds_cache), None) + if cached: + return self._cmds_cache[cached][0] elif os.path.isfile(name) and name != os.path.basename(name): return name From acd372a3a1de5c9d8031b1aaa0431a5819d1cb9b Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 02:48:38 +0300 Subject: [PATCH 80/95] Add `is_empty()` to commands cache --- xonsh/environ.py | 10 +++++----- xonsh/tools.py | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index da61a52b5..d81923578 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -935,14 +935,14 @@ def _first_branch_timeout_message(): def current_branch(pad=True): """Gets the branch for a current working directory. Returns an empty string if the cwd is not a repository. This currently only works for git and hg - and should be extended in the future. If a timeout occured, the string + and should be extended in the future. If a timeout occurred, the string '' is returned. """ branch = '' cmds = builtins.__xonsh_commands_cache__ - if cmds.lazy_locate_binary('git') or cmds.lazylen() == 0: + if cmds.lazy_locate_binary('git') or cmds.is_empty(): branch = get_git_branch() - if (cmds.lazy_locate_binary('hg') or cmds.lazylen() == 0) and not branch: + if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch: branch = get_hg_branch() if isinstance(branch, subprocess.TimeoutExpired): branch = '' @@ -1006,9 +1006,9 @@ def dirty_working_directory(cwd=None): """ dwd = None cmds = builtins.__xonsh_commands_cache__ - if cmds.lazy_locate_binary('git') or cmds.lazylen() == 0: + if cmds.lazy_locate_binary('git') or cmds.is_empty(): dwd = git_dirty_working_directory() - if (cmds.lazy_locate_binary('hg') or cmds.lazylen() == 0) and (dwd is None): + if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and (dwd is None): dwd = hg_dirty_working_directory() return dwd diff --git a/xonsh/tools.py b/xonsh/tools.py index 34b27f42c..a20c77d6a 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1566,17 +1566,6 @@ class CommandsCache(abc.Mapping): self._alias_checksum = None self._path_mtime = -1 - @staticmethod - def get_possible_names(key): - if ON_WINDOWS: - key = key.upper() - return [ - key + ext - for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) - ] - else: - return [key] - def __contains__(self, key): return key in self.all_commands @@ -1589,6 +1578,20 @@ class CommandsCache(abc.Mapping): def __getitem__(self, key): return self.all_commands[key] + def is_empty(self): + return len(self._cmds_cache) == 0 + + @staticmethod + def get_possible_names(key): + if ON_WINDOWS: + key = key.upper() + return [ + key + ext + for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) + ] + else: + return [key] + @property def all_commands(self): paths = builtins.__xonsh_env__.get('PATH', []) From 4193e40ee1dc8299ef6d3eb4302d06768d08caea Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 12:29:07 +0300 Subject: [PATCH 81/95] Remove some empty lines and add docstrings --- xonsh/tools.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xonsh/tools.py b/xonsh/tools.py index a20c77d6a..aa0ba305d 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1579,18 +1579,22 @@ class CommandsCache(abc.Mapping): return self.all_commands[key] def is_empty(self): + """Returns whether the cache is populated or not. Does not invalidate.""" return len(self._cmds_cache) == 0 @staticmethod - def get_possible_names(key): + def get_possible_names(name): + """Generates the possible `PATHEXT` extension variants of a given executable + name on Windows as a list, conserving the ordering in `PATHEXT`. + Returns a list as `name` being the only item in it on other platforms.""" if ON_WINDOWS: - key = key.upper() + name = name.upper() return [ - key + ext + name + ext for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) ] else: - return [key] + return [name] @property def all_commands(self): @@ -1615,7 +1619,6 @@ class CommandsCache(abc.Mapping): self._path_mtime = max_mtime if cache_valid: return self._cmds_cache - allcmds = {} for path in reversed(paths): # iterate backwards so that entries at the front of PATH overwrite @@ -1623,7 +1626,6 @@ class CommandsCache(abc.Mapping): for cmd in executables_in(path): key = cmd.upper() if ON_WINDOWS else cmd allcmds[key] = (os.path.join(path, cmd), cmd in alss) - only_alias = (None, True) for cmd in alss: if cmd not in allcmds: @@ -1647,7 +1649,7 @@ class CommandsCache(abc.Mapping): def lazylen(self): """Returns the length of the current cache contents without the - potential to update the cache. This may not reflect precicesly + potential to update the cache. This may not reflect precisely what is on the $PATH. """ return len(self._cmds_cache) @@ -1665,12 +1667,10 @@ class CommandsCache(abc.Mapping): # Windows users expect to be able to execute files in the same # directory without `./` cwd = _get_cwd() - local_bin = next(( full_name for full_name in possibilities if os.path.isfile(full_name) ), None) - if local_bin: return os.path.abspath(os.path.relpath(local_bin, cwd)) @@ -1696,7 +1696,7 @@ WINDOWS_DRIVE_MATCHER = LazyObject(lambda: re.compile(r'^\w:'), def expand_case_matching(s): - """Expands a string to a case insenstive globable string.""" + """Expands a string to a case insensitive globable string.""" t = [] openers = {'[', '{'} closers = {']', '}'} From 00b3f2220e78a07037e0396cef149fd74ea42eae Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 18:06:55 +0300 Subject: [PATCH 82/95] Make `lazy_locate_binary` be consistent with `locate_binary` --- xonsh/tools.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/xonsh/tools.py b/xonsh/tools.py index aa0ba305d..38579140e 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1660,6 +1660,12 @@ class CommandsCache(abc.Mapping): def locate_binary(self, name): """Locates an executable on the file system using the cache.""" + # invalidate the cache by accessing this property + _ = self.all_commands + return self.lazy_locate_binary(name) + + def lazy_locate_binary(self, name): + """Locates an executable in the cache, without invalidating it.""" possibilities = self.get_possible_names(name) if ON_WINDOWS: @@ -1674,16 +1680,6 @@ class CommandsCache(abc.Mapping): if local_bin: return os.path.abspath(os.path.relpath(local_bin, cwd)) - cmds = self.all_commands - cached = next((cmd for cmd in possibilities if cmd in cmds), None) - if cached: - return cmds[cached][0] - elif os.path.isfile(name) and name != os.path.basename(name): - return name - - def lazy_locate_binary(self, name): - """Locates an executable in the cache, without invalidating it.""" - possibilities = self.get_possible_names(name) cached = next((cmd for cmd in possibilities if cmd in self._cmds_cache), None) if cached: return self._cmds_cache[cached][0] From e6643622c0fe52333d81798e1326f16b62ffb2fd Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 19:49:37 +0300 Subject: [PATCH 83/95] Don't use the word "invalidate" --- xonsh/tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xonsh/tools.py b/xonsh/tools.py index 38579140e..5690aa339 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1579,7 +1579,7 @@ class CommandsCache(abc.Mapping): return self.all_commands[key] def is_empty(self): - """Returns whether the cache is populated or not. Does not invalidate.""" + """Returns whether the cache is populated or not. Does not check cache validity.""" return len(self._cmds_cache) == 0 @staticmethod @@ -1660,12 +1660,12 @@ class CommandsCache(abc.Mapping): def locate_binary(self, name): """Locates an executable on the file system using the cache.""" - # invalidate the cache by accessing this property + # make sure the cache is up to date by accessing the property _ = self.all_commands return self.lazy_locate_binary(name) def lazy_locate_binary(self, name): - """Locates an executable in the cache, without invalidating it.""" + """Locates an executable in the cache, without checking its validity.""" possibilities = self.get_possible_names(name) if ON_WINDOWS: From eda60048b14e382cd017d158ce737c5073e40eb8 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 19:56:20 +0300 Subject: [PATCH 84/95] Extract CommandsCache to its own module --- tests/test_tools.py | 5 +- xonsh/__init__.py | 2 + xonsh/built_ins.py | 3 +- xonsh/commands_cache.py | 140 +++++++++++++++++++++++++++++++++++ xonsh/tools.py | 159 +++------------------------------------- 5 files changed, 158 insertions(+), 151 deletions(-) create mode 100644 xonsh/commands_cache.py diff --git a/tests/test_tools.py b/tests/test_tools.py index 58587e477..affc79fa6 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -11,7 +11,7 @@ from xonsh.platform import ON_WINDOWS from xonsh.lexer import Lexer from xonsh.tools import ( - CommandsCache, EnvPath, always_false, always_true, argvquote, + EnvPath, always_false, always_true, argvquote, bool_or_int_to_str, bool_to_str, check_for_partial_string, dynamic_cwd_tuple_to_str, ensure_int_or_slice, ensure_string, env_path_to_str, escape_windows_cmd_string, executables_in, @@ -24,8 +24,7 @@ from xonsh.tools import ( is_string_seq, pathsep_to_seq, seq_to_pathsep, is_nonstring_seq_of_strings, pathsep_to_upper_seq, seq_to_upper_pathsep, ) - -from tools import mock_xonsh_env +from xonsh.commands_cache import CommandsCache from tools import mock_xonsh_env diff --git a/xonsh/__init__.py b/xonsh/__init__.py index f858095ac..5b356d2d6 100644 --- a/xonsh/__init__.py +++ b/xonsh/__init__.py @@ -57,6 +57,8 @@ else: _sys.modules['xonsh.proc'] = __amalgam__ xontribs = __amalgam__ _sys.modules['xonsh.xontribs'] = __amalgam__ + commands_cache = __amalgam__ + _sys.modules['xonsh.commands_cache'] = __amalgam__ environ = __amalgam__ _sys.modules['xonsh.environ'] = __amalgam__ history = __amalgam__ diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index 4e0a007e5..a89e1a719 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -32,9 +32,10 @@ from xonsh.proc import (ProcProxy, SimpleProcProxy, ForegroundProcProxy, SimpleForegroundProcProxy, TeePTYProc, CompletedCommand, HiddenCompletedCommand) from xonsh.tools import ( - suggest_commands, expandvars, CommandsCache, globpath, XonshError, + suggest_commands, expandvars, globpath, XonshError, XonshCalledProcessError, XonshBlockError ) +from xonsh.commands_cache import CommandsCache ENV = None diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py new file mode 100644 index 000000000..be98656ca --- /dev/null +++ b/xonsh/commands_cache.py @@ -0,0 +1,140 @@ +import os +from collections import abc as abc + +from xonsh.dirstack import _get_cwd +from xonsh.platform import ON_WINDOWS +from xonsh.tools import executables_in + + +class CommandsCache(abc.Mapping): + """A lazy cache representing the commands available on the file system. + The keys are the command names and the values a tuple of (loc, has_alias) + where loc is either a str pointing to the executable on the file system or + None (if no executable exists) and has_alias is a boolean flag for whether + the command has an alias. + """ + + def __init__(self): + self._cmds_cache = {} + self._path_checksum = None + self._alias_checksum = None + self._path_mtime = -1 + + def __contains__(self, key): + return key in self.all_commands + + def __iter__(self): + return iter(self.all_commands) + + def __len__(self): + return len(self.all_commands) + + def __getitem__(self, key): + return self.all_commands[key] + + def is_empty(self): + """Returns whether the cache is populated or not. Does not check cache validity.""" + return len(self._cmds_cache) == 0 + + @staticmethod + def get_possible_names(name): + """Generates the possible `PATHEXT` extension variants of a given executable + name on Windows as a list, conserving the ordering in `PATHEXT`. + Returns a list as `name` being the only item in it on other platforms.""" + if ON_WINDOWS: + name = name.upper() + return [ + name + ext + for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) + ] + else: + return [name] + + @property + def all_commands(self): + paths = builtins.__xonsh_env__.get('PATH', []) + pathset = frozenset(x for x in paths if os.path.isdir(x)) + # did PATH change? + path_hash = hash(pathset) + cache_valid = path_hash == self._path_checksum + self._path_checksum = path_hash + # did aliases change? + alss = getattr(builtins, 'aliases', set()) + al_hash = hash(frozenset(alss)) + cache_valid = cache_valid and al_hash == self._alias_checksum + self._alias_checksum = al_hash + # did the contents of any directory in PATH change? + max_mtime = 0 + for path in pathset: + mtime = os.stat(path).st_mtime + if mtime > max_mtime: + max_mtime = mtime + cache_valid = cache_valid and (max_mtime <= self._path_mtime) + self._path_mtime = max_mtime + if cache_valid: + return self._cmds_cache + allcmds = {} + for path in reversed(paths): + # iterate backwards so that entries at the front of PATH overwrite + # entries at the back. + for cmd in executables_in(path): + key = cmd.upper() if ON_WINDOWS else cmd + allcmds[key] = (os.path.join(path, cmd), cmd in alss) + only_alias = (None, True) + for cmd in alss: + if cmd not in allcmds: + allcmds[cmd] = only_alias + self._cmds_cache = allcmds + return allcmds + + def lazyin(self, key): + """Checks if the value is in the current cache without the potential to + update the cache. It just says whether the value is known *now*. This + may not reflect precisely what is on the $PATH. + """ + return key in self._cmds_cache + + def lazyiter(self): + """Returns an iterator over the current cache contents without the + potential to update the cache. This may not reflect what is on the + $PATH. + """ + return iter(self._cmds_cache) + + def lazylen(self): + """Returns the length of the current cache contents without the + potential to update the cache. This may not reflect precisely + what is on the $PATH. + """ + return len(self._cmds_cache) + + def lazyget(self, key, default=None): + """A lazy value getter.""" + return self._cmds_cache.get(key, default) + + def locate_binary(self, name): + """Locates an executable on the file system using the cache.""" + # make sure the cache is up to date by accessing the property + _ = self.all_commands + return self.lazy_locate_binary(name) + + def lazy_locate_binary(self, name): + """Locates an executable in the cache, without checking its validity.""" + possibilities = self.get_possible_names(name) + + if ON_WINDOWS: + # Windows users expect to be able to execute files in the same + # directory without `./` + cwd = _get_cwd() + local_bin = next(( + full_name for full_name in possibilities + if os.path.isfile(full_name) + ), None) + if local_bin: + return os.path.abspath(os.path.relpath(local_bin, cwd)) + + cached = next((cmd for cmd in possibilities if cmd in self._cmds_cache), None) + if cached: + return self._cmds_cache[cached][0] + elif os.path.isfile(name) and name != os.path.basename(name): + return name diff --git a/xonsh/tools.py b/xonsh/tools.py index 5690aa339..86875fa08 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -17,21 +17,21 @@ Implementations: * indent() """ -import os -import re -import sys -import glob -import string -import ctypes import builtins -import pathlib -import warnings -import functools -import threading -import traceback -import subprocess import collections import collections.abc as abc +import ctypes +import functools +import glob +import os +import pathlib +import re +import string +import subprocess +import sys +import threading +import traceback +import warnings from contextlib import contextmanager from subprocess import CalledProcessError @@ -1552,141 +1552,6 @@ def expanduser_abs_path(inp): return os.path.abspath(os.path.expanduser(inp)) -class CommandsCache(abc.Mapping): - """A lazy cache representing the commands available on the file system. - The keys are the command names and the values a tuple of (loc, has_alias) - where loc is either a str pointing to the executable on the file system or - None (if no executable exists) and has_alias is a boolean flag for whether - the command has an alias. - """ - - def __init__(self): - self._cmds_cache = {} - self._path_checksum = None - self._alias_checksum = None - self._path_mtime = -1 - - def __contains__(self, key): - return key in self.all_commands - - def __iter__(self): - return iter(self.all_commands) - - def __len__(self): - return len(self.all_commands) - - def __getitem__(self, key): - return self.all_commands[key] - - def is_empty(self): - """Returns whether the cache is populated or not. Does not check cache validity.""" - return len(self._cmds_cache) == 0 - - @staticmethod - def get_possible_names(name): - """Generates the possible `PATHEXT` extension variants of a given executable - name on Windows as a list, conserving the ordering in `PATHEXT`. - Returns a list as `name` being the only item in it on other platforms.""" - if ON_WINDOWS: - name = name.upper() - return [ - name + ext - for ext in ([''] + builtins.__xonsh_env__['PATHEXT']) - ] - else: - return [name] - - @property - def all_commands(self): - paths = builtins.__xonsh_env__.get('PATH', []) - pathset = frozenset(x for x in paths if os.path.isdir(x)) - # did PATH change? - path_hash = hash(pathset) - cache_valid = path_hash == self._path_checksum - self._path_checksum = path_hash - # did aliases change? - alss = getattr(builtins, 'aliases', set()) - al_hash = hash(frozenset(alss)) - cache_valid = cache_valid and al_hash == self._alias_checksum - self._alias_checksum = al_hash - # did the contents of any directory in PATH change? - max_mtime = 0 - for path in pathset: - mtime = os.stat(path).st_mtime - if mtime > max_mtime: - max_mtime = mtime - cache_valid = cache_valid and (max_mtime <= self._path_mtime) - self._path_mtime = max_mtime - if cache_valid: - return self._cmds_cache - allcmds = {} - for path in reversed(paths): - # iterate backwards so that entries at the front of PATH overwrite - # entries at the back. - for cmd in executables_in(path): - key = cmd.upper() if ON_WINDOWS else cmd - allcmds[key] = (os.path.join(path, cmd), cmd in alss) - only_alias = (None, True) - for cmd in alss: - if cmd not in allcmds: - allcmds[cmd] = only_alias - self._cmds_cache = allcmds - return allcmds - - def lazyin(self, key): - """Checks if the value is in the current cache without the potential to - update the cache. It just says whether the value is known *now*. This - may not reflect precisely what is on the $PATH. - """ - return key in self._cmds_cache - - def lazyiter(self): - """Returns an iterator over the current cache contents without the - potential to update the cache. This may not reflect what is on the - $PATH. - """ - return iter(self._cmds_cache) - - def lazylen(self): - """Returns the length of the current cache contents without the - potential to update the cache. This may not reflect precisely - what is on the $PATH. - """ - return len(self._cmds_cache) - - def lazyget(self, key, default=None): - """A lazy value getter.""" - return self._cmds_cache.get(key, default) - - def locate_binary(self, name): - """Locates an executable on the file system using the cache.""" - # make sure the cache is up to date by accessing the property - _ = self.all_commands - return self.lazy_locate_binary(name) - - def lazy_locate_binary(self, name): - """Locates an executable in the cache, without checking its validity.""" - possibilities = self.get_possible_names(name) - - if ON_WINDOWS: - from xonsh.dirstack import _get_cwd # circular dependency - # Windows users expect to be able to execute files in the same - # directory without `./` - cwd = _get_cwd() - local_bin = next(( - full_name for full_name in possibilities - if os.path.isfile(full_name) - ), None) - if local_bin: - return os.path.abspath(os.path.relpath(local_bin, cwd)) - - cached = next((cmd for cmd in possibilities if cmd in self._cmds_cache), None) - if cached: - return self._cmds_cache[cached][0] - elif os.path.isfile(name) and name != os.path.basename(name): - return name - - WINDOWS_DRIVE_MATCHER = LazyObject(lambda: re.compile(r'^\w:'), globals(), 'WINDOWS_DRIVE_MATCHER') From 1c3a59d1813a4880c49199112484453de8550600 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 19:58:03 +0300 Subject: [PATCH 85/95] Extract CommandsCache to its own module --- xonsh/commands_cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py index be98656ca..fd4bf27a1 100644 --- a/xonsh/commands_cache.py +++ b/xonsh/commands_cache.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +import builtins import os from collections import abc as abc @@ -33,7 +35,7 @@ class CommandsCache(abc.Mapping): return self.all_commands[key] def is_empty(self): - """Returns whether the cache is populated or not. Does not check cache validity.""" + """Returns whether the cache is populated or not.""" return len(self._cmds_cache) == 0 @staticmethod From d3bb55de14d233e67db138ba3908647c2fec3d5a Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 20:25:09 +0300 Subject: [PATCH 86/95] Better import --- xonsh/built_ins.py | 2 -- xonsh/commands_cache.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py index a89e1a719..41dd209f5 100644 --- a/xonsh/built_ins.py +++ b/xonsh/built_ins.py @@ -9,7 +9,6 @@ import builtins from collections import Sequence from contextlib import contextmanager import inspect -from glob import iglob import os import re import shlex @@ -21,7 +20,6 @@ import time from xonsh.lazyasd import LazyObject from xonsh.history import History -from xonsh.tokenize import SearchPath from xonsh.inspectors import Inspector from xonsh.aliases import Aliases, make_default_aliases from xonsh.environ import Env, default_env, locate_binary diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py index fd4bf27a1..3be182383 100644 --- a/xonsh/commands_cache.py +++ b/xonsh/commands_cache.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import builtins import os -from collections import abc as abc +import collections.abc as abc from xonsh.dirstack import _get_cwd from xonsh.platform import ON_WINDOWS From b2f7ebb58c8c00108179d730183dd01954c116ec Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 24 Jun 2016 20:26:50 +0300 Subject: [PATCH 87/95] Add stub docs for the new commands_cache module --- docs/api/commands_cache.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docs/api/commands_cache.rst diff --git a/docs/api/commands_cache.rst b/docs/api/commands_cache.rst new file mode 100644 index 000000000..489999c72 --- /dev/null +++ b/docs/api/commands_cache.rst @@ -0,0 +1,10 @@ +.. _xonsh_commands_cache: + +****************************************************** +CommandsCache (``xonsh.commands_cache``) +****************************************************** + +.. automodule:: xonsh.commands_cache + :members: + :undoc-members: + :inherited-members: From 3d910661457b10c58b2ee00aad26dc5cc7b6aea4 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 14:20:37 -0400 Subject: [PATCH 88/95] minor doc fixes --- docs/api/commands_cache.rst | 2 +- docs/api/completers/path.rst | 2 +- docs/api/index.rst | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/api/commands_cache.rst b/docs/api/commands_cache.rst index 489999c72..2472c79af 100644 --- a/docs/api/commands_cache.rst +++ b/docs/api/commands_cache.rst @@ -1,7 +1,7 @@ .. _xonsh_commands_cache: ****************************************************** -CommandsCache (``xonsh.commands_cache``) +Commands Cache (``xonsh.commands_cache``) ****************************************************** .. automodule:: xonsh.commands_cache diff --git a/docs/api/completers/path.rst b/docs/api/completers/path.rst index 5ac4af0fd..ac500847a 100644 --- a/docs/api/completers/path.rst +++ b/docs/api/completers/path.rst @@ -4,7 +4,7 @@ File System Path Completer (``xonsh.completers.path``) ********************************************************** -.. automodule:: xonsh.completers.base +.. automodule:: xonsh.completers.path :members: :undoc-members: :inherited-members: diff --git a/docs/api/index.rst b/docs/api/index.rst index bbb61646d..42c32f9b2 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -55,6 +55,7 @@ For those of you who want the gritty details. teepty openpy foreign_shells + commands_cache tracer main pyghooks From 03bda46acd62c8be7849764fec5e2672968d4d3b Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 14:23:19 -0400 Subject: [PATCH 89/95] version bump to 0.4.0 --- .appveyor.yml | 2 +- CHANGELOG.rst | 178 +++++++++++++++++++++++++++ news/035.rst | 68 ---------- news/adqm-anon_aliases.rst | 15 --- news/adqm-more_search.rst | 15 --- news/amal.rst | 43 ------- news/cc.rst | 20 --- news/clean-up-premain.rst | 16 --- news/completer_list_bugs.rst | 13 -- news/fix-main-config-file.rst | 13 -- news/fix_alias.rst | 13 -- news/fix_pipeline.rst | 14 --- news/fix_xonfig.rst | 13 -- news/history-all.rst | 18 --- news/issue_1233.rst | 13 -- news/path_expand.rst | 25 ---- news/path_tuple.rst | 13 -- news/pid.rst | 14 --- news/pytest.rst | 13 -- news/quoted_path_completions.rst | 14 --- news/replace_prompt.rst | 15 --- news/rmbash.rst | 22 ---- news/simplify_env_repr.rst | 14 --- news/sorted_comp.rst | 13 -- news/source_cmd_prompt.rst | 14 --- news/vi_mode_change.rst | 14 --- news/wizard_foreign_shell_prompt.rst | 13 -- news/xonsh_darwin.rst | 13 -- xonsh/__init__.py | 4 +- 29 files changed, 181 insertions(+), 474 deletions(-) delete mode 100644 news/035.rst delete mode 100644 news/adqm-anon_aliases.rst delete mode 100644 news/adqm-more_search.rst delete mode 100644 news/amal.rst delete mode 100644 news/cc.rst delete mode 100644 news/clean-up-premain.rst delete mode 100644 news/completer_list_bugs.rst delete mode 100644 news/fix-main-config-file.rst delete mode 100644 news/fix_alias.rst delete mode 100644 news/fix_pipeline.rst delete mode 100644 news/fix_xonfig.rst delete mode 100644 news/history-all.rst delete mode 100644 news/issue_1233.rst delete mode 100644 news/path_expand.rst delete mode 100644 news/path_tuple.rst delete mode 100644 news/pid.rst delete mode 100644 news/pytest.rst delete mode 100644 news/quoted_path_completions.rst delete mode 100644 news/replace_prompt.rst delete mode 100644 news/rmbash.rst delete mode 100644 news/simplify_env_repr.rst delete mode 100644 news/sorted_comp.rst delete mode 100644 news/source_cmd_prompt.rst delete mode 100644 news/vi_mode_change.rst delete mode 100644 news/wizard_foreign_shell_prompt.rst delete mode 100644 news/xonsh_darwin.rst diff --git a/.appveyor.yml b/.appveyor.yml index 26f339bb6..4caaee60b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,4 @@ -version: 0.3.4.{build} +version: 0.4.0.{build} os: Windows Server 2012 R2 install: - C:\Python35\Scripts\pip install ply pyreadline pytest pygments prompt_toolkit diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8264150bf..0fb9a5c6f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,184 @@ Xonsh Change Log .. current developments +v0.4.0 +==================== + +**Added:** + +* A new class, ``xonsh.tools.EnvPath`` has been added. This class implements a + ``MutableSequence`` object and overrides the ``__getitem__`` method so that + when its entries are requested (either explicitly or implicitly), variable + and user expansion is performed, and relative paths are resolved. + ``EnvPath`` accepts objects (or lists of objects) of ``str``, ``bytes`` or + ``pathlib.Path`` types. +* New amalgamate tool collapses modules inside of a package into a single + ``__amalgam__.py`` module. This tool glues together all of the code from the + modules in a package, finds and removes intra-package imports, makes all + non-package imports lazy, and adds hooks into the ``__init__.py``. + This helps makes initial imports of modules fast and decreases startup time. + Packages and sub-packages must be amalgamated separately. +* New lazy and self-destructive module ``xonsh.lazyasd`` adds a suite of + classes for delayed creation of objects. + + - A ``LazyObject`` won't be created until it has an attribute accessed. + - A ``LazyDict`` will load each value only when a key is accessed. + - A ``LazyBool`` will only be created when ``__bool__()`` is called. + + Additionally, when fully loaded, the above objects will replace themselves + by name in the context that they were handed, thus derefenceing themselves. + This is useful for global variables that may be expensive to create, + should only be created once, and may not be used in any particular session. +* New ``xon.sh`` script added for launching xonsh from a sh environment. + This should be used if the normal ``xonsh`` script does not work for + some reason. +* Normal globbing is now available in Python mode via ``g```` +* Backticks were expanded to allow searching using arbitrary functions, via + ``@```` +* ``xonsh.platform`` now has a new ``PATH_DEFAULT`` variable. +* Tab completers can now raise ``StopIteration`` to prevent consideration of + remaining completers. +* Added tab completer for the ``completer`` alias. +* New ``Block`` and ``Functor`` context managers are now available as + part of the ``xonsh.contexts`` module. +* ``Block`` provides support for turning a context body into a non-executing + list of string lines. This is implmement via a syntax tree transformation. + This is useful for creating remote execution tools that seek to prevent + local execution. +* ``Functor`` is a subclass of the ``Block`` context manager that turns the + block into a callable object. The function object is available via the + ``func()`` attribute. However, the ``Functor`` instance is itself callable + and will dispatch to ``func()``. +* New ``$VC_BRANCH_TIMEOUT`` environment variable is the time (in seconds) + of how long to spend attempting each individual version control branch + information command during ``$PROMPT`` formatting. This allows for faster + prompt resolution and faster startup times. +* New lazy methods added to CommandsCache allowing for testing and inspection + without the possibility of recomputing the cache. +* ``!(command)`` is now usefully iterable, yielding lines of stdout +* Added XonshCalledProcessError, which includes the relevant CompletedCommand. + Also handles differences between Py3.4 and 3.5 in CalledProcessError +* Tab completion of paths now includes zsh-style path expansion (subsequence + matching), toggleable with ``$SUBSEQUENCE_PATH_COMPLETION`` +* Tab completion of paths now includes "fuzzy" matches that are accurate to + within a few characters, toggleable with ``$FUZZY_PATH_COMPLETION`` +* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to + the currently running script's path +* Arguments '+' and '-' for the ``fg`` command (job control) +* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to + the currently running script's path +* ``!(command)`` is now usefully iterable, yielding lines of stdout +* Added XonshCalledProcessError, which includes the relevant CompletedCommand. + Also handles differences between Py3.4 and 3.5 in CalledProcessError +* XonshError and XonshCalledProcessError are now in builtins +- ``history session`` +- ``history xonsh`` + ``history all`` +- ``history zsh`` +- ``history bash`` +- ``__xonsh_history__.show()`` +* New ``pathsep_to_set()`` and ``set_to_pathsep()`` functions convert to/from + ``os.pathsep`` separated strings to a set of strings. + + +**Changed:** + +* Changed testing framework from nose to pytest +* All ``PATH``-like environment variables are now stored in an ``EnvPath`` + object, so that non-absolute paths or paths containing environment variables + can be resolved properly. +* In ``VI_MODE``, the ``v`` key will enter character selection mode, not open + the editor. ``Ctrl-X Ctrl-E`` will still open an editor in any mode +* ``$XONSH_DEBUG`` will now supress amalgamted imports. This usually needs to be + set in the calling environment or prior to *any* xonsh imports. +* Restuctured ``xonsh.platform`` to be fully lazy. +* Restuctured ``xonsh.ansi_colors`` to be fully lazy. +* Ensured the ``pygments`` and ``xonsh.pyghooks`` are not imported until + actually needed. +* Yacc parser is now loaded in a background thread. +* Cleaned up argument parsing in ``xonsh.main.premain`` by removing the + ``undo_args`` hack. + +* Now complains on invalid arguments. +* ``Env`` now guarantees that the ``$PATH`` is available and mutable when + initialized. +* On Windows the ``PROMPT`` environment variable is reset to `$P$G` before + sourcing *.bat files. +* On Windows the ``PROMPT`` environment variable is reset to `$P$G` before starting + subprocesses. This prevents the unformatted xonsh ``PROMPT`` tempalte from showing up + when running batch files with ``ECHO ON``` +* ``@()`` now passes through functions as well as strings, which allows for the + use of anonymous aliases and aliases not explicitly added to the ``aliases`` + mapping. +* Functions in ``Execer`` now take ``transform`` kwarg instead of + ``wrap_subproc``. +* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to + the currently running script's path +* XonshError and XonshCalledProcessError are now in builtins +* ``__repr__`` on the environment only shows a short representation of the + object instead of printing the whole environment dictionary +* More informative prompt when configuring foreign shells in the wizard. +* ``CommandsCache`` is now a mapping from command names to a tuple of + (executable locations, has alias flags). This enables faster lookup times. +* ``locate_bin()`` now uses the ``CommandsCache``, rather than scanning the + ``$PATH`` itself. +* ``$PATHEXT`` is now a set, rather than a list. +* Ignore case and leading a quotes when sorting completions + + +**Removed:** + +None + +* The ``'console_scripts'`` option to setuptools has been removed. It was found + to cause slowdowns of over 150 ms on every startup. +* Bash is no longer loaded by default as a foreign shell for initial + configuration. This was done to increase stock startup times. This + behaviour can be recovered by adding ``{"shell": "bash"}`` to your + ``"foreign_shells"`` in your config.json file. For more details, + see http://xon.sh/xonshconfig.html#foreign-shells +* ``ensure_git()`` and ``ensure_hg()`` decorators removed. +* ``call_hg_command()`` function removed. + + +**Fixed:** + +* Issue where ``xonsh`` did not expand user and environment variables in + ``$PATH``, forcing the user to add absolute paths. +* Fixed a problem with aliases not always beeing found. +* Fixed issue where input was directed to the last process in a pipeline, + rather than the first. +* Bug where xonfig wizard can't find ENV docs +* Fixed ``xonsh.environ.locate_binary()`` to handle PATH variable are given as a tuple. +* Fixed missing completions for ``cd`` and ```rmdir`` when directories had spaces + in their names. +None + +* Bug preventing `xonsh` executable being installed on macOS. +* Strip leading space in commands passed using the "-c" switch +* Fixed xonfig wizard failing on Windows due to colon in created filename. +* Ensured that the prompt_toolkit shell functions, even without a ``completer`` + attribute. +* Fixed crash resulting from malformed ``$PROMPT`` or ``$TITLE``. +* xonsh no longer backgrounds itself after every command on Cygwin. +* Fixed an issue about ``os.killpg()`` on Cygwin which caused xonsh to crash + occasionally +* Fix crash on startup when Bash Windows Subsystem for Linux is on the Path. +* Fixed issue with setting and signaling process groups on Linux when the first + process is a function alias and has no pid. +None +* Fixed ``_list_completers`` such that it does not throw a ValueError if no completer is registered. +* Fixed ``_list_completers`` such that it does not throw an AttributeError if a completer has no docstring. +None + +* Bug that caused command line argument ``--config-path`` to be ignored. +None + +* Bug that caused xonsh to break on startup when prompt-toolkit < 1.0.0. + + + + v0.3.4 ==================== diff --git a/news/035.rst b/news/035.rst deleted file mode 100644 index e9b0b9dc8..000000000 --- a/news/035.rst +++ /dev/null @@ -1,68 +0,0 @@ -**Added:** - -* Tab completers can now raise ``StopIteration`` to prevent consideration of - remaining completers. -* Added tab completer for the ``completer`` alias. -* New ``Block`` and ``Functor`` context managers are now available as - part of the ``xonsh.contexts`` module. -* ``Block`` provides support for turning a context body into a non-executing - list of string lines. This is implmement via a syntax tree transformation. - This is useful for creating remote execution tools that seek to prevent - local execution. -* ``Functor`` is a subclass of the ``Block`` context manager that turns the - block into a callable object. The function object is available via the - ``func()`` attribute. However, the ``Functor`` instance is itself callable - and will dispatch to ``func()``. -* New ``$VC_BRANCH_TIMEOUT`` environment variable is the time (in seconds) - of how long to spend attempting each individual version control branch - information command during ``$PROMPT`` formatting. This allows for faster - prompt resolution and faster startup times. -* New lazy methods added to CommandsCache allowing for testing and inspection - without the possibility of recomputing the cache. -* ``!(command)`` is now usefully iterable, yielding lines of stdout -* Added XonshCalledProcessError, which includes the relevant CompletedCommand. - Also handles differences between Py3.4 and 3.5 in CalledProcessError -* Tab completion of paths now includes zsh-style path expansion (subsequence - matching), toggleable with ``$SUBSEQUENCE_PATH_COMPLETION`` -* Tab completion of paths now includes "fuzzy" matches that are accurate to - within a few characters, toggleable with ``$FUZZY_PATH_COMPLETION`` -* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to - the currently running script's path -* Arguments '+' and '-' for the ``fg`` command (job control) -* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to - the currently running script's path -* ``!(command)`` is now usefully iterable, yielding lines of stdout -* Added XonshCalledProcessError, which includes the relevant CompletedCommand. - Also handles differences between Py3.4 and 3.5 in CalledProcessError -* XonshError and XonshCalledProcessError are now in builtins - -**Changed:** - -* Functions in ``Execer`` now take ``transform`` kwarg instead of - ``wrap_subproc``. -* Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to - the currently running script's path -* XonshError and XonshCalledProcessError are now in builtins - -**Deprecated:** None - - -**Removed:** - -* ``ensure_git()`` and ``ensure_hg()`` decorators removed. -* ``call_hg_command()`` function removed. - - -**Fixed:** - -* Strip leading space in commands passed using the "-c" switch -* Fixed xonfig wizard failing on Windows due to colon in created filename. -* Ensured that the prompt_toolkit shell functions, even without a ``completer`` - attribute. -* Fixed crash resulting from malformed ``$PROMPT`` or ``$TITLE``. -* xonsh no longer backgrounds itself after every command on Cygwin. -* Fixed an issue about ``os.killpg()`` on Cygwin which caused xonsh to crash - occasionally -* Fix crash on startup when Bash Windows Subsystem for Linux is on the Path. - -**Security:** None diff --git a/news/adqm-anon_aliases.rst b/news/adqm-anon_aliases.rst deleted file mode 100644 index ce42cdb48..000000000 --- a/news/adqm-anon_aliases.rst +++ /dev/null @@ -1,15 +0,0 @@ -**Added:** None - -**Changed:** - -* ``@()`` now passes through functions as well as strings, which allows for the - use of anonymous aliases and aliases not explicitly added to the ``aliases`` - mapping. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/adqm-more_search.rst b/news/adqm-more_search.rst deleted file mode 100644 index f104ece03..000000000 --- a/news/adqm-more_search.rst +++ /dev/null @@ -1,15 +0,0 @@ -**Added:** - -* Normal globbing is now available in Python mode via ``g```` -* Backticks were expanded to allow searching using arbitrary functions, via - ``@```` - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/amal.rst b/news/amal.rst deleted file mode 100644 index 0b4b247d3..000000000 --- a/news/amal.rst +++ /dev/null @@ -1,43 +0,0 @@ -**Added:** - -* New amalgamate tool collapses modules inside of a package into a single - ``__amalgam__.py`` module. This tool glues together all of the code from the - modules in a package, finds and removes intra-package imports, makes all - non-package imports lazy, and adds hooks into the ``__init__.py``. - This helps makes initial imports of modules fast and decreases startup time. - Packages and sub-packages must be amalgamated separately. -* New lazy and self-destructive module ``xonsh.lazyasd`` adds a suite of - classes for delayed creation of objects. - - - A ``LazyObject`` won't be created until it has an attribute accessed. - - A ``LazyDict`` will load each value only when a key is accessed. - - A ``LazyBool`` will only be created when ``__bool__()`` is called. - - Additionally, when fully loaded, the above objects will replace themselves - by name in the context that they were handed, thus derefenceing themselves. - This is useful for global variables that may be expensive to create, - should only be created once, and may not be used in any particular session. -* New ``xon.sh`` script added for launching xonsh from a sh environment. - This should be used if the normal ``xonsh`` script does not work for - some reason. - -**Changed:** - -* ``$XONSH_DEBUG`` will now supress amalgamted imports. This usually needs to be - set in the calling environment or prior to *any* xonsh imports. -* Restuctured ``xonsh.platform`` to be fully lazy. -* Restuctured ``xonsh.ansi_colors`` to be fully lazy. -* Ensured the ``pygments`` and ``xonsh.pyghooks`` are not imported until - actually needed. -* Yacc parser is now loaded in a background thread. - -**Deprecated:** None - -**Removed:** None - -* The ``'console_scripts'`` option to setuptools has been removed. It was found - to cause slowdowns of over 150 ms on every startup. - -**Fixed:** None - -**Security:** None diff --git a/news/cc.rst b/news/cc.rst deleted file mode 100644 index c2d48d50d..000000000 --- a/news/cc.rst +++ /dev/null @@ -1,20 +0,0 @@ -**Added:** - -* New ``pathsep_to_set()`` and ``set_to_pathsep()`` functions convert to/from - ``os.pathsep`` separated strings to a set of strings. - -**Changed:** - -* ``CommandsCache`` is now a mapping from command names to a tuple of - (executable locations, has alias flags). This enables faster lookup times. -* ``locate_bin()`` now uses the ``CommandsCache``, rather than scanning the - ``$PATH`` itself. -* ``$PATHEXT`` is now a set, rather than a list. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/clean-up-premain.rst b/news/clean-up-premain.rst deleted file mode 100644 index cf5c8c89a..000000000 --- a/news/clean-up-premain.rst +++ /dev/null @@ -1,16 +0,0 @@ -**Added:** None - -**Changed:** - -* Cleaned up argument parsing in ``xonsh.main.premain`` by removing the - ``undo_args`` hack. - -* Now complains on invalid arguments. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/completer_list_bugs.rst b/news/completer_list_bugs.rst deleted file mode 100644 index e77c71a17..000000000 --- a/news/completer_list_bugs.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None -* Fixed ``_list_completers`` such that it does not throw a ValueError if no completer is registered. -* Fixed ``_list_completers`` such that it does not throw an AttributeError if a completer has no docstring. - -**Security:** None diff --git a/news/fix-main-config-file.rst b/news/fix-main-config-file.rst deleted file mode 100644 index 8220840ca..000000000 --- a/news/fix-main-config-file.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -* Bug that caused command line argument ``--config-path`` to be ignored. - -**Security:** None diff --git a/news/fix_alias.rst b/news/fix_alias.rst deleted file mode 100644 index 6542d82c5..000000000 --- a/news/fix_alias.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Fixed a problem with aliases not always beeing found. - -**Security:** None diff --git a/news/fix_pipeline.rst b/news/fix_pipeline.rst deleted file mode 100644 index ec5d00a0a..000000000 --- a/news/fix_pipeline.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Fixed issue where input was directed to the last process in a pipeline, - rather than the first. - -**Security:** None diff --git a/news/fix_xonfig.rst b/news/fix_xonfig.rst deleted file mode 100644 index d80c04087..000000000 --- a/news/fix_xonfig.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Bug where xonfig wizard can't find ENV docs - -**Security:** None diff --git a/news/history-all.rst b/news/history-all.rst deleted file mode 100644 index d8a76c8d7..000000000 --- a/news/history-all.rst +++ /dev/null @@ -1,18 +0,0 @@ -**Added:** - -- ``history session`` -- ``history xonsh`` - ``history all`` -- ``history zsh`` -- ``history bash`` -- ``__xonsh_history__.show()`` - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/issue_1233.rst b/news/issue_1233.rst deleted file mode 100644 index 7039275df..000000000 --- a/news/issue_1233.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -* Bug that caused xonsh to break on startup when prompt-toolkit < 1.0.0. - -**Security:** None diff --git a/news/path_expand.rst b/news/path_expand.rst deleted file mode 100644 index 6cf9b273e..000000000 --- a/news/path_expand.rst +++ /dev/null @@ -1,25 +0,0 @@ -**Added:** - -* A new class, ``xonsh.tools.EnvPath`` has been added. This class implements a - ``MutableSequence`` object and overrides the ``__getitem__`` method so that - when its entries are requested (either explicitly or implicitly), variable - and user expansion is performed, and relative paths are resolved. - ``EnvPath`` accepts objects (or lists of objects) of ``str``, ``bytes`` or - ``pathlib.Path`` types. - -**Changed:** - -* All ``PATH``-like environment variables are now stored in an ``EnvPath`` - object, so that non-absolute paths or paths containing environment variables - can be resolved properly. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Issue where ``xonsh`` did not expand user and environment variables in - ``$PATH``, forcing the user to add absolute paths. - -**Security:** None diff --git a/news/path_tuple.rst b/news/path_tuple.rst deleted file mode 100644 index 29576907a..000000000 --- a/news/path_tuple.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Fixed ``xonsh.environ.locate_binary()`` to handle PATH variable are given as a tuple. - -**Security:** None diff --git a/news/pid.rst b/news/pid.rst deleted file mode 100644 index 6b9957d60..000000000 --- a/news/pid.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Fixed issue with setting and signaling process groups on Linux when the first - process is a function alias and has no pid. - -**Security:** None diff --git a/news/pytest.rst b/news/pytest.rst deleted file mode 100644 index 6a8d039b5..000000000 --- a/news/pytest.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** - -* Changed testing framework from nose to pytest - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/quoted_path_completions.rst b/news/quoted_path_completions.rst deleted file mode 100644 index 650d6c85b..000000000 --- a/news/quoted_path_completions.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* Fixed missing completions for ``cd`` and ```rmdir`` when directories had spaces - in their names. - -**Security:** None diff --git a/news/replace_prompt.rst b/news/replace_prompt.rst deleted file mode 100644 index e06520c74..000000000 --- a/news/replace_prompt.rst +++ /dev/null @@ -1,15 +0,0 @@ -**Added:** None - -**Changed:** - -* On Windows the ``PROMPT`` environment variable is reset to `$P$G` before starting - subprocesses. This prevents the unformatted xonsh ``PROMPT`` tempalte from showing up - when running batch files with ``ECHO ON``` - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/rmbash.rst b/news/rmbash.rst deleted file mode 100644 index d60d7e997..000000000 --- a/news/rmbash.rst +++ /dev/null @@ -1,22 +0,0 @@ -**Added:** - -* ``xonsh.platform`` now has a new ``PATH_DEFAULT`` variable. - -**Changed:** - -* ``Env`` now guarantees that the ``$PATH`` is available and mutable when - initialized. - -**Deprecated:** None - -**Removed:** - -* Bash is no longer loaded by default as a foreign shell for initial - configuration. This was done to increase stock startup times. This - behaviour can be recovered by adding ``{"shell": "bash"}`` to your - ``"foreign_shells"`` in your config.json file. For more details, - see http://xon.sh/xonshconfig.html#foreign-shells - -**Fixed:** None - -**Security:** None diff --git a/news/simplify_env_repr.rst b/news/simplify_env_repr.rst deleted file mode 100644 index af28ae668..000000000 --- a/news/simplify_env_repr.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** - -* ``__repr__`` on the environment only shows a short representation of the - object instead of printing the whole environment dictionary - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/sorted_comp.rst b/news/sorted_comp.rst deleted file mode 100644 index 7d42a2b84..000000000 --- a/news/sorted_comp.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** - -* Ignore case and leading a quotes when sorting completions - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/source_cmd_prompt.rst b/news/source_cmd_prompt.rst deleted file mode 100644 index fecd0843e..000000000 --- a/news/source_cmd_prompt.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** - -* On Windows the ``PROMPT`` environment variable is reset to `$P$G` before - sourcing *.bat files. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/vi_mode_change.rst b/news/vi_mode_change.rst deleted file mode 100644 index 260c2300e..000000000 --- a/news/vi_mode_change.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** - -* In ``VI_MODE``, the ``v`` key will enter character selection mode, not open - the editor. ``Ctrl-X Ctrl-E`` will still open an editor in any mode - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/wizard_foreign_shell_prompt.rst b/news/wizard_foreign_shell_prompt.rst deleted file mode 100644 index 25a8564f4..000000000 --- a/news/wizard_foreign_shell_prompt.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** - -* More informative prompt when configuring foreign shells in the wizard. - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -**Security:** None diff --git a/news/xonsh_darwin.rst b/news/xonsh_darwin.rst deleted file mode 100644 index 4383a2cb2..000000000 --- a/news/xonsh_darwin.rst +++ /dev/null @@ -1,13 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** None - -* Bug preventing `xonsh` executable being installed on macOS. - -**Security:** None diff --git a/xonsh/__init__.py b/xonsh/__init__.py index 5b356d2d6..26e87803f 100644 --- a/xonsh/__init__.py +++ b/xonsh/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.3.4' +__version__ = '0.4.0' # amalgamate exclude jupyter_kernel parser_table parser_test_table pyghooks # amalgamate exclude winutils wizard @@ -90,4 +90,4 @@ else: pass del _sys del _os -# amalgamate end \ No newline at end of file +# amalgamate end From 3438e54d4c10fc1bebcdefbca1a5ad98e4caa8cf Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 14:44:57 -0400 Subject: [PATCH 90/95] newline --- xonsh/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/__init__.py b/xonsh/__init__.py index 26e87803f..d35f14ede 100644 --- a/xonsh/__init__.py +++ b/xonsh/__init__.py @@ -90,4 +90,4 @@ else: pass del _sys del _os -# amalgamate end +# amalgamate end \ No newline at end of file From 2892bcde22737cc392351fa1f6e951044fcf4504 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 14:49:34 -0400 Subject: [PATCH 91/95] some cl cleanup --- CHANGELOG.rst | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0fb9a5c6f..164667e1e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -101,14 +101,13 @@ v0.4.0 * Yacc parser is now loaded in a background thread. * Cleaned up argument parsing in ``xonsh.main.premain`` by removing the ``undo_args`` hack. - * Now complains on invalid arguments. * ``Env`` now guarantees that the ``$PATH`` is available and mutable when initialized. * On Windows the ``PROMPT`` environment variable is reset to `$P$G` before sourcing *.bat files. * On Windows the ``PROMPT`` environment variable is reset to `$P$G` before starting - subprocesses. This prevents the unformatted xonsh ``PROMPT`` tempalte from showing up + subprocesses. This prevents the unformatted xonsh ``PROMPT`` tempalte from showing up when running batch files with ``ECHO ON``` * ``@()`` now passes through functions as well as strings, which allows for the use of anonymous aliases and aliases not explicitly added to the ``aliases`` @@ -118,7 +117,7 @@ v0.4.0 * Provide ``$XONSH_SOURCE`` for scripts in the environment variables pointing to the currently running script's path * XonshError and XonshCalledProcessError are now in builtins -* ``__repr__`` on the environment only shows a short representation of the +* ``__repr__`` on the environment only shows a short representation of the object instead of printing the whole environment dictionary * More informative prompt when configuring foreign shells in the wizard. * ``CommandsCache`` is now a mapping from command names to a tuple of @@ -131,8 +130,6 @@ v0.4.0 **Removed:** -None - * The ``'console_scripts'`` option to setuptools has been removed. It was found to cause slowdowns of over 150 ms on every startup. * Bash is no longer loaded by default as a foreign shell for initial @@ -153,10 +150,8 @@ None rather than the first. * Bug where xonfig wizard can't find ENV docs * Fixed ``xonsh.environ.locate_binary()`` to handle PATH variable are given as a tuple. -* Fixed missing completions for ``cd`` and ```rmdir`` when directories had spaces +* Fixed missing completions for ``cd`` and ```rmdir`` when directories had spaces in their names. -None - * Bug preventing `xonsh` executable being installed on macOS. * Strip leading space in commands passed using the "-c" switch * Fixed xonfig wizard failing on Windows due to colon in created filename. @@ -169,19 +164,12 @@ None * Fix crash on startup when Bash Windows Subsystem for Linux is on the Path. * Fixed issue with setting and signaling process groups on Linux when the first process is a function alias and has no pid. -None * Fixed ``_list_completers`` such that it does not throw a ValueError if no completer is registered. * Fixed ``_list_completers`` such that it does not throw an AttributeError if a completer has no docstring. -None - * Bug that caused command line argument ``--config-path`` to be ignored. -None - * Bug that caused xonsh to break on startup when prompt-toolkit < 1.0.0. - - v0.3.4 ==================== From 60f0c37a7abe8b92e445893089ff6bc11108fcb4 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 14:52:14 -0400 Subject: [PATCH 92/95] some cl cleanup --- CHANGELOG.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 164667e1e..9c18262db 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -73,13 +73,15 @@ v0.4.0 * ``!(command)`` is now usefully iterable, yielding lines of stdout * Added XonshCalledProcessError, which includes the relevant CompletedCommand. Also handles differences between Py3.4 and 3.5 in CalledProcessError -* XonshError and XonshCalledProcessError are now in builtins -- ``history session`` -- ``history xonsh`` - ``history all`` -- ``history zsh`` -- ``history bash`` -- ``__xonsh_history__.show()`` +* XonshError and XonshCalledProcessError are now in builtins: + + - ``history session`` + - ``history xonsh`` + - ``history all`` + - ``history zsh`` + - ``history bash`` + - ``__xonsh_history__.show()`` + * New ``pathsep_to_set()`` and ``set_to_pathsep()`` functions convert to/from ``os.pathsep`` separated strings to a set of strings. @@ -105,7 +107,7 @@ v0.4.0 * ``Env`` now guarantees that the ``$PATH`` is available and mutable when initialized. * On Windows the ``PROMPT`` environment variable is reset to `$P$G` before - sourcing *.bat files. + sourcing ``*.bat`` files. * On Windows the ``PROMPT`` environment variable is reset to `$P$G` before starting subprocesses. This prevents the unformatted xonsh ``PROMPT`` tempalte from showing up when running batch files with ``ECHO ON``` From 57f362ab1746a65f8f71ec1b901737bc4164435a Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 16:35:11 -0400 Subject: [PATCH 93/95] amalgamate fix --- news/amalfix.rst | 14 ++++++++++++++ setup.py | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 news/amalfix.rst diff --git a/news/amalfix.rst b/news/amalfix.rst new file mode 100644 index 000000000..3ef0f2164 --- /dev/null +++ b/news/amalfix.rst @@ -0,0 +1,14 @@ +**Added:** None + +**Changed:** None + +**Deprecated:** None + +**Removed:** None + +**Fixed:** + +* ``setup.py`` will only amalgamate source files if ``amalgamate.py`` is + available. This fixes issues with installing from pip. + +**Security:** None diff --git a/setup.py b/setup.py index 42468138f..c8955160b 100755 --- a/setup.py +++ b/setup.py @@ -48,6 +48,15 @@ def clean_tables(): os.environ['XONSH_DEBUG'] = '1' from xonsh import __version__ as XONSH_VERSION +def amalagamate_source(): + """Amalgamtes source files.""" + try: + import amalgamate + except ImportError: + return + amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh']) + + def build_tables(): """Build the lexer/parser modules.""" print('Building lexer and parser tables.') @@ -55,8 +64,7 @@ def build_tables(): from xonsh.parser import Parser Parser(lexer_table='lexer_table', yacc_table='parser_table', outputdir='xonsh') - import amalgamate - amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh']) + amalagamate_source() sys.path.pop(0) From dfc6142b8305e586cded565d5eb9180e13ac65e4 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 16:36:48 -0400 Subject: [PATCH 94/95] added amalgamate error --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index c8955160b..3eec35569 100755 --- a/setup.py +++ b/setup.py @@ -53,6 +53,7 @@ def amalagamate_source(): try: import amalgamate except ImportError: + print('Could not import amalgamate, skipping.', file=sys.stderr) return amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh']) From c6f573f11b33ddcbc9d0dcbe798a6963aea27eff Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Fri, 24 Jun 2016 17:40:40 -0400 Subject: [PATCH 95/95] version bump to 0.4.1 --- .appveyor.yml | 2 +- CHANGELOG.rst | 11 +++++++++++ news/amalfix.rst | 14 -------------- xonsh/__init__.py | 4 ++-- 4 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 news/amalfix.rst diff --git a/.appveyor.yml b/.appveyor.yml index 4caaee60b..d4cc08823 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,4 @@ -version: 0.4.0.{build} +version: 0.4.1.{build} os: Windows Server 2012 R2 install: - C:\Python35\Scripts\pip install ply pyreadline pytest pygments prompt_toolkit diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9c18262db..935005ace 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,17 @@ Xonsh Change Log .. current developments +v0.4.1 +==================== + +**Fixed:** + +* ``setup.py`` will only amalgamate source files if ``amalgamate.py`` is + available. This fixes issues with installing from pip. + + + + v0.4.0 ==================== diff --git a/news/amalfix.rst b/news/amalfix.rst deleted file mode 100644 index 3ef0f2164..000000000 --- a/news/amalfix.rst +++ /dev/null @@ -1,14 +0,0 @@ -**Added:** None - -**Changed:** None - -**Deprecated:** None - -**Removed:** None - -**Fixed:** - -* ``setup.py`` will only amalgamate source files if ``amalgamate.py`` is - available. This fixes issues with installing from pip. - -**Security:** None diff --git a/xonsh/__init__.py b/xonsh/__init__.py index d35f14ede..68d2ad260 100644 --- a/xonsh/__init__.py +++ b/xonsh/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.4.0' +__version__ = '0.4.1' # amalgamate exclude jupyter_kernel parser_table parser_test_table pyghooks # amalgamate exclude winutils wizard @@ -90,4 +90,4 @@ else: pass del _sys del _os -# amalgamate end \ No newline at end of file +# amalgamate end