aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_cmd_line_script.py
Commit message (Collapse)AuthorAge
* gh-116042: Fix location for SyntaxErrors of invalid escapes in the tokenizer ↵Pablo Galindo Salgado2025-02-13
| | | | (#116049)
* gh-127873: Only check `sys.flags.ignore_environment` for `PYTHON*` env vars ↵Hugo van Kemenade2025-01-21
| | | | (#127877)
* gh-128016: Improved invalid escape sequence warning message (#128020)Umar Butler2025-01-15
|
* gh-125522 : add explicit exception types to bare excepts in tests (#125523)Irit Katriel2024-10-15
|
* gh-114099: Add test exclusions to support running the test suite on iOS ↵Russell Keith-Magee2024-02-05
| | | | | | | | | | | | | (#114889) Add test annotations required to run the test suite on iOS (PEP 730). The majority of the change involve annotating tests that use subprocess, but are skipped on Emscripten/WASI for other reasons, and including iOS/tvOS/watchOS under the same umbrella as macOS/darwin checks. `is_apple` and `is_apple_mobile` test helpers have been added to identify *any* Apple platform, and "any Apple platform except macOS", respectively.
* gh-67224: Show source lines in tracebacks when using the -c option when ↵Pablo Galindo Salgado2023-10-26
| | | | running Python (#111200)
* gh-111132: Fix crash on interactive_filename in `run_mod` (#111136)Nikita Sobolev2023-10-20
|
* gh-110805: Allow the repl to show source code and complete tracebacks (#110775)Pablo Galindo Salgado2023-10-13
|
* gh-103186: Fix or catch 'extra' stderr output from unittests (#103196)Ijtaba Hussain2023-07-10
| | | | | | | | | | | | Reduce test noise by fixing or catching and testing stderr messages from individual tests. test_cmd_line_script.test_script_as_dev_fd calls spawn_python and hence subprocess.Popen with incompatible arguments. On POSIX, pass_fds forces close_fds to be True (subprocess.py line 848). Correct the call. test_uuid.test_cli_namespace_required_for_uuid3: when the namespace is omitted, uuid.main calls argparse.Argument_Parser.error, which prints to stderr before calling sys.exit, which raises SystemExit. Unittest assertRaises catches the exception but not the previous output. Catch the output and test it. test_warnings.test_catchwarnings_with_simplefilter_error similarly prints before raising. Catch the output and test it. --------- Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
* gh-97556: Raise null bytes syntax error upon null in multiline string ↵Lysandros Nikolaou2023-05-04
| | | | (GH-104136)
* gh-102856: Initial implementation of PEP 701 (#102855)Pablo Galindo Salgado2023-04-19
| | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-100005: Skip test_script_as_dev_fd() on FreeBSD (#100006)Victor Stinner2022-12-05
| | | | On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if fdescfs is not mounted (at /dev/fd).
* GH-87235: Make sure "python /dev/fd/9 9</path/to/script.py" works on macOS ↵Ronald Oussoren2022-11-27
| | | | | | | | | | | | (#99768) On macOS all file descriptors for a particular file in /dev/fd share the same file offset, that is ``open("/dev/fd/9", "r")`` behaves more like ``dup(9)`` than a regular open. This causes problems when a user tries to run "/dev/fd/9" as a script because zipimport changes the file offset to try to read a zipfile directory. Therefore change zipimport to reset the file offset after trying to read the zipfile directory.
* gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)Pablo Galindo Salgado2022-09-27
|
* gh-93883: elide traceback indicators when possible (#93994)John Belmonte2022-07-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gh-93883: elide traceback indicators when possible Elide traceback column indicators when the entire line of the frame is implicated. This reduces traceback length and draws even more attention to the remaining (very relevant) indicators. Example: ``` Traceback (most recent call last): File "query.py", line 99, in <module> bar() File "query.py", line 66, in bar foo() File "query.py", line 37, in foo magic_arithmetic('foo') File "query.py", line 18, in magic_arithmetic return add_counts(x) / 25 ^^^^^^^^^^^^^ File "query.py", line 24, in add_counts return 25 + query_user(user1) + query_user(user2) ^^^^^^^^^^^^^^^^^ File "query.py", line 32, in query_user return 1 + query_count(db, response['a']['b']['c']['user'], retry=True) ~~~~~~~~~~~~~~~~~~^^^^^ TypeError: 'NoneType' object is not subscriptable ``` Rather than going out of our way to provide indicator coverage in every traceback test suite, the indicator test suite should be responible for sufficient coverage (e.g. by adding a basic exception group test to ensure that margin strings are covered).
* gh-90473: Skip tests that don't apply to Emscripten and WASI (GH-92846)Christian Heimes2022-05-16
|
* gh-57684: Update tests for PYTHONSAFEPATH=1 (#92358)Victor Stinner2022-05-06
| | | | | Fix tests failing with the PYTHONSAFEPATH=1 env var. Enhance also -P help in Python usage (python --help).
* bpo-45229: Remove test_main in many tests (GH-28405)Serhiy Storchaka2021-09-19
| | | | | | | | | Instead of explicitly enumerate test classes for run_unittest() use the unittest ability to discover tests. This also makes these tests discoverable and runnable with unittest. load_tests() can be used for dynamic generating tests and adding doctests. setUpModule(), tearDownModule() and addModuleCleanup() can be used for running code before and after all module tests.
* bpo-45020: Freeze some of the modules imported during startup. (gh-28335)Eric Snow2021-09-15
| | | | | | | Doing this provides significant performance gains for runtime startup (~15% with all the imported modules frozen). We don't yet freeze all the imported modules because there are a few hiccups in the build systems we need to sort out first. (See bpo-45186 and bpo-45188.) Note that in PR GH-28320 we added a command-line flag (-X frozen_modules=[on|off]) that allows users to opt out of (or into) using frozen modules. The default is still "off" but we will change it to "on" as soon as we can do it in a way that does not cause contributors pain. https://bugs.python.org/issue45020
* bpo-43950: Print columns in tracebacks (PEP 657) (GH-26958)Ammar Askar2021-07-05
| | | | | | | | The traceback.c and traceback.py mechanisms now utilize the newly added code.co_positions and PyCode_Addr2Location to print carets on the specific expressions involved in a traceback. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com> Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
* fix: use unambiguous punction in 'invalid escape sequence' message (GH-26582)Ned Batchelder2021-06-08
|
* bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo2021-04-23
| | | | | | | | | | | | | | | | | To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
* bpo-43797: Improve syntax error for invalid comparisons (#25317)Pablo Galindo2021-04-12
| | | | | | | | | | | | | * bpo-43797: Improve syntax error for invalid comparisons * Update Lib/test/test_fstring.py Co-authored-by: Guido van Rossum <gvanrossum@gmail.com> * Apply review comments * can't -> cannot Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25145)Inada Naoki2021-04-04
| | | | | | | | | | | | | | | | | | | * test_asyncio * test_bz2 * test_math * test_cmath * test_cmd_line * test_cmd_line_script * test_compile * test_contextlib * test_profile * ctypes/test/test_find * test_multiprocessing * test_configparser * test_csv * test_dbm_dumb * test_decimal * test_difflib * os.fdopen() calls io.text_encoding() to emit EncodingWarning for right place.
* bpo-41731: Make test_cmd_line_script pass with -vv (GH-22206)Terry Jan Reedy2020-09-12
| | | | | Argument script_exec_args is usually an absolute file name, but twice has form ['-m', 'module_name'].
* bpo-40275: Use new test.support helper submodules in tests (GH-21412)Hai Shi2020-07-09
|
* bpo-40612: Fix SyntaxError edge cases in traceback formatting (GH-20072)Guido van Rossum2020-05-14
| | | | | | | | | | | | | This fixes both the traceback.py module and the C code for formatting syntax errors (in Python/pythonrun.c). They now both consistently do the following: - Suppress caret if it points left of text - Allow caret pointing just past end of line - If caret points past end of line, clip to *just* past end of line The syntax error formatting code in traceback.py was mostly rewritten; small, subtle changes were applied to the C code in pythonrun.c. There's still a difference when the text contains embedded newlines. Neither handles these very well, and I don't think the case occurs in practice. Automerge-Triggered-By: @gvanrossum
* bpo-40334: Fix error location upon parsing an invalid string literal (GH-19962)Lysandros Nikolaou2020-05-07
| | | | | | | When parsing a string with an invalid escape, the old parser used to point to the beginning of the invalid string. This commit changes the new parser to match that behaviour, since it's currently pointing to the end of the string (or to be more precise, to the beginning of the next token).
* bpo-40334: Improve column offsets for thrown syntax errors by Pegen (GH-19782)Batuhan Taskaya2020-05-01
|
* bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503)Pablo Galindo2020-04-22
| | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-40108: Improve the error message in runpy when importing a module that ↵Pablo Galindo2020-03-31
| | | | includes the extension (GH-19239)
* bpo-20443: No longer make sys.argv[0] absolute for script (GH-17534)Victor Stinner2019-12-09
| | | | | In Python 3.9.0a1, sys.argv[0] was made an asolute path if a filename was specified on the command line. Revert this change, since most users expect sys.argv to be unmodified.
* bpo-38991: Remove test.support.strip_python_stderr() (GH-17490)Victor Stinner2019-12-08
| | | | | test.support: run_python_until_end(), assert_python_ok() and assert_python_failure() functions no longer strip whitespaces from stderr.
* Fix typos mostly in comments, docs and test names (GH-15209)Min ho Kim2019-08-30
|
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-30
| | | | | | | | | | | | | | | | | | | | | | | | * Fix typos in comments, docs and test names * Update test_pyparse.py account for change in string length * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: Dealloccte -> Deallocate Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Update posixmodule checksum. * Reverse idlelib changes.
* Add additional test for multi-line SyntaxError (GH-15003)Anthony Sottile2019-07-29
|
* Fix `SyntaxError` indicator printing too many spaces for multi-line strings ↵Anthony Sottile2019-07-29
| | | | (GH-14433)
* bpo-20443: _PyConfig_Read() gets the absolute path of run_filename (GH-14053)Victor Stinner2019-06-25
| | | | | | | | | | | | Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the __file__ attribute of the __main__ module, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path. * Add _Py_isabs() and _Py_abspath() functions. * _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails. * Reimplement os._getfullpathname() using _Py_abspath(). * Use _Py_isabs() in getpath.c.
* bpo-20844: open script file with "rb" mode (GH-12616)Inada Naoki2019-04-01
|
* bpo-34726: Fix handling of hash-based pycs in zipimport. (GH-10327)Elvis Pranskevichus2018-11-07
| | | | | | | | Current support for hash-based bytecode files in `zipimport` is rather sparse, which leads to test failures when the test suite is ran with the ``SOURCE_DATE_EPOCH`` environment variable set. This teaches zipimport to handle hash-based pycs properly.
* bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842)Alexey Izbyshev2018-10-20
| | | | | | | | | If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1.
* bpo-34783: Fix test_nonexisting_script() (GH-9896)Victor Stinner2018-10-15
| | | | | | Fix test_cmd_line_script.test_nonexisting_script(): the test must not rely on sys.executable, since main.c uses config->program which can be different than sys.executable in many cases (for example, on macOS when using the framework).
* bpo-34783: Disable test_nonexisting_script for macOS framework builds (GH-9831)Ned Deily2018-10-12
| | | | | | | | | With macOS framework builds, test case test_nonexisting_script in test_nonexisting_script fails because the test case assumes that the file name in sys.executable will appear in the error message. For macOS framework builds, sys.executable is the file name of the stub launcher and its file name bears no relationship to the file name of the actual python executable. For now, skip the test in this case.
* bpo-34783: Add test_cmd_line_script.test_nonexisting_script() (GH-9535)Victor Stinner2018-09-24
| | | | Make sure that "./python script.py" does not crash if the script file doesn't exist.
* bpo-33053: Remove test_cmd_line_script debugging print (GH-6237)Nick Coghlan2018-03-25
| | | | I noticed this had slipped into the original commit when resolving a merge conflict for the backport to 3.7.
* bpo-33053: -m now adds *starting* directory to sys.path (GH-6231)Nick Coghlan2018-03-25
| | | | | | | | | | | | Historically, -m added the empty string as sys.path zero, meaning it resolved imports against the current working directory, the same way -c and the interactive prompt do. This changes the sys.path initialisation to add the *starting* working directory as sys.path[0] instead, such that changes to the working directory while the program is running will have no effect on imports when using the -m switch.
* bpo-30436: Raise ModuleNotFoundError for importlib.util.find_spec() when ↵Milan Oberkirch2017-06-14
| | | | | parent isn't a package (GH-1899) Previously AttributeError was raised, but that's not very reflective of the fact that the requested module can't be found since the specified parent isn't actually a package.
* bpo-29723: Consistently configure sys.path[0] (#575)Nick Coghlan2017-03-12
| | | | | | | | | | | | | | | | | | | | | | Directory and zipfile execution previously added the parent directory of the directory or zipfile as sys.path[0] and then subsequently overwrote it with the directory or zipfile itself. This caused problems in isolated mode, as it overwrote the "stdlib as a zip archive" entry in sys.path, as the parent directory was never added. The attempted fix to that issue in bpo-29319 created the opposite problem in *non*-isolated mode, by potentially leaving the parent directory on sys.path instead of overwriting it. This change fixes the root cause of the problem by removing the whole "add-and-overwrite" dance for sys.path[0], and instead simply never adds the parent directory to sys.path in the first place.
* Issue #25677: Merge SyntaxError caret positioning from 3.5Martin Panter2016-12-19
|\
| * Issue #25677: Correct syntax error caret for indented blocks.Martin Panter2016-12-11
| | | | | | | | Based on patch by Michael Layzell.