Repository navigation
Parity suite against another Python Jinja2: JINJA2CPP_TEST_ORACLE (0186 phase 1) #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2fc5222
Parity suite against another Python Jinja2: JINJA2CPP_TEST_ORACLE (01…
claude 1f53fb8
Oracle mode: verifier findings (0186 phase 1)
claude 8025018
Merge remote-tracking branch 'origin/master' into claude/project-thre…
claude a984a03
Oracle mode: Codex findings (0186 phase 1)
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Compare the parity suite with a Python Jinja2 other than the bundled one (docs/tasks/0186, | ||
| # test/parity/README.md "Other oracles"). Included from the test block of CMakeLists.txt. | ||
| # | ||
| # bundled (default): the checked-in test/parity/expected/; nothing here runs and no Python is needed | ||
| # python: test/parity/generate.py runs under JINJA2CPP_TEST_ORACLE_PYTHON (default: the | ||
| # Python3 interpreter CMake finds) with whatever jinja2 and markupsafe it has | ||
| # venv: a venv in the build directory gets JINJA2CPP_TEST_ORACLE_REQUIREMENTS from pip | ||
| # | ||
| # The other oracle's expectations are generated at test time, by the fixture | ||
| # jinja2cpp_parity_oracle_generate, so configure needs no network and a failing pip is a failing | ||
| # test. jinja2cpp_parity_oracle then runs the narrow suite against them and writes | ||
| # parity-oracle/report.md in the build directory. | ||
| set(JINJA2CPP_TEST_ORACLE bundled CACHE STRING "Python Jinja2 the parity suite compares against: bundled | python | venv") | ||
| set_property(CACHE JINJA2CPP_TEST_ORACLE PROPERTY STRINGS bundled python venv) | ||
| set(JINJA2CPP_TEST_ORACLE_PYTHON "" CACHE FILEPATH "Interpreter for JINJA2CPP_TEST_ORACLE=python, and the base of the venv (default: find_package(Python3))") | ||
| set(JINJA2CPP_TEST_ORACLE_REQUIREMENTS "" CACHE STRING | ||
| "pip requirements for JINJA2CPP_TEST_ORACLE=venv, ';'-separated, e.g. 'jinja2==3.1.2;markupsafe==2.1.5' or 'jinja2 @ git+https://github.com/pallets/jinja@main'") | ||
|
|
||
| if (JINJA2CPP_TEST_ORACLE STREQUAL "bundled") | ||
| return() | ||
| endif () | ||
| if (NOT JINJA2CPP_TEST_ORACLE MATCHES "^(python|venv)$") | ||
| message(FATAL_ERROR "JINJA2CPP_TEST_ORACLE must be bundled, python or venv, not '${JINJA2CPP_TEST_ORACLE}'") | ||
| endif () | ||
| if (JINJA2CPP_TEST_ORACLE STREQUAL "venv" AND JINJA2CPP_TEST_ORACLE_REQUIREMENTS STREQUAL "") | ||
| message(FATAL_ERROR "JINJA2CPP_TEST_ORACLE=venv needs JINJA2CPP_TEST_ORACLE_REQUIREMENTS, e.g. 'jinja2==3.1.2'") | ||
| endif () | ||
|
|
||
| if (JINJA2CPP_TEST_ORACLE_PYTHON) | ||
| set(_oracle_python "${JINJA2CPP_TEST_ORACLE_PYTHON}") | ||
| else () | ||
| find_package(Python3 3.10 REQUIRED COMPONENTS Interpreter) | ||
| set(_oracle_python "${Python3_EXECUTABLE}") | ||
| endif () | ||
| execute_process(COMMAND "${_oracle_python}" -c "import sys; print('%d.%d' % sys.version_info[:2])" | ||
| OUTPUT_VARIABLE _oracle_python_version OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE _oracle_python_result) | ||
| if (NOT _oracle_python_result EQUAL 0) | ||
| message(FATAL_ERROR "JINJA2CPP_TEST_ORACLE: cannot run ${_oracle_python}") | ||
| endif () | ||
| # The Unicode tables in src/ come from the pinned Python, so Unicode cases may differ for a | ||
| # reason that is not a Jinja2C++ bug | ||
| if (NOT _oracle_python_version VERSION_EQUAL JINJA2CPP_ORACLE_PYTHON) | ||
| message(WARNING "JINJA2CPP_TEST_ORACLE: the oracle runs Python ${_oracle_python_version}, but Jinja2C++ follows Python " | ||
| "${JINJA2CPP_ORACLE_PYTHON} (.python-version); cases that depend on the Python version (Unicode data, textwrap, " | ||
| "\\N{} names) can show up in the report as deltas that are not Jinja2 changes") | ||
| endif () | ||
| message(STATUS "Parity oracle: ${JINJA2CPP_TEST_ORACLE}, Python ${_oracle_python_version} (${_oracle_python})") | ||
|
|
||
| set(_oracle_dir ${CMAKE_CURRENT_BINARY_DIR}/parity-oracle) | ||
| set(_oracle_requirements "") | ||
| if (JINJA2CPP_TEST_ORACLE STREQUAL "venv") | ||
| # A file, so the list reaches pip without quoting trouble; the generate step reinstalls when it changes | ||
| set(_oracle_requirements ${_oracle_dir}/requirements.txt) | ||
| string(REPLACE ";" "\n" _oracle_requirement_lines "${JINJA2CPP_TEST_ORACLE_REQUIREMENTS}") | ||
| file(WRITE ${_oracle_requirements}.in "${_oracle_requirement_lines}\n") | ||
| configure_file(${_oracle_requirements}.in ${_oracle_requirements} COPYONLY) | ||
| endif () | ||
|
|
||
| add_test(NAME jinja2cpp_parity_oracle_generate | ||
| COMMAND ${CMAKE_COMMAND} | ||
| -DPYTHON=${_oracle_python} | ||
| -DREQUIREMENTS=${_oracle_requirements} | ||
| -DGENERATE=${CMAKE_CURRENT_SOURCE_DIR}/test/parity/generate.py | ||
| -DOUT=${_oracle_dir} | ||
| -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/parity_oracle_generate.cmake) | ||
| set_tests_properties(jinja2cpp_parity_oracle_generate PROPERTIES FIXTURES_SETUP jinja2cpp_parity_oracle) | ||
|
|
||
| # The narrow suite and the registry checks; the wide suite is held to the narrow result, not | ||
| # to an oracle, so it has nothing to add | ||
| add_test(NAME jinja2cpp_parity_oracle COMMAND jinja2cpp_tests --gtest_filter=Parity/*:ParityRegistry.*) | ||
| set_tests_properties(jinja2cpp_parity_oracle PROPERTIES | ||
| FIXTURES_REQUIRED jinja2cpp_parity_oracle | ||
| ENVIRONMENT "JINJA2CPP_TEST_ORACLE_DIR=${_oracle_dir}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # The setup step of the jinja2cpp_parity_oracle fixture (cmake/parity_oracle.cmake): renders the | ||
| # parity corpus with the other oracle into OUT. | ||
| # cmake -DPYTHON=<interpreter> -DGENERATE=<generate.py> -DOUT=<dir> [-DREQUIREMENTS=<file>] -P parity_oracle_generate.cmake | ||
| # With REQUIREMENTS, PYTHON is the base of a venv in OUT/venv that pip fills from that file. The venv | ||
| # is rebuilt when the file changes; delete OUT/venv to pick up a new commit of a branch requirement. | ||
| foreach (_var PYTHON GENERATE OUT) | ||
| if (NOT ${_var}) | ||
| message(FATAL_ERROR "parity_oracle_generate.cmake needs -D${_var}=...") | ||
| endif () | ||
| endforeach () | ||
|
|
||
| set(_python "${PYTHON}") | ||
| if (REQUIREMENTS) | ||
| set(_venv ${OUT}/venv) | ||
| if (WIN32) | ||
| set(_python ${_venv}/Scripts/python.exe) | ||
| else () | ||
| set(_python ${_venv}/bin/python) | ||
| endif () | ||
| set(_stamp ${_venv}/jinja2cpp-requirements.txt) | ||
| set(_fresh FALSE) | ||
| if (EXISTS ${_stamp} AND EXISTS ${_python}) | ||
| file(READ ${_stamp} _installed) | ||
| file(READ ${REQUIREMENTS} _wanted) | ||
| if (_installed STREQUAL _wanted) | ||
| set(_fresh TRUE) | ||
| endif () | ||
| endif () | ||
| if (NOT _fresh) | ||
| message(STATUS "Creating ${_venv} with ${PYTHON}") | ||
| execute_process(COMMAND "${PYTHON}" -m venv --clear ${_venv} RESULT_VARIABLE _result) | ||
| if (NOT _result EQUAL 0) | ||
| message(FATAL_ERROR "python -m venv failed (${_result})") | ||
| endif () | ||
| execute_process(COMMAND "${_python}" -m pip install --disable-pip-version-check -r ${REQUIREMENTS} RESULT_VARIABLE _result) | ||
| if (NOT _result EQUAL 0) | ||
| message(FATAL_ERROR "pip install -r ${REQUIREMENTS} failed (${_result}); the venv oracle needs network access to the package index") | ||
| endif () | ||
| configure_file(${REQUIREMENTS} ${_stamp} COPYONLY) | ||
| endif () | ||
| endif () | ||
|
|
||
| execute_process(COMMAND "${_python}" -c "import jinja2" RESULT_VARIABLE _result OUTPUT_QUIET ERROR_QUIET) | ||
| if (NOT _result EQUAL 0) | ||
| if (REQUIREMENTS) | ||
| message(FATAL_ERROR "${_python} cannot import jinja2: JINJA2CPP_TEST_ORACLE_REQUIREMENTS must name jinja2") | ||
| endif () | ||
| message(FATAL_ERROR "${_python} cannot import jinja2: install it there, or use JINJA2CPP_TEST_ORACLE=venv") | ||
| endif () | ||
| execute_process(COMMAND "${_python}" ${GENERATE} --out ${OUT} --any-version RESULT_VARIABLE _result) | ||
| if (NOT _result EQUAL 0) | ||
| message(FATAL_ERROR "generate.py --out ${OUT} failed (${_result})") | ||
| endif () | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| status: open | ||
| priority: low | ||
| area: parity | ||
| depends: [0186] | ||
| touches: [test/parity/cases/literals.py, test/parity/cases/string_filters.py, test/parity/expected/literals.json, test/parity/expected/string_filters.json] | ||
| --- | ||
| # Corpus cases on code points whose Unicode properties changed after 15.0 | ||
|
|
||
| **Problem.** Jinja2C++'s generated tables (`src/unicode_printable.h`, `unicode_tables.h`, | ||
| `unicode_case.h`, `unicode_names.h`) follow the pinned Python 3.12, which ships Unicode 15.0. | ||
| Python 3.13 ships 15.1 and 3.14 ships 16.0. The 0186 oracle runs (`JINJA2CPP_TEST_ORACLE`, | ||
| test/parity/README.md "Other oracles") show the Python axis only where the corpus has a case, | ||
| and the corpus has none on a code point that 15.1 or 16.0 assigned or changed: under Python | ||
| 3.13 the measured deltas were stdlib code (`textwrap`, `\N{}` name rules), never table data | ||
| (0186 plan, section 10). A table change between Python versions is therefore invisible to the | ||
| oracle rows of phase 2. | ||
|
|
||
| For example, U+2EBF0 (first ideograph of CJK Extension I, new in 15.1): Python 3.12 gives | ||
| `repr` `'\U0002ebf0'`, `isalpha()` False, no name; Python 3.13 gives `''`, True and | ||
| `CJK UNIFIED IDEOGRAPH-2EBF0`. | ||
|
|
||
| **Proposal.** Add a few cases, in the areas that own each behaviour, on code points new or | ||
| changed in 15.1 and 16.0: `repr` of a string holding one (printable table), `upper`/`lower`/ | ||
| `title` on a cased letter added in 16.0 (case tables), a `\N{...}` escape naming one (names | ||
| table), and `int()`/`wordcount` style uses of `\d`/`\w` if 16.0 changed a digit or word | ||
| property. They match under the pinned 3.12 (no allow-list line), and the 3.13/3.14 oracle rows | ||
| then report them as `tracks-bundled`, which is the record that the Python axis is measured. | ||
|
|
||
| **Done when.** The cases are in the corpus, the bundled suite matches them, and an oracle run | ||
| under Python 3.13 lists them in `report.md`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.