Harbor format: 871 coding_baseline tasks (part 44)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- tasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/tests/trusted-inventory.jsonAdded+62
- tasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/validation/canaries/original-bug.shAdded+3
- tasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/validation/openenv.jsonAdded+27
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/LICENSE.sourceAdded+7
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/adapter.jsonAdded+127
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/dependency-setup.shAdded+17
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/environment/DockerfileAdded+3
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/instruction.mdAdded+37
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/metadata.jsonAdded+386
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/provenance.jsonAdded+88
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/provided-gold.diffAdded+15
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/solution/solve.shAdded+21
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/task.tomlAdded+24
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/check_pytest.pyAdded+177
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/expected-panels.jsonAdded+210
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/grade.pyAdded+128
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/panel-config.jsonAdded+23
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/test.shAdded+6
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted-inventory.jsonAdded+62
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/pyproject.tomlAdded+61
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/pytest.iniAdded+2
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/__init__.pyAdded
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/conftest.pyAdded+27
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_middlewares.pyAdded+105
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_operations.pyAdded+37
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_queries.pyAdded+445
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_storages.pyAdded+281
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_tables.pyAdded+179
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_tinydb.pyAdded+716
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_utils.pyAdded+116
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/validation/canaries/original-bug.shAdded+3
- tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/validation/openenv.jsonAdded+27
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/LICENSE.sourceAdded+7
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/adapter.jsonAdded+127
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/dependency-setup.shAdded+17
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/environment/DockerfileAdded+3
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/instruction.mdAdded+41
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/metadata.jsonAdded+386
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/provenance.jsonAdded+88
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/provided-gold.diffAdded+35
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/solution/solve.shAdded+41
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/task.tomlAdded+24
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/check_pytest.pyAdded+177
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/expected-panels.jsonAdded+210
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/grade.pyAdded+128
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/panel-config.jsonAdded+23
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/test.shAdded+6
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted-inventory.jsonAdded+62
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted/pyproject.tomlAdded+61
- tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted/pytest.iniAdded+2
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "directory_roots": [ "tests" ], "files": { "pyproject.toml": { "bytes": 1846, "mode": 420, "sha256": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be" }, "pytest.ini": { "bytes": 70, "mode": 420, "sha256": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" }, "tests/__init__.py": { "bytes": 0, "mode": 420, "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "tests/conftest.py": { "bytes": 625, "mode": 420, "sha256": "502596fae1843322ec533028a76474d39e6fb70587a5749d8c9dd734b35e625b" }, "tests/test_middlewares.py": { "bytes": 2412, "mode": 420, "sha256": "85a748d3d10e7be042ed37318153a6b79c7913a5d9536cad406ccccad380577b" }, "tests/test_operations.py": { "bytes": 1021, "mode": 420, "sha256": "6313d342626a12973a5532b0b9344c5a30a959d7bfa4f6ca07d147317aee469e" }, "tests/test_queries.py": { "bytes": 12331, "mode": 420, "sha256": "7978c6220a192f4256018bf37d76e6b4c644a962fed4d6fca7d8594b2cf63a49" }, "tests/test_storages.py": { "bytes": 6489, "mode": 420, "sha256": "d74695d20e1d1742fa558da49bc2df8e84ca34e64e001070cbccce215bd39fa2" }, "tests/test_tables.py": { "bytes": 4109, "mode": 420, "sha256": "f018615899e7c9c813aba0820c639f9402d3c9865a376eedaf9dc3ee89b85ef3" }, "tests/test_tinydb.py": { "bytes": 18110, "mode": 420, "sha256": "d106d5e94536afe8416c1b8b01bc63381abb97f81a6a120743e7e1963b07b1d1" }, "tests/test_utils.py": { "bytes": 2257, "mode": 420, "sha256": "659bd414226988e81d2811259c112676aa6bdfa3b9fb6fed4631030ae6d73f2e" } }}123#!/bin/bashset -Eeuo pipefail:123456789101112131415161718192021222324252627{ "canaries": "validation/canaries", "profile": "harbor-semantic-v1", "requires_credentials": false, "resources": { "cpu": 2, "disk_mb": 16384, "episode_timeout_s": 1800, "memory_mb": 8192 }, "reward": { "floor_margin": 0.1, "oracle_tolerance": 0, "range": [ 0, 1 ] }, "reward_key": "reward", "types": { "tags": [ "swe", "python", "mutation-repair" ] }}1234567Copyright (C) 2013 Markus Siemens <markus@m-siemens.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127{ "canary_selection": "Fixed first provided gold hunk only when at least2hunks exist; strict subset, never reward-selected. Single-hunk task original-bug canary is explicitly NOP-equivalent and adds no signal beyond floor_gap.", "collector_sha256": "2a75d35790f6496f754850af247239363d8226867be0988241601d82a0eefc59", "dependency_installation_pinned": false, "dependency_setup_sha256": "0551e0806afd99add5cb7c6184a7e0b4813c16aa421c4031e64e7e3a27b44236", "gold_patch_sha256": "d25f7c52c6eedf21f19339c50d406daf1e92c07d93c363721a4c93349170f779", "hostile_code_isolation_established": false, "known_wrong_semantic_implementations": 0, "native_inventory_sha256": "c855bfeecb949d87ad5ee310b71fdccb479a8284c385533fcb514336e888a8d1", "new_files_deletions_and_executable_modes_supported": true, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "original_bug_canary_nop_equivalent": true, "original_bug_runtime_wrongness_established": false, "partial_repair_canary": false, "partial_repair_sha256": null, "partial_repair_wrongness_established": false, "provided_original_bug_control": true, "repo_url": "https://github.com/swesmith/msiemens__tinydb.10644a0e.git", "runtime_image": null, "runtime_ready": false, "runtime_recipe": { "dependency_installation_pinned": false, "official_install_cmds": [ "python -m pip install -e ." ], "official_pytest_argv": [ "pytest", "--disable-warnings", "--color=no", "--tb=no", "--verbose" ], "official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose", "panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.", "python_version": "3.10", "source_bound_test_dependency_cmds": [ "python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'" ], "test_dependency_source_sha256": { "pyproject.toml": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be", "pytest.ini": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" } }, "runtime_resource_review_required": false, "schema": "python-git-patch-jobs-v1", "source_base_commit": "f179c61be118377ba74036b8e4c08677601f75d5", "source_completion_sha256": "c5edaf5de014610fa5399e23361ca050bf1fc4fa95b5e504080cd6de71273538", "source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876", "source_pr_url": null, "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__4550j9d7", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "371b2b25f3acff68a02528285202c4df1e13aff19b9d9b053d6b612c1993829d", "is_fork": true, "learner_path": "tasks/daaea77ab3478975172c588b/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/f179c61be118377ba74036b8e4c08677601f75d5/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "7e68a1f6993b91db5206d811f40e8fce8959c87149541872514bb1737141ed4c", "provenance_path": "tasks/daaea77ab3478975172c588b/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "f179c61be118377ba74036b8e4c08677601f75d5", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "8522dc68e304e58c5b81071c8f0f660b29aab7a5", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__4550j9d7", "task_sha256": "e5855b57cd0fa566fc2bfc005a1225cd2bc811854f032b0737e61aa1a496cc22", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "source_repo": "swesmith/msiemens__tinydb.10644a0e", "symlink_submodule_changes_supported": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__4550j9d7", "transfer": "index-independent-worktree-to-Git-binary-patch", "transfer_path": "/testbed/submission.patch", "upstream_repo": "msiemens/tinydb"}1234567891011121314151617#!/bin/bashset -Eeuo pipefailsource /opt/miniconda3/bin/activateconda activate testbedcd /testbed/repopython -c 'import sys; assert sys.version_info[:2] == (3, 10)'/usr/bin/sha256sum --check <<'OPENENV_NATIVE_TEST_REQUIREMENT'4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be pyproject.tomlOPENENV_NATIVE_TEST_REQUIREMENTpython -m pip install -e .python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'
cat > /tmp/openenv-tinydb-yaml.txt <<'OPENENV_PYYAML_PIN'PyYAML==6.0.3 --hash=sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0bOPENENV_PYYAML_PINpython -m pip install --no-deps --only-binary=:all: --require-hashes --index-url https://pypi.org/simple -r /tmp/openenv-tinydb-yaml.txtpython -c 'import yaml; assert yaml.__version__ == "6.0.3"'123# Runtime is selected only by an independently qualified immutable amd64 receipt.FROM ubuntu:22.04RUN false12345678910111213141516171819202122232425262728293031323334353637Query.exists() returns False instead of True for existing fields
#### Description
The `Query.exists()` method is returning `False` for fields that actually exist in documents, when it should return `True`.
#### Steps/Code to Reproduce
```pythonfrom tinydb import TinyDB, Query, wherefrom tinydb.storages import MemoryStorage
# Create a test database with some datadb = TinyDB(storage=MemoryStorage)db.insert({'value': 1})db.insert({'value': 2})db.insert({'something': 3})
# This should find documents with 'value' field, but returns empty listquery = Query()['value'].exists()results = db.search(query)print(f"Found {len(results)} documents with 'value' field") # Expected: 2, Actual: 0
# Test with where() syntax - same issueresults2 = db.search(where('value').exists())print(f"Found {len(results2)} documents using where syntax") # Expected: 2, Actual: 0
# Direct query testtest_doc = {'value': 5}print(f"Query matches document: {query(test_doc)}") # Expected: True, Actual: False```
The `exists()` method should return `True` when a field exists in a document, but it's currently returning `False` for all cases.
## Environment
The repository is at `/testbed/repo`. Its dependencies, including pytest, are installed in the `testbed` conda environment, which comes first on PATH. If `python -m pytest` reports that pytest is missing, use the full interpreter path: `/opt/miniconda3/envs/testbed/bin/python -m pytest <tests>`. Don't install packages: the tests need nothing else, and the sandbox may have no network access.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386{ "all_runtime_and_training_flags": false, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "source_healthy_reference_proof": { "FAIL_TO_PASS": [ "tests/test_queries.py::test_path_exists", "tests/test_queries.py::test_path_and", "tests/test_queries.py::test_has_key", "tests/test_queries.py::test_has", "tests/test_tinydb.py::test_insert_multiple[memory]", "tests/test_tinydb.py::test_insert_multiple[json]", "tests/test_tinydb.py::test_search_path[memory]", "tests/test_tinydb.py::test_search_path[json]" ], "PASS_TO_PASS": [ "tests/test_middlewares.py::test_caching", "tests/test_middlewares.py::test_caching_read", "tests/test_middlewares.py::test_caching_write_many", "tests/test_middlewares.py::test_caching_flush", "tests/test_middlewares.py::test_caching_flush_manually", "tests/test_middlewares.py::test_caching_write", "tests/test_middlewares.py::test_nested", "tests/test_middlewares.py::test_caching_json_write", "tests/test_operations.py::test_delete[memory]", "tests/test_operations.py::test_delete[json]", "tests/test_operations.py::test_add_int[memory]", "tests/test_operations.py::test_add_int[json]", "tests/test_operations.py::test_add_str[memory]", "tests/test_operations.py::test_add_str[json]", "tests/test_operations.py::test_subtract[memory]", "tests/test_operations.py::test_subtract[json]", "tests/test_operations.py::test_set[memory]", "tests/test_operations.py::test_set[json]", "tests/test_operations.py::test_increment[memory]", "tests/test_operations.py::test_increment[json]", "tests/test_operations.py::test_decrement[memory]", "tests/test_operations.py::test_decrement[json]", "tests/test_queries.py::test_no_path", "tests/test_queries.py::test_callable_in_path_with_map", "tests/test_queries.py::test_callable_in_path_with_chain", "tests/test_queries.py::test_eq", "tests/test_queries.py::test_ne", "tests/test_queries.py::test_lt", "tests/test_queries.py::test_le", "tests/test_queries.py::test_gt", "tests/test_queries.py::test_ge", "tests/test_queries.py::test_or", "tests/test_queries.py::test_and", "tests/test_queries.py::test_not", "tests/test_queries.py::test_regex", "tests/test_queries.py::test_custom", "tests/test_queries.py::test_custom_with_params", "tests/test_queries.py::test_any", "tests/test_queries.py::test_all", "tests/test_queries.py::test_one_of", "tests/test_queries.py::test_hash", "tests/test_queries.py::test_orm_usage", "tests/test_queries.py::test_repr", "tests/test_queries.py::test_subclass", "tests/test_queries.py::test_noop", "tests/test_queries.py::test_equality", "tests/test_queries.py::test_empty_query_error", "tests/test_queries.py::test_fragment", "tests/test_queries.py::test_fragment_with_path", "tests/test_queries.py::test_get_item", "tests/test_storages.py::test_json", "tests/test_storages.py::test_json_kwargs", "tests/test_storages.py::test_json_readwrite", "tests/test_storages.py::test_json_read", "tests/test_storages.py::test_create_dirs", "tests/test_storages.py::test_json_invalid_directory", "tests/test_storages.py::test_in_memory", "tests/test_storages.py::test_in_memory_close", "tests/test_storages.py::test_custom", "tests/test_storages.py::test_read_once", "tests/test_storages.py::test_custom_with_exception", "tests/test_storages.py::test_yaml", "tests/test_storages.py::test_encoding", "tests/test_tables.py::test_next_id[memory]", "tests/test_tables.py::test_next_id[json]", "tests/test_tables.py::test_tables_list[memory]", "tests/test_tables.py::test_tables_list[json]", "tests/test_tables.py::test_one_table[memory]", "tests/test_tables.py::test_one_table[json]", "tests/test_tables.py::test_multiple_tables[memory]", "tests/test_tables.py::test_multiple_tables[json]", "tests/test_tables.py::test_caching[memory]", "tests/test_tables.py::test_caching[json]", "tests/test_tables.py::test_query_cache[memory]", "tests/test_tables.py::test_query_cache[json]", "tests/test_tables.py::test_query_cache_with_mutable_callable[memory]", "tests/test_tables.py::test_query_cache_with_mutable_callable[json]", "tests/test_tables.py::test_zero_cache_size[memory]", "tests/test_tables.py::test_zero_cache_size[json]", "tests/test_tables.py::test_query_cache_size[memory]", "tests/test_tables.py::test_query_cache_size[json]", "tests/test_tables.py::test_lru_cache[memory]", "tests/test_tables.py::test_lru_cache[json]", "tests/test_tables.py::test_table_is_iterable[memory]", "tests/test_tables.py::test_table_is_iterable[json]", "tests/test_tables.py::test_table_name[memory]", "tests/test_tables.py::test_table_name[json]", "tests/test_tables.py::test_table_repr[memory]", "tests/test_tables.py::test_table_repr[json]", "tests/test_tables.py::test_truncate_table[memory]", "tests/test_tables.py::test_truncate_table[json]", "tests/test_tables.py::test_persist_table[memory]", "tests/test_tables.py::test_persist_table[json]", "tests/test_tinydb.py::test_drop_tables[memory]", "tests/test_tinydb.py::test_drop_tables[json]", "tests/test_tinydb.py::test_all[memory]", "tests/test_tinydb.py::test_all[json]", "tests/test_tinydb.py::test_insert[memory]", "tests/test_tinydb.py::test_insert[json]", "tests/test_tinydb.py::test_insert_ids[memory]", "tests/test_tinydb.py::test_insert_ids[json]", "tests/test_tinydb.py::test_insert_with_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_doc_id[json]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[json]", "tests/test_tinydb.py::test_insert_multiple_with_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_ids[json]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[json]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[memory]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[json]", "tests/test_tinydb.py::test_insert_valid_mapping_type[memory]", "tests/test_tinydb.py::test_insert_valid_mapping_type[json]", "tests/test_tinydb.py::test_custom_mapping_type_with_json", "tests/test_tinydb.py::test_remove[memory]", "tests/test_tinydb.py::test_remove[json]", "tests/test_tinydb.py::test_remove_all_fails[memory]", "tests/test_tinydb.py::test_remove_all_fails[json]", "tests/test_tinydb.py::test_remove_multiple[memory]", "tests/test_tinydb.py::test_remove_multiple[json]", "tests/test_tinydb.py::test_remove_ids[memory]", "tests/test_tinydb.py::test_remove_ids[json]", "tests/test_tinydb.py::test_remove_returns_ids[memory]", "tests/test_tinydb.py::test_remove_returns_ids[json]", "tests/test_tinydb.py::test_update[memory]", "tests/test_tinydb.py::test_update[json]", "tests/test_tinydb.py::test_update_all[memory]", "tests/test_tinydb.py::test_update_all[json]", "tests/test_tinydb.py::test_update_returns_ids[memory]", "tests/test_tinydb.py::test_update_returns_ids[json]", "tests/test_tinydb.py::test_update_transform[memory]", "tests/test_tinydb.py::test_update_transform[json]", "tests/test_tinydb.py::test_update_ids[memory]", "tests/test_tinydb.py::test_update_ids[json]", "tests/test_tinydb.py::test_update_multiple[memory]", "tests/test_tinydb.py::test_update_multiple[json]", "tests/test_tinydb.py::test_update_multiple_operation[memory]", "tests/test_tinydb.py::test_update_multiple_operation[json]", "tests/test_tinydb.py::test_upsert[memory]", "tests/test_tinydb.py::test_upsert[json]", "tests/test_tinydb.py::test_upsert_by_id[memory]", "tests/test_tinydb.py::test_upsert_by_id[json]", "tests/test_tinydb.py::test_search[memory]", "tests/test_tinydb.py::test_search[json]", "tests/test_tinydb.py::test_search_no_results_cache[memory]", "tests/test_tinydb.py::test_search_no_results_cache[json]", "tests/test_tinydb.py::test_get[memory]", "tests/test_tinydb.py::test_get[json]", "tests/test_tinydb.py::test_get_ids[memory]", "tests/test_tinydb.py::test_get_ids[json]", "tests/test_tinydb.py::test_get_multiple_ids[memory]", "tests/test_tinydb.py::test_get_multiple_ids[json]", "tests/test_tinydb.py::test_get_invalid[memory]", "tests/test_tinydb.py::test_get_invalid[json]", "tests/test_tinydb.py::test_count[memory]", "tests/test_tinydb.py::test_count[json]", "tests/test_tinydb.py::test_contains[memory]", "tests/test_tinydb.py::test_contains[json]", "tests/test_tinydb.py::test_contains_ids[memory]", "tests/test_tinydb.py::test_contains_ids[json]", "tests/test_tinydb.py::test_contains_invalid[memory]", "tests/test_tinydb.py::test_contains_invalid[json]", "tests/test_tinydb.py::test_get_idempotent[memory]", "tests/test_tinydb.py::test_get_idempotent[json]", "tests/test_tinydb.py::test_multiple_dbs", "tests/test_tinydb.py::test_storage_closed_once", "tests/test_tinydb.py::test_unique_ids", "tests/test_tinydb.py::test_lastid_after_open", "tests/test_tinydb.py::test_doc_ids_json", "tests/test_tinydb.py::test_insert_string", "tests/test_tinydb.py::test_insert_invalid_dict", "tests/test_tinydb.py::test_gc", "tests/test_tinydb.py::test_drop_table", "tests/test_tinydb.py::test_empty_write", "tests/test_tinydb.py::test_query_cache", "tests/test_tinydb.py::test_tinydb_is_iterable[memory]", "tests/test_tinydb.py::test_tinydb_is_iterable[json]", "tests/test_tinydb.py::test_repr", "tests/test_tinydb.py::test_delete", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[memory]", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[json]", "tests/test_tinydb.py::test_access_storage", "tests/test_tinydb.py::test_empty_db_len", "tests/test_tinydb.py::test_insert_on_existing_db", "tests/test_tinydb.py::test_storage_access", "tests/test_tinydb.py::test_lambda_query", "tests/test_utils.py::test_lru_cache", "tests/test_utils.py::test_lru_cache_set_multiple", "tests/test_utils.py::test_lru_cache_set_update", "tests/test_utils.py::test_lru_cache_get", "tests/test_utils.py::test_lru_cache_delete", "tests/test_utils.py::test_lru_cache_clear", "tests/test_utils.py::test_lru_cache_unlimited", "tests/test_utils.py::test_lru_cache_unlimited_explicit", "tests/test_utils.py::test_lru_cache_iteration_works", "tests/test_utils.py::test_freeze" ], "all_git_blobs_modes_verified": true, "cloud_launch_ready": false, "commits": { "bug": "8522dc68e304e58c5b81071c8f0f660b29aab7a5", "healthy": "278700580526dd378f18f40b641885ec78df63e1", "learner": "f179c61be118377ba74036b8e4c08677601f75d5" }, "existing_squirrel_snapshot_reused": false, "full_transfer_allowlist": [ "/testbed/.coveragerc", "/testbed/.github/stale.yml", "/testbed/.gitignore", "/testbed/.readthedocs.yml", "/testbed/CONTRIBUTING.rst", "/testbed/LICENSE", "/testbed/MANIFEST.in", "/testbed/README.rst", "/testbed/artwork/logo.png", "/testbed/artwork/logo.svg", "/testbed/docs/.gitignore", "/testbed/docs/Makefile", "/testbed/docs/_static/logo.png", "/testbed/docs/_templates/links.html", "/testbed/docs/_templates/sidebarlogo.html", "/testbed/docs/_themes/.gitignore", "/testbed/docs/_themes/LICENSE", "/testbed/docs/_themes/README", "/testbed/docs/_themes/flask/layout.html", "/testbed/docs/_themes/flask/page.html", "/testbed/docs/_themes/flask/relations.html", "/testbed/docs/_themes/flask/static/flasky.css_t", "/testbed/docs/_themes/flask/theme.conf", "/testbed/docs/_themes/flask_theme_support.py", "/testbed/docs/api.rst", "/testbed/docs/changelog.rst", "/testbed/docs/conf.py", "/testbed/docs/contribute.rst", "/testbed/docs/extend.rst", "/testbed/docs/extensions.rst", "/testbed/docs/getting-started.rst", "/testbed/docs/index.rst", "/testbed/docs/intro.rst", "/testbed/docs/make.bat", "/testbed/docs/upgrade.rst", "/testbed/docs/usage.rst", "/testbed/mypy.ini", "/testbed/poetry.lock", "/testbed/pyproject.toml", "/testbed/pytest.ini", "/testbed/tests/__init__.py", "/testbed/tests/conftest.py", "/testbed/tests/test_middlewares.py", "/testbed/tests/test_operations.py", "/testbed/tests/test_storages.py", "/testbed/tests/test_tables.py", "/testbed/tests/test_utils.py", "/testbed/tinydb/__init__.py", "/testbed/tinydb/database.py", "/testbed/tinydb/middlewares.py", "/testbed/tinydb/mypy_plugin.py", "/testbed/tinydb/operations.py", "/testbed/tinydb/py.typed", "/testbed/tinydb/queries.py", "/testbed/tinydb/storages.py", "/testbed/tinydb/table.py", "/testbed/tinydb/utils.py", "/testbed/tinydb/version.py" ], "healthy_stage_meaning": "Direct parent of the mutation; no source or test execution has been performed", "mutation_matches_dataset_and_git_blobs": true, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "private_test_paths": [ "tests/test_queries.py", "tests/test_tinydb.py" ], "private_tests_unchanged": true, "profile_mapping_basis": "Explicit upstream repo and full commit fields parsed from pinned official Python profile AST, not basename inference", "qwen_calibrated": false, "runtime_qualified": false, "source_paths": [ "tinydb/queries.py" ], "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_stages_bytes": 927478, "task_id": "msiemens__tinydb.10644a0e.func_basic__4550j9d7", "transfer_limitation": "Existing regular files only; new arbitrary file additions need a qualified patch adapter", "upstream_repo": "msiemens/tinydb" }, "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__4550j9d7", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "371b2b25f3acff68a02528285202c4df1e13aff19b9d9b053d6b612c1993829d", "is_fork": true, "learner_path": "tasks/daaea77ab3478975172c588b/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/f179c61be118377ba74036b8e4c08677601f75d5/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "7e68a1f6993b91db5206d811f40e8fce8959c87149541872514bb1737141ed4c", "provenance_path": "tasks/daaea77ab3478975172c588b/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "f179c61be118377ba74036b8e4c08677601f75d5", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "8522dc68e304e58c5b81071c8f0f660b29aab7a5", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__4550j9d7", "task_sha256": "e5855b57cd0fa566fc2bfc005a1225cd2bc811854f032b0737e61aa1a496cc22", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "task_kind": "original-source-mutation"}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788{ "generated_reference": false, "healthy_reference_delta_sha256": "d25f7c52c6eedf21f19339c50d406daf1e92c07d93c363721a4c93349170f779", "native_pytest_ids_preserved": true, "original_source_code_license": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/f179c61be118377ba74036b8e4c08677601f75d5/LICENSE" }, "provided_reference": true, "qwen_calibrated": false, "runtime_qualified": false, "source_completion_sha256": "c5edaf5de014610fa5399e23361ca050bf1fc4fa95b5e504080cd6de71273538", "source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876", "source_proof_sha256": "c9193e7a83cc717dcd173ce76fd29c3982813c2061c6df704add77827716830d", "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__4550j9d7", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "371b2b25f3acff68a02528285202c4df1e13aff19b9d9b053d6b612c1993829d", "is_fork": true, "learner_path": "tasks/daaea77ab3478975172c588b/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/f179c61be118377ba74036b8e4c08677601f75d5/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "7e68a1f6993b91db5206d811f40e8fce8959c87149541872514bb1737141ed4c", "provenance_path": "tasks/daaea77ab3478975172c588b/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "f179c61be118377ba74036b8e4c08677601f75d5", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "8522dc68e304e58c5b81071c8f0f660b29aab7a5", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__4550j9d7", "task_sha256": "e5855b57cd0fa566fc2bfc005a1225cd2bc811854f032b0737e61aa1a496cc22", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "task_bundle_license": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" }, "training_admissible": false, "trusted_tests_sha256": "ff9a5ef814fab3aeaea8a510213b4330c9b7600d0e4cd9f29754ec6179c0d458"}123456789101112131415diff --git a/tinydb/queries.py b/tinydb/queries.pyindex 4fe011fa4fcefd06247013d393dafec7bce33f92..0ef6a69b545e23bbe3acb710b9200190dd6acd78 100644--- a/tinydb/queries.py+++ b/tinydb/queries.py@@ -325,8 +325,8 @@ >>> Query().f1.exists() """ return self._generate_test(- lambda _: False,- ('missing', self._path)+ lambda _: True,+ ('exists', self._path) ) def matches(self, regex: str, flags: int = 0) -> QueryInstance:123456789101112131415161718192021#!/bin/bashset -Eeuo pipefailcd /testbed/repocat > /tmp/openenv-reference.diff <<'OPENENV_REFERENCE'diff --git a/tinydb/queries.py b/tinydb/queries.pyindex 4fe011fa4fcefd06247013d393dafec7bce33f92..0ef6a69b545e23bbe3acb710b9200190dd6acd78 100644--- a/tinydb/queries.py+++ b/tinydb/queries.py@@ -325,8 +325,8 @@ >>> Query().f1.exists() """ return self._generate_test(- lambda _: False,- ('missing', self._path)+ lambda _: True,+ ('exists', self._path) ) def matches(self, regex: str, flags: int = 0) -> QueryInstance:OPENENV_REFERENCE/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff123456789101112131415161718192021222324version = "1.0"
[agent]timeout_sec = 1800.0
[verifier]timeout_sec = 900.0
[environment]docker_image = "ghcr.io/younesbelkada/scale800@sha256:1ccfa02601febeda887bd28796526bb5c5d4852f8a0aa02545cc216173fdc358"build_timeout_sec = 600.0cpus = 2memory_mb = 8192storage_mb = 16384
[metadata]author_name = "SWE-smith source adapter"category = "bugfix"tags = ["swe", "python", "mutation-repair"]
[environment.env]# The image's PATH with the testbed env first: the project and pytest are installed there, and the agent's# non-interactive shells never run `conda activate`PATH = "/opt/miniconda3/envs/testbed/bin:/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177"""Preserve confirmed requested assertion failures; keep positive checks strict."""
import argparseimport hashlibimport jsonimport reimport xml.etree.ElementTree as ETfrom pathlib import Path
GROUPS = ("pass-to-pass", "fail-to-pass")
def split_nodeid(target): prefix, bracket, parameter = target.partition("[") parts = prefix.split("::") if bracket: parts[-1] += bracket + parameter return parts
def matches(case, target): parts = split_nodeid(target) module = parts[0].removesuffix(".py").replace("/", ".") classname, name = case.get("classname", ""), case.get("name", "") if not (classname == module or classname.startswith(module + ".")): return False selector = parts[-1] if len(parts) > 1 else "" classes = parts[1:-1] if classes and classname != module + "." + ".".join(classes): return False return ( not selector or name == selector or ("[" not in selector and name.startswith(selector + "[")) )
def capture_panels(root): panels, digests = {}, {} for group in GROUPS: path = Path(root) / (group + ".xml") if not path.exists(): panels[group] = None continue with path.open("rb") as stream: raw = stream.read(4 * 1024**2 + 1) if not 0 < len(raw) <= 4 * 1024**2 or re.search( rb"<!\s*(?:DOCTYPE|ENTITY)", raw, re.I ): raise ValueError("Unbounded or unsafe pytest XML") try: tree = ET.fromstring(raw) except ET.ParseError: raise ValueError("Malformed pytest XML") from None cases = list(tree.iter("testcase")) if len(cases) > 20000: raise ValueError("Too many pytest cases") identities = [(case.get("classname"), case.get("name")) for case in cases] if len(identities) != len(set(identities)): raise ValueError("Duplicate pytest case evidence") panels[group] = cases digests[group] = hashlib.sha256(raw).hexdigest() return panels, digests
def strict_assess(panels, expected, native_exit): """The original positive-approval conditions, applied to captured cases.""" all_cases, actual_failure = [], False for group in GROUPS: cases = panels[group] if cases is None: if actual_failure: continue raise ValueError("Missing preceding pytest panel") if actual_failure: raise ValueError( "Pytest evidence continued after the native stop-on-failure" ) targets = expected[group] if any(not any(matches(case, target) for target in targets) for case in cases): raise ValueError("Unexpected pytest case") all_cases.extend(cases) failures = [case for case in cases if case.find("failure") is not None] if any( case.find("error") is not None or case.find("skipped") is not None for case in cases ): raise ValueError("Pytest collection/error/skip is not a completed panel") actual_failure = actual_failure or bool(failures) if not failures and any( not any(matches(case, target) for case in cases) for target in targets ): raise ValueError("Declared pytest target never ran") if actual_failure: if native_exit == 0: raise ValueError("Native verifier exit disagrees with pytest failure") return {"reward": 0, "valid_test_failure": True, "cases": len(all_cases)} if native_exit != 0: raise ValueError("Setup or native verifier failed without a real test failure") if any(panels[group] is None for group in GROUPS): raise ValueError("Missing completed pytest panel") return {"reward": 1, "valid_test_failure": False, "cases": len(all_cases)}
def assess(root, expected, native_exit): if type(native_exit) is not int: raise ValueError("Native verifier exit must be an integer") if not isinstance(expected, dict) or any( not isinstance(expected.get(group), list) or not expected[group] or any(not isinstance(target, str) or not target for target in expected[group]) for group in GROUPS ): raise ValueError("Complete exact native pytest targets required") panels, digests = capture_panels(root) counts = { "cases": 0, "matched_failures": 0, "unexpected_cases": 0, "unmatched_failures": 0, "skipped_cases": 0, "error_cases": 0, "missing_panels": 0, "missing_targets": 0, } for group in GROUPS: cases = panels[group] if cases is None: counts["missing_panels"] += 1 counts["missing_targets"] += len(expected[group]) continue counts["cases"] += len(cases) for case in cases: requested = any(matches(case, target) for target in expected[group]) failure = case.find("failure") is not None counts["matched_failures"] += int(requested and failure) counts["unmatched_failures"] += int(not requested and failure) counts["unexpected_cases"] += int(not requested) counts["skipped_cases"] += int(case.find("skipped") is not None) counts["error_cases"] += int(case.find("error") is not None) counts["missing_targets"] += sum( not any(matches(case, target) for case in cases) for target in expected[group] ) if counts["matched_failures"]: if native_exit == 0: raise ValueError( "Native verifier exit disagrees with requested pytest failure" ) return { "reward": 0, "valid_test_failure": True, "cases": counts["cases"], "diagnostic_counts": counts, "panel_sha256": digests, "decision": "confirmed_requested_failure_precedence", } result = strict_assess(panels, expected, native_exit) result.update(diagnostic_counts=counts, panel_sha256=digests) return result
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--root", required=True) parser.add_argument("--expected", required=True) parser.add_argument("--native-exit", type=int, required=True) args = parser.parse_args() result = assess( args.root, json.loads(Path(args.expected).read_bytes()), args.native_exit ) reward = Path(args.root) / "reward.txt" if reward.read_text().strip() != str(result["reward"]): raise ValueError("Native raw reward disagrees with pytest evidence") (Path(args.root) / "pytest-evidence.json").write_text( json.dumps(result, sort_keys=True) + "\n" )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210{ "fail-to-pass": [ "tests/test_queries.py::test_path_exists", "tests/test_queries.py::test_path_and", "tests/test_queries.py::test_has_key", "tests/test_queries.py::test_has", "tests/test_tinydb.py::test_insert_multiple[memory]", "tests/test_tinydb.py::test_insert_multiple[json]", "tests/test_tinydb.py::test_search_path[memory]", "tests/test_tinydb.py::test_search_path[json]" ], "pass-to-pass": [ "tests/test_middlewares.py::test_caching", "tests/test_middlewares.py::test_caching_read", "tests/test_middlewares.py::test_caching_write_many", "tests/test_middlewares.py::test_caching_flush", "tests/test_middlewares.py::test_caching_flush_manually", "tests/test_middlewares.py::test_caching_write", "tests/test_middlewares.py::test_nested", "tests/test_middlewares.py::test_caching_json_write", "tests/test_operations.py::test_delete[memory]", "tests/test_operations.py::test_delete[json]", "tests/test_operations.py::test_add_int[memory]", "tests/test_operations.py::test_add_int[json]", "tests/test_operations.py::test_add_str[memory]", "tests/test_operations.py::test_add_str[json]", "tests/test_operations.py::test_subtract[memory]", "tests/test_operations.py::test_subtract[json]", "tests/test_operations.py::test_set[memory]", "tests/test_operations.py::test_set[json]", "tests/test_operations.py::test_increment[memory]", "tests/test_operations.py::test_increment[json]", "tests/test_operations.py::test_decrement[memory]", "tests/test_operations.py::test_decrement[json]", "tests/test_queries.py::test_no_path", "tests/test_queries.py::test_callable_in_path_with_map", "tests/test_queries.py::test_callable_in_path_with_chain", "tests/test_queries.py::test_eq", "tests/test_queries.py::test_ne", "tests/test_queries.py::test_lt", "tests/test_queries.py::test_le", "tests/test_queries.py::test_gt", "tests/test_queries.py::test_ge", "tests/test_queries.py::test_or", "tests/test_queries.py::test_and", "tests/test_queries.py::test_not", "tests/test_queries.py::test_regex", "tests/test_queries.py::test_custom", "tests/test_queries.py::test_custom_with_params", "tests/test_queries.py::test_any", "tests/test_queries.py::test_all", "tests/test_queries.py::test_one_of", "tests/test_queries.py::test_hash", "tests/test_queries.py::test_orm_usage", "tests/test_queries.py::test_repr", "tests/test_queries.py::test_subclass", "tests/test_queries.py::test_noop", "tests/test_queries.py::test_equality", "tests/test_queries.py::test_empty_query_error", "tests/test_queries.py::test_fragment", "tests/test_queries.py::test_fragment_with_path", "tests/test_queries.py::test_get_item", "tests/test_storages.py::test_json", "tests/test_storages.py::test_json_kwargs", "tests/test_storages.py::test_json_readwrite", "tests/test_storages.py::test_json_read", "tests/test_storages.py::test_create_dirs", "tests/test_storages.py::test_json_invalid_directory", "tests/test_storages.py::test_in_memory", "tests/test_storages.py::test_in_memory_close", "tests/test_storages.py::test_custom", "tests/test_storages.py::test_read_once", "tests/test_storages.py::test_custom_with_exception", "tests/test_storages.py::test_yaml", "tests/test_storages.py::test_encoding", "tests/test_tables.py::test_next_id[memory]", "tests/test_tables.py::test_next_id[json]", "tests/test_tables.py::test_tables_list[memory]", "tests/test_tables.py::test_tables_list[json]", "tests/test_tables.py::test_one_table[memory]", "tests/test_tables.py::test_one_table[json]", "tests/test_tables.py::test_multiple_tables[memory]", "tests/test_tables.py::test_multiple_tables[json]", "tests/test_tables.py::test_caching[memory]", "tests/test_tables.py::test_caching[json]", "tests/test_tables.py::test_query_cache[memory]", "tests/test_tables.py::test_query_cache[json]", "tests/test_tables.py::test_query_cache_with_mutable_callable[memory]", "tests/test_tables.py::test_query_cache_with_mutable_callable[json]", "tests/test_tables.py::test_zero_cache_size[memory]", "tests/test_tables.py::test_zero_cache_size[json]", "tests/test_tables.py::test_query_cache_size[memory]", "tests/test_tables.py::test_query_cache_size[json]", "tests/test_tables.py::test_lru_cache[memory]", "tests/test_tables.py::test_lru_cache[json]", "tests/test_tables.py::test_table_is_iterable[memory]", "tests/test_tables.py::test_table_is_iterable[json]", "tests/test_tables.py::test_table_name[memory]", "tests/test_tables.py::test_table_name[json]", "tests/test_tables.py::test_table_repr[memory]", "tests/test_tables.py::test_table_repr[json]", "tests/test_tables.py::test_truncate_table[memory]", "tests/test_tables.py::test_truncate_table[json]", "tests/test_tables.py::test_persist_table[memory]", "tests/test_tables.py::test_persist_table[json]", "tests/test_tinydb.py::test_drop_tables[memory]", "tests/test_tinydb.py::test_drop_tables[json]", "tests/test_tinydb.py::test_all[memory]", "tests/test_tinydb.py::test_all[json]", "tests/test_tinydb.py::test_insert[memory]", "tests/test_tinydb.py::test_insert[json]", "tests/test_tinydb.py::test_insert_ids[memory]", "tests/test_tinydb.py::test_insert_ids[json]", "tests/test_tinydb.py::test_insert_with_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_doc_id[json]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[json]", "tests/test_tinydb.py::test_insert_multiple_with_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_ids[json]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[json]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[memory]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[json]", "tests/test_tinydb.py::test_insert_valid_mapping_type[memory]", "tests/test_tinydb.py::test_insert_valid_mapping_type[json]", "tests/test_tinydb.py::test_custom_mapping_type_with_json", "tests/test_tinydb.py::test_remove[memory]", "tests/test_tinydb.py::test_remove[json]", "tests/test_tinydb.py::test_remove_all_fails[memory]", "tests/test_tinydb.py::test_remove_all_fails[json]", "tests/test_tinydb.py::test_remove_multiple[memory]", "tests/test_tinydb.py::test_remove_multiple[json]", "tests/test_tinydb.py::test_remove_ids[memory]", "tests/test_tinydb.py::test_remove_ids[json]", "tests/test_tinydb.py::test_remove_returns_ids[memory]", "tests/test_tinydb.py::test_remove_returns_ids[json]", "tests/test_tinydb.py::test_update[memory]", "tests/test_tinydb.py::test_update[json]", "tests/test_tinydb.py::test_update_all[memory]", "tests/test_tinydb.py::test_update_all[json]", "tests/test_tinydb.py::test_update_returns_ids[memory]", "tests/test_tinydb.py::test_update_returns_ids[json]", "tests/test_tinydb.py::test_update_transform[memory]", "tests/test_tinydb.py::test_update_transform[json]", "tests/test_tinydb.py::test_update_ids[memory]", "tests/test_tinydb.py::test_update_ids[json]", "tests/test_tinydb.py::test_update_multiple[memory]", "tests/test_tinydb.py::test_update_multiple[json]", "tests/test_tinydb.py::test_update_multiple_operation[memory]", "tests/test_tinydb.py::test_update_multiple_operation[json]", "tests/test_tinydb.py::test_upsert[memory]", "tests/test_tinydb.py::test_upsert[json]", "tests/test_tinydb.py::test_upsert_by_id[memory]", "tests/test_tinydb.py::test_upsert_by_id[json]", "tests/test_tinydb.py::test_search[memory]", "tests/test_tinydb.py::test_search[json]", "tests/test_tinydb.py::test_search_no_results_cache[memory]", "tests/test_tinydb.py::test_search_no_results_cache[json]", "tests/test_tinydb.py::test_get[memory]", "tests/test_tinydb.py::test_get[json]", "tests/test_tinydb.py::test_get_ids[memory]", "tests/test_tinydb.py::test_get_ids[json]", "tests/test_tinydb.py::test_get_multiple_ids[memory]", "tests/test_tinydb.py::test_get_multiple_ids[json]", "tests/test_tinydb.py::test_get_invalid[memory]", "tests/test_tinydb.py::test_get_invalid[json]", "tests/test_tinydb.py::test_count[memory]", "tests/test_tinydb.py::test_count[json]", "tests/test_tinydb.py::test_contains[memory]", "tests/test_tinydb.py::test_contains[json]", "tests/test_tinydb.py::test_contains_ids[memory]", "tests/test_tinydb.py::test_contains_ids[json]", "tests/test_tinydb.py::test_contains_invalid[memory]", "tests/test_tinydb.py::test_contains_invalid[json]", "tests/test_tinydb.py::test_get_idempotent[memory]", "tests/test_tinydb.py::test_get_idempotent[json]", "tests/test_tinydb.py::test_multiple_dbs", "tests/test_tinydb.py::test_storage_closed_once", "tests/test_tinydb.py::test_unique_ids", "tests/test_tinydb.py::test_lastid_after_open", "tests/test_tinydb.py::test_doc_ids_json", "tests/test_tinydb.py::test_insert_string", "tests/test_tinydb.py::test_insert_invalid_dict", "tests/test_tinydb.py::test_gc", "tests/test_tinydb.py::test_drop_table", "tests/test_tinydb.py::test_empty_write", "tests/test_tinydb.py::test_query_cache", "tests/test_tinydb.py::test_tinydb_is_iterable[memory]", "tests/test_tinydb.py::test_tinydb_is_iterable[json]", "tests/test_tinydb.py::test_repr", "tests/test_tinydb.py::test_delete", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[memory]", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[json]", "tests/test_tinydb.py::test_access_storage", "tests/test_tinydb.py::test_empty_db_len", "tests/test_tinydb.py::test_insert_on_existing_db", "tests/test_tinydb.py::test_storage_access", "tests/test_tinydb.py::test_lambda_query", "tests/test_utils.py::test_lru_cache", "tests/test_utils.py::test_lru_cache_set_multiple", "tests/test_utils.py::test_lru_cache_set_update", "tests/test_utils.py::test_lru_cache_get", "tests/test_utils.py::test_lru_cache_delete", "tests/test_utils.py::test_lru_cache_clear", "tests/test_utils.py::test_lru_cache_unlimited", "tests/test_utils.py::test_lru_cache_unlimited_explicit", "tests/test_utils.py::test_lru_cache_iteration_works", "tests/test_utils.py::test_freeze" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128"""Trusted private pytest panel runner. Installed only in a fresh grader Job."""
import hashlibimport importlib.utilimport jsonimport osimport shutilimport statimport subprocessfrom pathlib import Path, PurePosixPath
def sha(raw): return hashlib.sha256(raw).hexdigest()
def safe(value): path = PurePosixPath(value) if ( path.is_absolute() or path.as_posix() != value or not path.parts or any(part in {".", "..", ".git"} for part in path.parts) ): raise ValueError("Unsafe trusted test path") return path
def restore(worktree, private, manifest): worktree, private = Path(worktree), Path(private) captured = {} for name, expected in manifest["files"].items(): path = private / safe(name) info = path.lstat() raw = path.read_bytes() if stat.S_ISREG(info.st_mode) else b"" if ( not stat.S_ISREG(info.st_mode) or len(raw) != expected["bytes"] or sha(raw) != expected["sha256"] or stat.S_IMODE(info.st_mode) != expected["mode"] ): raise ValueError("Trusted private test bytes or modes drifted") captured[name] = (raw, expected["mode"]) # Capture and verify every private byte before changing the submitted tree. for name in manifest["directory_roots"]: destination = worktree / safe(name) if destination.is_symlink(): raise ValueError("Submitted test directory is a symlink") for parent in destination.parents: if parent == worktree: break if parent.is_symlink(): raise ValueError("Submitted test parent is a symlink") if destination.exists(): if not destination.is_dir(): raise ValueError("Submitted test directory is not a directory") shutil.rmtree(destination) for name, (raw, mode) in captured.items(): destination = worktree / safe(name) for parent in destination.parents: if parent == worktree: break if parent.is_symlink(): raise ValueError("Submitted test parent is a symlink") if destination.is_symlink(): raise ValueError("Submitted trusted file is a symlink") destination.parent.mkdir(parents=True, exist_ok=True) destination.write_bytes(raw) destination.chmod(mode)
def run(worktree, private_root, output, invoke=None): private_root, output, worktree = Path(private_root), Path(output), Path(worktree) expected = json.loads((private_root / "expected-panels.json").read_bytes()) config = json.loads((private_root / "panel-config.json").read_bytes()) manifest = json.loads((private_root / "trusted-inventory.json").read_bytes()) restore(worktree, private_root / "trusted", manifest) output.mkdir(parents=True, exist_ok=True) for name in ( "reward.txt", "pass-to-pass.xml", "fail-to-pass.xml", "pytest-evidence.json", ): (output / name).unlink(missing_ok=True) environment = dict(os.environ) for key in ("PYTEST_ADDOPTS", "PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTHONPATH"): environment.pop(key, None) commands, native_exit = [], 0 invoke = invoke or subprocess.run for group in ("pass-to-pass", "fail-to-pass"): if ( not isinstance(expected[group], list) or not expected[group] or any( not isinstance(target, str) or not target for target in expected[group] ) ): raise ValueError("Frozen native pytest selectors are incomplete") command = [ *config["official_pytest_argv"], "--override-ini=addopts=", "--junitxml=" + str(output / (group + ".xml")), *expected[group], ] result = invoke(command, cwd=worktree, env=environment, check=False) native_exit = result.returncode commands.append({"group": group, "argv": command, "exit_code": native_exit}) if native_exit != 0: break (output / "pytest-commands.json").write_text( json.dumps(commands, sort_keys=True) + "\n" ) spec = importlib.util.spec_from_file_location( "trusted_pytest_result", private_root / "check_pytest.py" ) checker = importlib.util.module_from_spec(spec) spec.loader.exec_module(checker) result = checker.assess(output, expected, native_exit) (output / "reward.txt").write_text(str(result["reward"]) + "\n") (output / "pytest-evidence.json").write_text( json.dumps(result, sort_keys=True) + "\n" ) return result
if __name__ == "__main__": run("/testbed/repo", "/tests", "/logs/verifier")1234567891011121314151617181920212223{ "dependency_installation_pinned": false, "official_install_cmds": [ "python -m pip install -e ." ], "official_pytest_argv": [ "pytest", "--disable-warnings", "--color=no", "--tb=no", "--verbose" ], "official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose", "panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.", "python_version": "3.10", "source_bound_test_dependency_cmds": [ "python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'" ], "test_dependency_source_sha256": { "pyproject.toml": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be", "pytest.ini": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" }}123456#!/bin/bashset -Eeuo pipefailsource /opt/miniconda3/bin/activateconda activate testbedcd /testbed/repoexec python -I /tests/grade.py1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "directory_roots": [ "tests" ], "files": { "pyproject.toml": { "bytes": 1846, "mode": 420, "sha256": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be" }, "pytest.ini": { "bytes": 70, "mode": 420, "sha256": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" }, "tests/__init__.py": { "bytes": 0, "mode": 420, "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "tests/conftest.py": { "bytes": 625, "mode": 420, "sha256": "502596fae1843322ec533028a76474d39e6fb70587a5749d8c9dd734b35e625b" }, "tests/test_middlewares.py": { "bytes": 2412, "mode": 420, "sha256": "85a748d3d10e7be042ed37318153a6b79c7913a5d9536cad406ccccad380577b" }, "tests/test_operations.py": { "bytes": 1021, "mode": 420, "sha256": "6313d342626a12973a5532b0b9344c5a30a959d7bfa4f6ca07d147317aee469e" }, "tests/test_queries.py": { "bytes": 12331, "mode": 420, "sha256": "7978c6220a192f4256018bf37d76e6b4c644a962fed4d6fca7d8594b2cf63a49" }, "tests/test_storages.py": { "bytes": 6489, "mode": 420, "sha256": "d74695d20e1d1742fa558da49bc2df8e84ca34e64e001070cbccce215bd39fa2" }, "tests/test_tables.py": { "bytes": 4109, "mode": 420, "sha256": "f018615899e7c9c813aba0820c639f9402d3c9865a376eedaf9dc3ee89b85ef3" }, "tests/test_tinydb.py": { "bytes": 18110, "mode": 420, "sha256": "d106d5e94536afe8416c1b8b01bc63381abb97f81a6a120743e7e1963b07b1d1" }, "tests/test_utils.py": { "bytes": 2257, "mode": 420, "sha256": "659bd414226988e81d2811259c112676aa6bdfa3b9fb6fed4631030ae6d73f2e" } }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061[tool.poetry]name = "tinydb"version = "4.8.2"description = "TinyDB is a tiny, document oriented database optimized for your happiness :)"authors = ["Markus Siemens <markus@m-siemens.de>"]license = "MIT"
readme = "README.rst"
homepage = "https://github.com/msiemens/tinydb"documentation = "https://tinydb.readthedocs.org/"
keywords = ["database", "nosql"]
classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Topic :: Database", "Topic :: Database :: Database Engines/Servers", "Topic :: Utilities", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Operating System :: OS Independent", "Typing :: Typed",]
packages = [ { include = "tinydb" }, { include = "tests", format = "sdist" }]
[tool.poetry.urls]"Changelog" = "https://tinydb.readthedocs.io/en/latest/changelog.html""Issues" = "https://github.com/msiemens/tinydb/issues"
[tool.poetry.dependencies]python = "^3.8"
[tool.poetry.dev-dependencies]pytest = "^7.2.0"pytest-pycodestyle = "^2.3.1"pytest-cov = "^4.0.0"pycodestyle = "^2.10.0"sphinx = "^7.0.0"coveralls = "^3.3.1"pyyaml = "^6.0"pytest-mypy = { version = "^0.10.2", markers = "platform_python_implementation != 'PyPy'" }types-PyYAML = "^6.0.0"
[build-system]requires = ["poetry-core"]build-backend = "poetry.core.masonry.api"12[pytest]addopts=--verbose --cov-append --cov-report term --cov tinydb123456789101112131415161718192021222324252627import os.pathimport tempfilefrom pathlib import Path
import pytest # type: ignore
from tinydb.middlewares import CachingMiddlewarefrom tinydb.storages import MemoryStoragefrom tinydb import TinyDB, JSONStorage
@pytest.fixture(params=['memory', 'json'])def db(request, tmp_path: Path): if request.param == 'json': db_ = TinyDB(tmp_path / 'test.db', storage=JSONStorage) else: db_ = TinyDB(storage=MemoryStorage)
db_.drop_tables() db_.insert_multiple({'int': 1, 'char': c} for c in 'abc')
yield db_
@pytest.fixturedef storage(): return CachingMiddleware(MemoryStorage)()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105import os
from tinydb import TinyDBfrom tinydb.middlewares import CachingMiddlewarefrom tinydb.storages import MemoryStorage, JSONStorage
doc = {'none': [None, None], 'int': 42, 'float': 3.1415899999999999, 'list': ['LITE', 'RES_ACID', 'SUS_DEXT'], 'dict': {'hp': 13, 'sp': 5}, 'bool': [True, False, True, False]}
def test_caching(storage): # Write contents storage.write(doc)
# Verify contents assert doc == storage.read()
def test_caching_read(): db = TinyDB(storage=CachingMiddleware(MemoryStorage)) assert db.all() == []
def test_caching_write_many(storage): storage.WRITE_CACHE_SIZE = 3
# Storage should be still empty assert storage.memory is None
# Write contents for x in range(2): storage.write(doc) assert storage.memory is None # Still cached
storage.write(doc)
# Verify contents: Cache should be emptied and written to storage assert storage.memory
def test_caching_flush(storage): # Write contents for _ in range(CachingMiddleware.WRITE_CACHE_SIZE - 1): storage.write(doc)
# Not yet flushed... assert storage.memory is None
storage.write(doc)
# Verify contents: Cache should be emptied and written to storage assert storage.memory
def test_caching_flush_manually(storage): # Write contents storage.write(doc)
storage.flush()
# Verify contents: Cache should be emptied and written to storage assert storage.memory
def test_caching_write(storage): # Write contents storage.write(doc)
storage.close()
# Verify contents: Cache should be emptied and written to storage assert storage.storage.memory
def test_nested(): storage = CachingMiddleware(MemoryStorage) storage() # Initialization
# Write contents storage.write(doc)
# Verify contents assert doc == storage.read()
def test_caching_json_write(tmpdir): path = str(tmpdir.join('test.db'))
with TinyDB(path, storage=CachingMiddleware(JSONStorage)) as db: db.insert({'key': 'value'})
# Verify database filesize statinfo = os.stat(path) assert statinfo.st_size != 0
# Assert JSON file has been closed assert db._storage._handle.closed
del db
# Reopen database with TinyDB(path, storage=CachingMiddleware(JSONStorage)) as db: assert db.all() == [{'key': 'value'}]12345678910111213141516171819202122232425262728293031323334353637from tinydb import wherefrom tinydb.operations import delete, increment, decrement, add, subtract, set
def test_delete(db): db.update(delete('int'), where('char') == 'a') assert 'int' not in db.get(where('char') == 'a')
def test_add_int(db): db.update(add('int', 5), where('char') == 'a') assert db.get(where('char') == 'a')['int'] == 6
def test_add_str(db): db.update(add('char', 'xyz'), where('char') == 'a') assert db.get(where('char') == 'axyz')['int'] == 1
def test_subtract(db): db.update(subtract('int', 5), where('char') == 'a') assert db.get(where('char') == 'a')['int'] == -4
def test_set(db): db.update(set('char', 'xyz'), where('char') == 'a') assert db.get(where('char') == 'xyz')['int'] == 1
def test_increment(db): db.update(increment('int'), where('char') == 'a') assert db.get(where('char') == 'a')['int'] == 2
def test_decrement(db): db.update(decrement('int'), where('char') == 'a') assert db.get(where('char') == 'a')['int'] == 0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445import re
import pytest
from tinydb.queries import Query, where
def test_no_path(): with pytest.raises(ValueError): _ = Query() == 2
def test_path_exists(): query = Query()['value'].exists() assert query == where('value').exists() assert query({'value': 1}) assert not query({'something': 1}) assert hash(query) assert hash(query) != hash(where('asd'))
query = Query()['value']['val'].exists() assert query == where('value')['val'].exists() assert query({'value': {'val': 2}}) assert not query({'value': 1}) assert not query({'value': {'asd': 1}}) assert not query({'something': 1}) assert hash(query) assert hash(query) != hash(where('asd'))
def test_path_and(): query = Query()['value'].exists() & (Query()['value'] == 5) assert query({'value': 5}) assert not query({'value': 10}) assert not query({'something': 1}) assert hash(query) assert hash(query) != hash(where('value'))
def test_callable_in_path_with_map(): double = lambda x: x + x query = Query().value.map(double) == 10 assert query({'value': 5}) assert not query({'value': 10})
def test_callable_in_path_with_chain(): rekey = lambda x: {'y': x['a'], 'z': x['b']} query = Query().map(rekey).z == 10 assert query({'a': 5, 'b': 10})
def test_eq(): query = Query().value == 1 assert query({'value': 1}) assert not query({'value': 2}) assert hash(query)
query = Query().value == [0, 1] assert query({'value': [0, 1]}) assert not query({'value': [0, 1, 2]}) assert hash(query)
def test_ne(): query = Query().value != 1 assert query({'value': 0}) assert query({'value': 2}) assert not query({'value': 1}) assert hash(query)
query = Query().value != [0, 1] assert query({'value': [0, 1, 2]}) assert not query({'value': [0, 1]}) assert hash(query)
def test_lt(): query = Query().value < 1 assert query({'value': 0}) assert not query({'value': 1}) assert not query({'value': 2}) assert hash(query)
def test_le(): query = Query().value <= 1 assert query({'value': 0}) assert query({'value': 1}) assert not query({'value': 2}) assert hash(query)
def test_gt(): query = Query().value > 1 assert query({'value': 2}) assert not query({'value': 1}) assert hash(query)
def test_ge(): query = Query().value >= 1 assert query({'value': 2}) assert query({'value': 1}) assert not query({'value': 0}) assert hash(query)
def test_or(): query = ( (Query().val1 == 1) | (Query().val2 == 2) ) assert query({'val1': 1}) assert query({'val2': 2}) assert query({'val1': 1, 'val2': 2}) assert not query({'val1': '', 'val2': ''}) assert hash(query)
def test_and(): query = ( (Query().val1 == 1) & (Query().val2 == 2) ) assert query({'val1': 1, 'val2': 2}) assert not query({'val1': 1}) assert not query({'val2': 2}) assert not query({'val1': '', 'val2': ''}) assert hash(query)
def test_not(): query = ~ (Query().val1 == 1) assert query({'val1': 5, 'val2': 2}) assert not query({'val1': 1, 'val2': 2}) assert hash(query)
query = ( (~ (Query().val1 == 1)) & (Query().val2 == 2) ) assert query({'val1': '', 'val2': 2}) assert query({'val2': 2}) assert not query({'val1': 1, 'val2': 2}) assert not query({'val1': 1}) assert not query({'val1': '', 'val2': ''}) assert hash(query)
def test_has_key(): query = Query().val3.exists()
assert query({'val3': 1}) assert not query({'val1': 1, 'val2': 2}) assert hash(query)
def test_regex(): query = Query().val.matches(r'\d{2}\.')
assert query({'val': '42.'}) assert not query({'val': '44'}) assert not query({'val': 'ab.'}) assert not query({'val': 155}) assert not query({'val': False}) assert not query({'': None}) assert hash(query)
query = Query().val.search(r'\d+')
assert query({'val': 'ab3'}) assert not query({'val': 'abc'}) assert not query({'val': ''}) assert not query({'val': True}) assert not query({'': None}) assert hash(query)
query = Query().val.search(r'JOHN', flags=re.IGNORECASE) assert query({'val': 'john'}) assert query({'val': 'xJohNx'}) assert not query({'val': 'JOH'}) assert not query({'val': 12}) assert not query({'': None}) assert hash(query)
def test_custom(): def test(value): return value == 42
query = Query().val.test(test)
assert query({'val': 42}) assert not query({'val': 40}) assert not query({'val': '44'}) assert not query({'': None}) assert hash(query)
def in_list(value, l): return value in l
query = Query().val.test(in_list, tuple([25, 35])) assert not query({'val': 20}) assert query({'val': 25}) assert not query({'val': 30}) assert query({'val': 35}) assert not query({'val': 36}) assert hash(query)
def test_custom_with_params(): def test(value, minimum, maximum): return minimum <= value <= maximum
query = Query().val.test(test, 1, 10)
assert query({'val': 5}) assert not query({'val': 0}) assert not query({'val': 11}) assert not query({'': None}) assert hash(query)
def test_any(): query = Query().followers.any(Query().name == 'don')
assert query({'followers': [{'name': 'don'}, {'name': 'john'}]}) assert not query({'followers': 1}) assert not query({}) assert hash(query)
query = Query().followers.any(Query().num.matches('\\d+')) assert query({'followers': [{'num': '12'}, {'num': 'abc'}]}) assert not query({'followers': [{'num': 'abc'}]}) assert hash(query)
query = Query().followers.any(['don', 'jon']) assert query({'followers': ['don', 'greg', 'bill']}) assert not query({'followers': ['greg', 'bill']}) assert not query({}) assert hash(query)
query = Query().followers.any([{'name': 'don'}, {'name': 'john'}]) assert query({'followers': [{'name': 'don'}, {'name': 'greg'}]}) assert not query({'followers': [{'name': 'greg'}]}) assert hash(query)
def test_all(): query = Query().followers.all(Query().name == 'don') assert query({'followers': [{'name': 'don'}]}) assert not query({'followers': [{'name': 'don'}, {'name': 'john'}]}) assert hash(query)
query = Query().followers.all(Query().num.matches('\\d+')) assert query({'followers': [{'num': '123'}, {'num': '456'}]}) assert not query({'followers': [{'num': '123'}, {'num': 'abc'}]}) assert hash(query)
query = Query().followers.all(['don', 'john']) assert query({'followers': ['don', 'john', 'greg']}) assert not query({'followers': ['don', 'greg']}) assert not query({}) assert hash(query)
query = Query().followers.all([{'name': 'jane'}, {'name': 'john'}]) assert query({'followers': [{'name': 'john'}, {'name': 'jane'}]}) assert query({'followers': [{'name': 'john'}, {'name': 'jane'}, {'name': 'bob'}]}) assert not query({'followers': [{'name': 'john'}, {'name': 'bob'}]}) assert hash(query)
def test_has(): query = Query().key1.key2.exists() str(query) # This used to cause a bug...
assert query({'key1': {'key2': {'key3': 1}}}) assert query({'key1': {'key2': 1}}) assert not query({'key1': 3}) assert not query({'key1': {'key1': 1}}) assert not query({'key2': {'key1': 1}}) assert hash(query)
query = Query().key1.key2 == 1
assert query({'key1': {'key2': 1}}) assert not query({'key1': {'key2': 2}}) assert hash(query)
# Nested has: key exists query = Query().key1.key2.key3.exists() assert query({'key1': {'key2': {'key3': 1}}}) # Not a dict assert not query({'key1': 1}) assert not query({'key1': {'key2': 1}}) # Wrong key assert not query({'key1': {'key2': {'key0': 1}}}) assert not query({'key1': {'key0': {'key3': 1}}}) assert not query({'key0': {'key2': {'key3': 1}}})
assert hash(query)
# Nested has: check for value query = Query().key1.key2.key3 == 1 assert query({'key1': {'key2': {'key3': 1}}}) assert not query({'key1': {'key2': {'key3': 0}}}) assert hash(query)
# Test special methods: regex matches query = Query().key1.value.matches(r'\d+') assert query({'key1': {'value': '123'}}) assert not query({'key2': {'value': '123'}}) assert not query({'key2': {'value': 'abc'}}) assert hash(query)
# Test special methods: regex contains query = Query().key1.value.search(r'\d+') assert query({'key1': {'value': 'a2c'}}) assert not query({'key2': {'value': 'a2c'}}) assert not query({'key2': {'value': 'abc'}}) assert hash(query)
# Test special methods: nested has and regex matches query = Query().key1.x.y.matches(r'\d+') assert query({'key1': {'x': {'y': '123'}}}) assert not query({'key1': {'x': {'y': 'abc'}}}) assert hash(query)
# Test special method: nested has and regex contains query = Query().key1.x.y.search(r'\d+') assert query({'key1': {'x': {'y': 'a2c'}}}) assert not query({'key1': {'x': {'y': 'abc'}}}) assert hash(query)
# Test special methods: custom test query = Query().key1.int.test(lambda x: x == 3) assert query({'key1': {'int': 3}}) assert hash(query)
def test_one_of(): query = Query().key1.one_of(['value 1', 'value 2']) assert query({'key1': 'value 1'}) assert query({'key1': 'value 2'}) assert not query({'key1': 'value 3'})
def test_hash(): d = { Query().key1 == 2: True, Query().key1.key2.key3.exists(): True, Query().key1.exists() & Query().key2.exists(): True, Query().key1.exists() | Query().key2.exists(): True, }
assert (Query().key1 == 2) in d assert (Query().key1.key2.key3.exists()) in d assert (Query()['key1.key2'].key3.exists()) not in d
# Commutative property of & and | assert (Query().key1.exists() & Query().key2.exists()) in d assert (Query().key2.exists() & Query().key1.exists()) in d assert (Query().key1.exists() | Query().key2.exists()) in d assert (Query().key2.exists() | Query().key1.exists()) in d
def test_orm_usage(): data = {'name': 'John', 'age': {'year': 2000}}
User = Query() query1 = User.name == 'John' query2 = User.age.year == 2000 assert query1(data) assert query2(data)
def test_repr(): Fruit = Query()
assert repr(Fruit) == "Query()" assert repr(Fruit.type == 'peach') == "QueryImpl('==', ('type',), 'peach')"
def test_subclass(): # Test that a new query test method in a custom subclass is properly usable class MyQueryClass(Query): def equal_double(self, rhs): return self._generate_test( lambda value: value == rhs * 2, ('equal_double', self._path, rhs) )
query = MyQueryClass().val.equal_double('42')
assert query({'val': '4242'}) assert not query({'val': '42'}) assert not query({'': None}) assert hash(query)
def test_noop(): query = Query().noop()
assert query({'foo': True}) assert query({'foo': None}) assert query({})
def test_equality(): q = Query() assert (q.foo == 2) != 0 assert (q.foo == 'yes') != ''
def test_empty_query_error(): with pytest.raises(RuntimeError, match='Empty query was evaluated'): Query()({})
def test_fragment(): query = Query().fragment({'a': 4, 'b': True})
assert query({'a': 4, 'b': True, 'c': 'yes'}) assert not query({'a': 4, 'c': 'yes'}) assert not query({'b': True, 'c': 'yes'}) assert not query({'a': 5, 'b': True, 'c': 'yes'}) assert not query({'a': 4, 'b': 'no', 'c': 'yes'})
def test_fragment_with_path(): query = Query().doc.fragment({'a': 4, 'b': True})
assert query({'doc': {'a': 4, 'b': True, 'c': 'yes'}}) assert not query({'a': 4, 'b': True, 'c': 'yes'}) assert not query({'doc': {'a': 4, 'c': 'yes'}})
def test_get_item(): query = Query()['test'] == 1
assert query({'test': 1}) assert not query({'test': 0})123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281import jsonimport osimport randomimport tempfile
import pytest
from tinydb import TinyDB, wherefrom tinydb.storages import JSONStorage, MemoryStorage, Storage, touchfrom tinydb.table import Document
random.seed()
doc = {'none': [None, None], 'int': 42, 'float': 3.1415899999999999, 'list': ['LITE', 'RES_ACID', 'SUS_DEXT'], 'dict': {'hp': 13, 'sp': 5}, 'bool': [True, False, True, False]}
def test_json(tmpdir): # Write contents path = str(tmpdir.join('test.db')) storage = JSONStorage(path) storage.write(doc)
# Verify contents assert doc == storage.read() storage.close()
def test_json_kwargs(tmpdir): db_file = tmpdir.join('test.db') db = TinyDB(str(db_file), sort_keys=True, indent=4, separators=(',', ': '))
# Write contents db.insert({'b': 1}) db.insert({'a': 1})
assert db_file.read() == '''{ "_default": { "1": { "b": 1 }, "2": { "a": 1 } }}''' db.close()
def test_json_readwrite(tmpdir): """ Regression test for issue #1 """ path = str(tmpdir.join('test.db'))
# Create TinyDB instance db = TinyDB(path, storage=JSONStorage)
item = {'name': 'A very long entry'} item2 = {'name': 'A short one'}
def get(s): return db.get(where('name') == s)
db.insert(item) assert get('A very long entry') == item
db.remove(where('name') == 'A very long entry') assert get('A very long entry') is None
db.insert(item2) assert get('A short one') == item2
db.remove(where('name') == 'A short one') assert get('A short one') is None
db.close()
def test_json_read(tmpdir): r"""Open a database only for reading""" path = str(tmpdir.join('test.db')) with pytest.raises(FileNotFoundError): db = TinyDB(path, storage=JSONStorage, access_mode='r') # Create small database db = TinyDB(path, storage=JSONStorage) db.insert({'b': 1}) db.insert({'a': 1}) db.close() # Access in read mode db = TinyDB(path, storage=JSONStorage, access_mode='r') assert db.get(where('a') == 1) == {'a': 1} # reading is fine with pytest.raises(IOError): db.insert({'c': 1}) # writing is not db.close()
def test_create_dirs(): temp_dir = tempfile.gettempdir()
while True: dname = os.path.join(temp_dir, str(random.getrandbits(20))) if not os.path.exists(dname): db_dir = dname db_file = os.path.join(db_dir, 'db.json') break
with pytest.raises(IOError): JSONStorage(db_file)
JSONStorage(db_file, create_dirs=True).close() assert os.path.exists(db_file)
# Use create_dirs with already existing directory JSONStorage(db_file, create_dirs=True).close() assert os.path.exists(db_file)
os.remove(db_file) os.rmdir(db_dir)
def test_json_invalid_directory(): with pytest.raises(IOError): with TinyDB('/this/is/an/invalid/path/db.json', storage=JSONStorage): pass
def test_in_memory(): # Write contents storage = MemoryStorage() storage.write(doc)
# Verify contents assert doc == storage.read()
# Test case for #21 other = MemoryStorage() other.write({}) assert other.read() != storage.read()
def test_in_memory_close(): with TinyDB(storage=MemoryStorage) as db: db.insert({})
def test_custom(): # noinspection PyAbstractClass class MyStorage(Storage): pass
with pytest.raises(TypeError): MyStorage()
def test_read_once(): count = 0
# noinspection PyAbstractClass class MyStorage(Storage): def __init__(self): self.memory = None
def read(self): nonlocal count count += 1
return self.memory
def write(self, data): self.memory = data
with TinyDB(storage=MyStorage) as db: assert count == 0
db.table(db.default_table_name)
assert count == 0
db.all()
assert count == 1
db.insert({'foo': 'bar'})
assert count == 3 # One for getting the next ID, one for the insert
db.all()
assert count == 4
def test_custom_with_exception(): class MyStorage(Storage): def read(self): pass
def write(self, data): pass
def __init__(self): raise ValueError()
def close(self): raise RuntimeError()
with pytest.raises(ValueError): with TinyDB(storage=MyStorage) as db: pass
def test_yaml(tmpdir): """ :type tmpdir: py._path.local.LocalPath """
try: import yaml except ImportError: return pytest.skip('PyYAML not installed')
def represent_doc(dumper, data): # Represent `Document` objects as their dict's string representation # which PyYAML understands return dumper.represent_data(dict(data))
yaml.add_representer(Document, represent_doc)
class YAMLStorage(Storage): def __init__(self, filename): self.filename = filename touch(filename, False)
def read(self): with open(self.filename) as handle: data = yaml.safe_load(handle.read()) return data
def write(self, data): with open(self.filename, 'w') as handle: yaml.dump(data, handle)
def close(self): pass
# Write contents path = str(tmpdir.join('test.db')) db = TinyDB(path, storage=YAMLStorage) db.insert(doc) assert db.all() == [doc]
db.update({'name': 'foo'})
assert '!' not in tmpdir.join('test.db').read()
assert db.contains(where('name') == 'foo') assert len(db) == 1
def test_encoding(tmpdir): japanese_doc = {"Test": u"こんにちは世界"}
path = str(tmpdir.join('test.db')) # cp936 is used for japanese encodings jap_storage = JSONStorage(path, encoding="cp936") jap_storage.write(japanese_doc)
try: exception = json.decoder.JSONDecodeError except AttributeError: exception = ValueError
with pytest.raises(exception): # cp037 is used for english encodings eng_storage = JSONStorage(path, encoding="cp037") eng_storage.read()
jap_storage = JSONStorage(path, encoding="cp936") assert japanese_doc == jap_storage.read()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import re
import pytest
from tinydb import where
def test_next_id(db): db.truncate()
assert db._get_next_id() == 1 assert db._get_next_id() == 2 assert db._get_next_id() == 3
def test_tables_list(db): db.table('table1').insert({'a': 1}) db.table('table2').insert({'a': 1})
assert db.tables() == {'_default', 'table1', 'table2'}
def test_one_table(db): table1 = db.table('table1')
table1.insert_multiple({'int': 1, 'char': c} for c in 'abc')
assert table1.get(where('int') == 1)['char'] == 'a' assert table1.get(where('char') == 'b')['char'] == 'b'
def test_multiple_tables(db): table1 = db.table('table1') table2 = db.table('table2') table3 = db.table('table3')
table1.insert({'int': 1, 'char': 'a'}) table2.insert({'int': 1, 'char': 'b'}) table3.insert({'int': 1, 'char': 'c'})
assert table1.count(where('char') == 'a') == 1 assert table2.count(where('char') == 'b') == 1 assert table3.count(where('char') == 'c') == 1
db.drop_tables()
assert len(table1) == 0 assert len(table2) == 0 assert len(table3) == 0
def test_caching(db): table1 = db.table('table1') table2 = db.table('table1')
assert table1 is table2
def test_query_cache(db): query1 = where('int') == 1
assert db.count(query1) == 3 assert query1 in db._query_cache
assert db.count(query1) == 3 assert query1 in db._query_cache
query2 = where('int') == 0
assert db.count(query2) == 0 assert query2 in db._query_cache
assert db.count(query2) == 0 assert query2 in db._query_cache
def test_query_cache_with_mutable_callable(db): table = db.table('table') table.insert({'val': 5})
mutable = 5 increase = lambda x: x + mutable
assert where('val').is_cacheable() assert not where('val').map(increase).is_cacheable() assert not (where('val').map(increase) == 10).is_cacheable()
search = where('val').map(increase) == 10 assert table.count(search) == 1
# now `increase` would yield 15, not 10 mutable = 10
assert table.count(search) == 0 assert len(table._query_cache) == 0
def test_zero_cache_size(db): table = db.table('table3', cache_size=0) query = where('int') == 1
table.insert({'int': 1}) table.insert({'int': 1})
assert table.count(query) == 2 assert table.count(where('int') == 2) == 0 assert len(table._query_cache) == 0
def test_query_cache_size(db): table = db.table('table3', cache_size=1) query = where('int') == 1
table.insert({'int': 1}) table.insert({'int': 1})
assert table.count(query) == 2 assert table.count(where('int') == 2) == 0 assert len(table._query_cache) == 1
def test_lru_cache(db): # Test integration into TinyDB table = db.table('table3', cache_size=2) query = where('int') == 1
table.search(query) table.search(where('int') == 2) table.search(where('int') == 3) assert query not in table._query_cache
table.remove(where('int') == 1) assert not table._query_cache.lru
table.search(query)
assert len(table._query_cache) == 1 table.clear_cache() assert len(table._query_cache) == 0
def test_table_is_iterable(db): table = db.table('table1')
table.insert_multiple({'int': i} for i in range(3))
assert [r for r in table] == table.all()
def test_table_name(db): name = 'table3' table = db.table(name) assert name == table.name
with pytest.raises(AttributeError): table.name = 'foo'
def test_table_repr(db): name = 'table4' table = db.table(name)
assert re.match( r"<Table name=\'table4\', total=0, " r"storage=<tinydb\.storages\.(MemoryStorage|JSONStorage) object at [a-zA-Z0-9]+>>", repr(table))
def test_truncate_table(db): db.truncate() assert db._get_next_id() == 1
def test_persist_table(db): db.table("persisted", persist_empty=True) assert "persisted" in db.tables()
db.table("nonpersisted", persist_empty=False) assert "nonpersisted" not in db.tables()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716import refrom collections.abc import Mapping
import pytest
from tinydb import TinyDB, where, Queryfrom tinydb.middlewares import Middleware, CachingMiddlewarefrom tinydb.storages import MemoryStorage, JSONStoragefrom tinydb.table import Document
def test_drop_tables(db: TinyDB): db.drop_tables()
db.insert({}) db.drop_tables()
assert len(db) == 0
def test_all(db: TinyDB): db.drop_tables()
for i in range(10): db.insert({})
assert len(db.all()) == 10
def test_insert(db: TinyDB): db.drop_tables() db.insert({'int': 1, 'char': 'a'})
assert db.count(where('int') == 1) == 1
db.drop_tables()
db.insert({'int': 1, 'char': 'a'}) db.insert({'int': 1, 'char': 'b'}) db.insert({'int': 1, 'char': 'c'})
assert db.count(where('int') == 1) == 3 assert db.count(where('char') == 'a') == 1
def test_insert_ids(db: TinyDB): db.drop_tables() assert db.insert({'int': 1, 'char': 'a'}) == 1 assert db.insert({'int': 1, 'char': 'a'}) == 2
def test_insert_with_doc_id(db: TinyDB): db.drop_tables() assert db.insert({'int': 1, 'char': 'a'}) == 1 assert db.insert(Document({'int': 1, 'char': 'a'}, 12)) == 12 assert db.insert(Document({'int': 1, 'char': 'a'}, 77)) == 77 assert db.insert({'int': 1, 'char': 'a'}) == 78
def test_insert_with_duplicate_doc_id(db: TinyDB): db.drop_tables() assert db.insert({'int': 1, 'char': 'a'}) == 1
with pytest.raises(ValueError): db.insert(Document({'int': 1, 'char': 'a'}, 1))
def test_insert_multiple(db: TinyDB): db.drop_tables() assert not db.contains(where('int') == 1)
# Insert multiple from list db.insert_multiple([{'int': 1, 'char': 'a'}, {'int': 1, 'char': 'b'}, {'int': 1, 'char': 'c'}])
assert db.count(where('int') == 1) == 3 assert db.count(where('char') == 'a') == 1
# Insert multiple from generator function def generator(): for j in range(10): yield {'int': j}
db.drop_tables()
db.insert_multiple(generator())
for i in range(10): assert db.count(where('int') == i) == 1 assert db.count(where('int').exists()) == 10
# Insert multiple from inline generator db.drop_tables()
db.insert_multiple({'int': i} for i in range(10))
for i in range(10): assert db.count(where('int') == i) == 1
def test_insert_multiple_with_ids(db: TinyDB): db.drop_tables()
# Insert multiple from list assert db.insert_multiple([{'int': 1, 'char': 'a'}, {'int': 1, 'char': 'b'}, {'int': 1, 'char': 'c'}]) == [1, 2, 3]
def test_insert_multiple_with_doc_ids(db: TinyDB): db.drop_tables()
assert db.insert_multiple([ Document({'int': 1, 'char': 'a'}, 12), Document({'int': 1, 'char': 'b'}, 77) ]) == [12, 77] assert db.get(doc_id=12) == {'int': 1, 'char': 'a'} assert db.get(doc_id=77) == {'int': 1, 'char': 'b'}
with pytest.raises(ValueError): db.insert_multiple([Document({'int': 1, 'char': 'a'}, 12)])
def test_insert_invalid_type_raises_error(db: TinyDB): with pytest.raises(ValueError, match='Document is not a Mapping'): # object() as an example of a non-mapping-type db.insert(object()) # type: ignore
def test_insert_valid_mapping_type(db: TinyDB): class CustomDocument(Mapping): def __init__(self, data): self.data = data
def __getitem__(self, key): return self.data[key]
def __iter__(self): return iter(self.data)
def __len__(self): return len(self.data)
db.drop_tables() db.insert(CustomDocument({'int': 1, 'char': 'a'})) assert db.count(where('int') == 1) == 1
def test_custom_mapping_type_with_json(tmpdir): class CustomDocument(Mapping): def __init__(self, data): self.data = data
def __getitem__(self, key): return self.data[key]
def __iter__(self): return iter(self.data)
def __len__(self): return len(self.data)
# Insert db = TinyDB(str(tmpdir.join('test.db'))) db.drop_tables() db.insert(CustomDocument({'int': 1, 'char': 'a'})) assert db.count(where('int') == 1) == 1
# Insert multiple db.insert_multiple([ CustomDocument({'int': 2, 'char': 'a'}), CustomDocument({'int': 3, 'char': 'a'}) ]) assert db.count(where('int') == 1) == 1 assert db.count(where('int') == 2) == 1 assert db.count(where('int') == 3) == 1
# Write back doc_id = db.get(where('int') == 3).doc_id db.update(CustomDocument({'int': 4, 'char': 'a'}), doc_ids=[doc_id]) assert db.count(where('int') == 3) == 0 assert db.count(where('int') == 4) == 1
def test_remove(db: TinyDB): db.remove(where('char') == 'b')
assert len(db) == 2 assert db.count(where('int') == 1) == 2
def test_remove_all_fails(db: TinyDB): with pytest.raises(RuntimeError): db.remove()
def test_remove_multiple(db: TinyDB): db.remove(where('int') == 1)
assert len(db) == 0
def test_remove_ids(db: TinyDB): db.remove(doc_ids=[1, 2])
assert len(db) == 1
def test_remove_returns_ids(db: TinyDB): assert db.remove(where('char') == 'b') == [2]
def test_update(db: TinyDB): assert len(db) == 3
db.update({'int': 2}, where('char') == 'a')
assert db.count(where('int') == 2) == 1 assert db.count(where('int') == 1) == 2
def test_update_all(db: TinyDB): assert db.count(where('int') == 1) == 3
db.update({'newField': True})
assert db.count(where('newField') == True) == 3 # noqa
def test_update_returns_ids(db: TinyDB): db.drop_tables() assert db.insert({'int': 1, 'char': 'a'}) == 1 assert db.insert({'int': 1, 'char': 'a'}) == 2
assert db.update({'char': 'b'}, where('int') == 1) == [1, 2]
def test_update_transform(db: TinyDB): def increment(field): def transform(el): el[field] += 1
return transform
def delete(field): def transform(el): del el[field]
return transform
assert db.count(where('int') == 1) == 3
db.update(increment('int'), where('char') == 'a') db.update(delete('char'), where('char') == 'a')
assert db.count(where('int') == 2) == 1 assert db.count(where('char') == 'a') == 0 assert db.count(where('int') == 1) == 2
def test_update_ids(db: TinyDB): db.update({'int': 2}, doc_ids=[1, 2])
assert db.count(where('int') == 2) == 2
def test_update_multiple(db: TinyDB): assert len(db) == 3
db.update_multiple([ ({'int': 2}, where('char') == 'a'), ({'int': 4}, where('char') == 'b'), ])
assert db.count(where('int') == 1) == 1 assert db.count(where('int') == 2) == 1 assert db.count(where('int') == 4) == 1
def test_update_multiple_operation(db: TinyDB): def increment(field): def transform(el): el[field] += 1
return transform
assert db.count(where('int') == 1) == 3
db.update_multiple([ (increment('int'), where('char') == 'a'), (increment('int'), where('char') == 'b') ])
assert db.count(where('int') == 2) == 2
def test_upsert(db: TinyDB): assert len(db) == 3
# Document existing db.upsert({'int': 5}, where('char') == 'a') assert db.count(where('int') == 5) == 1
# Document missing assert db.upsert({'int': 9, 'char': 'x'}, where('char') == 'x') == [4] assert db.count(where('int') == 9) == 1
def test_upsert_by_id(db: TinyDB): assert len(db) == 3
# Single document existing extant_doc = Document({'char': 'v'}, doc_id=1) assert db.upsert(extant_doc) == [1] doc = db.get(where('char') == 'v') assert isinstance(doc, Document) assert doc is not None assert doc.doc_id == 1 assert len(db) == 3
# Single document missing missing_doc = Document({'int': 5, 'char': 'w'}, doc_id=5) assert db.upsert(missing_doc) == [5] doc = db.get(where('char') == 'w') assert isinstance(doc, Document) assert doc is not None assert doc.doc_id == 5 assert len(db) == 4
# Missing doc_id and condition with pytest.raises(ValueError, match=r"(?=.*\bdoc_id\b)(?=.*\bquery\b)"): db.upsert({'no_Document': 'no_query'})
# Make sure we didn't break anything assert db.insert({'check': '_next_id'}) == 6
def test_search(db: TinyDB): assert not db._query_cache assert len(db.search(where('int') == 1)) == 3
assert len(db._query_cache) == 1 assert len(db.search(where('int') == 1)) == 3 # Query result from cache
def test_search_path(db: TinyDB): assert not db._query_cache assert len(db.search(where('int').exists())) == 3 assert len(db._query_cache) == 1
assert len(db.search(where('asd').exists())) == 0 assert len(db.search(where('int').exists())) == 3 # Query result from cache
def test_search_no_results_cache(db: TinyDB): assert len(db.search(where('missing').exists())) == 0 assert len(db.search(where('missing').exists())) == 0
def test_get(db: TinyDB): item = db.get(where('char') == 'b') assert isinstance(item, Document) assert item is not None assert item['char'] == 'b'
def test_get_ids(db: TinyDB): el = db.all()[0] assert db.get(doc_id=el.doc_id) == el assert db.get(doc_id=float('NaN')) is None # type: ignore
def test_get_multiple_ids(db: TinyDB): el = db.all() assert db.get(doc_ids=[x.doc_id for x in el]) == el
def test_get_invalid(db: TinyDB): with pytest.raises(RuntimeError): db.get()
def test_count(db: TinyDB): assert db.count(where('int') == 1) == 3 assert db.count(where('char') == 'd') == 0
def test_contains(db: TinyDB): assert db.contains(where('int') == 1) assert not db.contains(where('int') == 0)
def test_contains_ids(db: TinyDB): assert db.contains(doc_id=1) assert db.contains(doc_id=2) assert not db.contains(doc_id=88)
def test_contains_invalid(db: TinyDB): with pytest.raises(RuntimeError): db.contains()
def test_get_idempotent(db: TinyDB): u = db.get(where('int') == 1) z = db.get(where('int') == 1) assert u == z
def test_multiple_dbs(): """ Regression test for issue #3 """ db1 = TinyDB(storage=MemoryStorage) db2 = TinyDB(storage=MemoryStorage)
db1.insert({'int': 1, 'char': 'a'}) db1.insert({'int': 1, 'char': 'b'}) db1.insert({'int': 1, 'value': 5.0})
db2.insert({'color': 'blue', 'animal': 'turtle'})
assert len(db1) == 3 assert len(db2) == 1
def test_storage_closed_once(): class Storage: def __init__(self): self.closed = False
def read(self): return {}
def write(self, data): pass
def close(self): assert not self.closed self.closed = True
with TinyDB(storage=Storage) as db: db.close()
del db # If db.close() is called during cleanup, the assertion will fail and throw # and exception
def test_unique_ids(tmpdir): """ :type tmpdir: py._path.local.LocalPath """ path = str(tmpdir.join('db.json'))
# Verify ids are unique when reopening the DB and inserting with TinyDB(path) as _db: _db.insert({'x': 1})
with TinyDB(path) as _db: _db.insert({'x': 1})
with TinyDB(path) as _db: data = _db.all()
assert data[0].doc_id != data[1].doc_id
# Verify ids stay unique when inserting/removing with TinyDB(path) as _db: _db.drop_tables() _db.insert_multiple({'x': i} for i in range(5)) _db.remove(where('x') == 2)
assert len(_db) == 4
ids = [e.doc_id for e in _db.all()] assert len(ids) == len(set(ids))
def test_lastid_after_open(tmpdir): """ Regression test for issue #34
:type tmpdir: py._path.local.LocalPath """
NUM = 100 path = str(tmpdir.join('db.json'))
with TinyDB(path) as _db: _db.insert_multiple({'i': i} for i in range(NUM))
with TinyDB(path) as _db: assert _db._get_next_id() - 1 == NUM
def test_doc_ids_json(tmpdir): """ Regression test for issue #45 """
path = str(tmpdir.join('db.json'))
with TinyDB(path) as _db: _db.drop_tables() assert _db.insert({'int': 1, 'char': 'a'}) == 1 assert _db.insert({'int': 1, 'char': 'a'}) == 2
_db.drop_tables() assert _db.insert_multiple([{'int': 1, 'char': 'a'}, {'int': 1, 'char': 'b'}, {'int': 1, 'char': 'c'}]) == [1, 2, 3]
assert _db.contains(doc_id=1) assert _db.contains(doc_id=2) assert not _db.contains(doc_id=88)
_db.update({'int': 2}, doc_ids=[1, 2]) assert _db.count(where('int') == 2) == 2
el = _db.all()[0] assert _db.get(doc_id=el.doc_id) == el assert _db.get(doc_id=float('NaN')) is None
_db.remove(doc_ids=[1, 2]) assert len(_db) == 1
def test_insert_string(tmpdir): path = str(tmpdir.join('db.json'))
with TinyDB(path) as _db: data = [{'int': 1}, {'int': 2}] _db.insert_multiple(data)
with pytest.raises(ValueError): _db.insert([1, 2, 3]) # Fails
with pytest.raises(ValueError): _db.insert({'bark'}) # Fails
assert data == _db.all()
_db.insert({'int': 3}) # Does not fail
def test_insert_invalid_dict(tmpdir): path = str(tmpdir.join('db.json'))
with TinyDB(path) as _db: data = [{'int': 1}, {'int': 2}] _db.insert_multiple(data)
with pytest.raises(TypeError): _db.insert({'int': _db}) # Fails
assert data == _db.all()
_db.insert({'int': 3}) # Does not fail
def test_gc(tmpdir): # See https://github.com/msiemens/tinydb/issues/92 path = str(tmpdir.join('db.json')) db = TinyDB(path) table = db.table('foo') table.insert({'something': 'else'}) table.insert({'int': 13}) assert len(table.search(where('int') == 13)) == 1 assert table.all() == [{'something': 'else'}, {'int': 13}] db.close()
def test_drop_table(): db = TinyDB(storage=MemoryStorage) default_table_name = db.table(db.default_table_name).name
assert [] == list(db.tables()) db.drop_table(default_table_name)
db.insert({'a': 1}) assert [default_table_name] == list(db.tables())
db.drop_table(default_table_name) assert [] == list(db.tables())
table_name = 'some-other-table' db = TinyDB(storage=MemoryStorage) db.table(table_name).insert({'a': 1}) assert {table_name} == db.tables()
db.drop_table(table_name) assert set() == db.tables() assert table_name not in db._tables
db.drop_table('non-existent-table-name') assert set() == db.tables()
def test_empty_write(tmpdir): path = str(tmpdir.join('db.json'))
class ReadOnlyMiddleware(Middleware): def write(self, data): raise AssertionError('No write for unchanged db')
TinyDB(path).close() TinyDB(path, storage=ReadOnlyMiddleware(JSONStorage)).close()
def test_query_cache(): db = TinyDB(storage=MemoryStorage) db.insert_multiple([ {'name': 'foo', 'value': 42}, {'name': 'bar', 'value': -1337} ])
query = where('value') > 0
results = db.search(query) assert len(results) == 1
# Modify the db instance to not return any results when # bypassing the query cache db._tables[db.table(db.default_table_name).name]._read_table = lambda: {}
# Make sure we got an independent copy of the result list results.extend([1]) assert db.search(query) == [{'name': 'foo', 'value': 42}]
def test_tinydb_is_iterable(db: TinyDB): assert [r for r in db] == db.all()
def test_repr(tmpdir): path = str(tmpdir.join('db.json'))
db = TinyDB(path) db.insert({'a': 1})
assert re.match( r"<TinyDB " r"tables=\[u?\'_default\'\], " r"tables_count=1, " r"default_table_documents_count=1, " r"all_tables_documents_count=\[\'_default=1\'\]>", repr(db))
def test_delete(tmpdir): path = str(tmpdir.join('db.json'))
db = TinyDB(path, ensure_ascii=False) q = Query() db.insert({'network': {'id': '114', 'name': 'ok', 'rpc': 'dac', 'ticker': 'mkay'}}) assert db.search(q.network.id == '114') == [ {'network': {'id': '114', 'name': 'ok', 'rpc': 'dac', 'ticker': 'mkay'}} ] db.remove(q.network.id == '114') assert db.search(q.network.id == '114') == []
def test_insert_multiple_with_single_dict(db: TinyDB): with pytest.raises(ValueError): d = {'first': 'John', 'last': 'smith'} db.insert_multiple(d) # type: ignore db.close()
def test_access_storage(): assert isinstance(TinyDB(storage=MemoryStorage).storage, MemoryStorage) assert isinstance(TinyDB(storage=CachingMiddleware(MemoryStorage)).storage, CachingMiddleware)
def test_empty_db_len(): db = TinyDB(storage=MemoryStorage) assert len(db) == 0
def test_insert_on_existing_db(tmpdir): path = str(tmpdir.join('db.json'))
db = TinyDB(path, ensure_ascii=False) db.insert({'foo': 'bar'})
assert len(db) == 1
db.close()
db = TinyDB(path, ensure_ascii=False) db.insert({'foo': 'bar'}) db.insert({'foo': 'bar'})
assert len(db) == 3
def test_storage_access(): db = TinyDB(storage=MemoryStorage)
assert isinstance(db.storage, MemoryStorage)
def test_lambda_query(): db = TinyDB(storage=MemoryStorage) db.insert({'foo': 'bar'})
query = lambda doc: doc.get('foo') == 'bar' query.is_cacheable = lambda: False assert db.search(query) == [{'foo': 'bar'}] assert not db._query_cache123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116import pytest
from tinydb.utils import LRUCache, freeze, FrozenDict
def test_lru_cache(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["b"] = 2 cache["c"] = 3 _ = cache["a"] # move to front in lru queue cache["d"] = 4 # move oldest item out of lru queue
try: _ = cache['f'] except KeyError: pass
assert cache.lru == ["c", "a", "d"]
def test_lru_cache_set_multiple(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["a"] = 2 cache["a"] = 3 cache["a"] = 4
assert cache.lru == ["a"]
def test_lru_cache_set_update(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["a"] = 2
assert cache["a"] == 2
def test_lru_cache_get(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["b"] = 1 cache["c"] = 1 cache.get("a") cache["d"] = 4
assert cache.lru == ["c", "a", "d"]
def test_lru_cache_delete(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["b"] = 2 del cache["a"]
try: del cache['f'] except KeyError: pass
assert cache.lru == ["b"]
def test_lru_cache_clear(): cache = LRUCache(capacity=3) cache["a"] = 1 cache["b"] = 2 cache.clear()
assert cache.lru == []
def test_lru_cache_unlimited(): cache = LRUCache() for i in range(100): cache[i] = i
assert len(cache.lru) == 100
def test_lru_cache_unlimited_explicit(): cache = LRUCache(capacity=None) for i in range(100): cache[i] = i
assert len(cache.lru) == 100
def test_lru_cache_iteration_works(): cache = LRUCache() count = 0 for _ in cache: assert False, 'there should be no elements in the cache'
assert count == 0
def test_freeze(): frozen = freeze([0, 1, 2, {'a': [1, 2, 3]}, {1, 2}]) assert isinstance(frozen, tuple) assert isinstance(frozen[3], FrozenDict) assert isinstance(frozen[3]['a'], tuple) assert isinstance(frozen[4], frozenset)
with pytest.raises(TypeError): frozen[0] = 10
with pytest.raises(TypeError): frozen[3]['a'] = 10
with pytest.raises(TypeError): frozen[3].pop('a')
with pytest.raises(TypeError): frozen[3].update({'a': 9})123#!/bin/bashset -Eeuo pipefail:123456789101112131415161718192021222324252627{ "canaries": "validation/canaries", "profile": "harbor-semantic-v1", "requires_credentials": false, "resources": { "cpu": 2, "disk_mb": 16384, "episode_timeout_s": 1800, "memory_mb": 8192 }, "reward": { "floor_margin": 0.1, "oracle_tolerance": 0, "range": [ 0, 1 ] }, "reward_key": "reward", "types": { "tags": [ "swe", "python", "mutation-repair" ] }}1234567Copyright (C) 2013 Markus Siemens <markus@m-siemens.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127{ "canary_selection": "Fixed first provided gold hunk only when at least2hunks exist; strict subset, never reward-selected. Single-hunk task original-bug canary is explicitly NOP-equivalent and adds no signal beyond floor_gap.", "collector_sha256": "2a75d35790f6496f754850af247239363d8226867be0988241601d82a0eefc59", "dependency_installation_pinned": false, "dependency_setup_sha256": "0551e0806afd99add5cb7c6184a7e0b4813c16aa421c4031e64e7e3a27b44236", "gold_patch_sha256": "fb64de0dda930e2063f7dd19d6d8ab3be58becf523f9e36969336c6507f7c614", "hostile_code_isolation_established": false, "known_wrong_semantic_implementations": 0, "native_inventory_sha256": "1321b345493830ea5acb9fe9b46c069c51a8ac16e3456ae5a5c50529491a9171", "new_files_deletions_and_executable_modes_supported": true, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "original_bug_canary_nop_equivalent": true, "original_bug_runtime_wrongness_established": false, "partial_repair_canary": false, "partial_repair_sha256": null, "partial_repair_wrongness_established": false, "provided_original_bug_control": true, "repo_url": "https://github.com/swesmith/msiemens__tinydb.10644a0e.git", "runtime_image": null, "runtime_ready": false, "runtime_recipe": { "dependency_installation_pinned": false, "official_install_cmds": [ "python -m pip install -e ." ], "official_pytest_argv": [ "pytest", "--disable-warnings", "--color=no", "--tb=no", "--verbose" ], "official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose", "panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.", "python_version": "3.10", "source_bound_test_dependency_cmds": [ "python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'" ], "test_dependency_source_sha256": { "pyproject.toml": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be", "pytest.ini": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" } }, "runtime_resource_review_required": false, "schema": "python-git-patch-jobs-v1", "source_base_commit": "32c86a9a38b67bcba98424fa13fb2d1c116e3ac6", "source_completion_sha256": "c0ac620a8360881c6ebfcdabc65648f60a852ebe1634d84fa9e21a8f0eb17a02", "source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876", "source_pr_url": null, "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__532t36or", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "7440c35132e4ab53105cfc55bdc3581158a0b90bc463de06862ffe4eabfc6bcd", "is_fork": true, "learner_path": "tasks/861ff22633f62d146ef5c43c/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/32c86a9a38b67bcba98424fa13fb2d1c116e3ac6/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "2a6ee925c9360d16d414592679953e7d200120bd6c135c311e2167530548cab6", "provenance_path": "tasks/861ff22633f62d146ef5c43c/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "32c86a9a38b67bcba98424fa13fb2d1c116e3ac6", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "32f4d0afbec2910dbddee3574bb37f8b7abbbc0f", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__532t36or", "task_sha256": "95bced34b63271a13f92efbad39c5d3ac76017f19cd62719f727b028dfa9b007", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "source_repo": "swesmith/msiemens__tinydb.10644a0e", "symlink_submodule_changes_supported": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__532t36or", "transfer": "index-independent-worktree-to-Git-binary-patch", "transfer_path": "/testbed/submission.patch", "upstream_repo": "msiemens/tinydb"}1234567891011121314151617#!/bin/bashset -Eeuo pipefailsource /opt/miniconda3/bin/activateconda activate testbedcd /testbed/repopython -c 'import sys; assert sys.version_info[:2] == (3, 10)'/usr/bin/sha256sum --check <<'OPENENV_NATIVE_TEST_REQUIREMENT'4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be pyproject.tomlOPENENV_NATIVE_TEST_REQUIREMENTpython -m pip install -e .python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'
cat > /tmp/openenv-tinydb-yaml.txt <<'OPENENV_PYYAML_PIN'PyYAML==6.0.3 --hash=sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0bOPENENV_PYYAML_PINpython -m pip install --no-deps --only-binary=:all: --require-hashes --index-url https://pypi.org/simple -r /tmp/openenv-tinydb-yaml.txtpython -c 'import yaml; assert yaml.__version__ == "6.0.3"'123# Runtime is selected only by an independently qualified immutable amd64 receipt.FROM ubuntu:22.04RUN false1234567891011121314151617181920212223242526272829303132333435363738394041JSONStorage ignores custom json.dumps kwargs
#### Description
When using JSONStorage with custom kwargs for json.dumps (like `sort_keys`, `indent`, etc.), the kwargs are being ignored and not passed to the json.dumps call.
#### Steps/Code to Reproduce
```pythonfrom tinydb import TinyDBimport tempfileimport os
# Create a temporary database filewith tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as f: db_path = f.name
try: # Initialize TinyDB with custom JSON formatting db = TinyDB(db_path, sort_keys=True, indent=4, separators=(',', ': ')) db.insert({'b': 1}) db.insert({'a': 1}) db.close() # Read the file content with open(db_path, 'r') as f: content = f.read() print("Actual output:") print(repr(content)) print("\nExpected formatted JSON with indentation and sorted keys") finally: os.unlink(db_path)```
The database file should contain properly formatted JSON with sorted keys and indentation, but instead it contains minified JSON without the custom formatting.
## Environment
The repository is at `/testbed/repo`. Its dependencies, including pytest, are installed in the `testbed` conda environment, which comes first on PATH. If `python -m pytest` reports that pytest is missing, use the full interpreter path: `/opt/miniconda3/envs/testbed/bin/python -m pytest <tests>`. Don't install packages: the tests need nothing else, and the sandbox may have no network access.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386{ "all_runtime_and_training_flags": false, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "source_healthy_reference_proof": { "FAIL_TO_PASS": [ "tests/test_storages.py::test_json_kwargs", "tests/test_tinydb.py::test_insert_invalid_dict" ], "PASS_TO_PASS": [ "tests/test_middlewares.py::test_caching", "tests/test_middlewares.py::test_caching_read", "tests/test_middlewares.py::test_caching_write_many", "tests/test_middlewares.py::test_caching_flush", "tests/test_middlewares.py::test_caching_flush_manually", "tests/test_middlewares.py::test_caching_write", "tests/test_middlewares.py::test_nested", "tests/test_middlewares.py::test_caching_json_write", "tests/test_operations.py::test_delete[memory]", "tests/test_operations.py::test_delete[json]", "tests/test_operations.py::test_add_int[memory]", "tests/test_operations.py::test_add_int[json]", "tests/test_operations.py::test_add_str[memory]", "tests/test_operations.py::test_add_str[json]", "tests/test_operations.py::test_subtract[memory]", "tests/test_operations.py::test_subtract[json]", "tests/test_operations.py::test_set[memory]", "tests/test_operations.py::test_set[json]", "tests/test_operations.py::test_increment[memory]", "tests/test_operations.py::test_increment[json]", "tests/test_operations.py::test_decrement[memory]", "tests/test_operations.py::test_decrement[json]", "tests/test_queries.py::test_no_path", "tests/test_queries.py::test_path_exists", "tests/test_queries.py::test_path_and", "tests/test_queries.py::test_callable_in_path_with_map", "tests/test_queries.py::test_callable_in_path_with_chain", "tests/test_queries.py::test_eq", "tests/test_queries.py::test_ne", "tests/test_queries.py::test_lt", "tests/test_queries.py::test_le", "tests/test_queries.py::test_gt", "tests/test_queries.py::test_ge", "tests/test_queries.py::test_or", "tests/test_queries.py::test_and", "tests/test_queries.py::test_not", "tests/test_queries.py::test_has_key", "tests/test_queries.py::test_regex", "tests/test_queries.py::test_custom", "tests/test_queries.py::test_custom_with_params", "tests/test_queries.py::test_any", "tests/test_queries.py::test_all", "tests/test_queries.py::test_has", "tests/test_queries.py::test_one_of", "tests/test_queries.py::test_hash", "tests/test_queries.py::test_orm_usage", "tests/test_queries.py::test_repr", "tests/test_queries.py::test_subclass", "tests/test_queries.py::test_noop", "tests/test_queries.py::test_equality", "tests/test_queries.py::test_empty_query_error", "tests/test_queries.py::test_fragment", "tests/test_queries.py::test_fragment_with_path", "tests/test_queries.py::test_get_item", "tests/test_storages.py::test_json", "tests/test_storages.py::test_json_readwrite", "tests/test_storages.py::test_json_read", "tests/test_storages.py::test_create_dirs", "tests/test_storages.py::test_json_invalid_directory", "tests/test_storages.py::test_in_memory", "tests/test_storages.py::test_in_memory_close", "tests/test_storages.py::test_custom", "tests/test_storages.py::test_read_once", "tests/test_storages.py::test_custom_with_exception", "tests/test_storages.py::test_yaml", "tests/test_storages.py::test_encoding", "tests/test_tables.py::test_next_id[memory]", "tests/test_tables.py::test_next_id[json]", "tests/test_tables.py::test_tables_list[memory]", "tests/test_tables.py::test_tables_list[json]", "tests/test_tables.py::test_one_table[memory]", "tests/test_tables.py::test_one_table[json]", "tests/test_tables.py::test_multiple_tables[memory]", "tests/test_tables.py::test_multiple_tables[json]", "tests/test_tables.py::test_caching[memory]", "tests/test_tables.py::test_caching[json]", "tests/test_tables.py::test_query_cache[memory]", "tests/test_tables.py::test_query_cache[json]", "tests/test_tables.py::test_query_cache_with_mutable_callable[memory]", "tests/test_tables.py::test_query_cache_with_mutable_callable[json]", "tests/test_tables.py::test_zero_cache_size[memory]", "tests/test_tables.py::test_zero_cache_size[json]", "tests/test_tables.py::test_query_cache_size[memory]", "tests/test_tables.py::test_query_cache_size[json]", "tests/test_tables.py::test_lru_cache[memory]", "tests/test_tables.py::test_lru_cache[json]", "tests/test_tables.py::test_table_is_iterable[memory]", "tests/test_tables.py::test_table_is_iterable[json]", "tests/test_tables.py::test_table_name[memory]", "tests/test_tables.py::test_table_name[json]", "tests/test_tables.py::test_table_repr[memory]", "tests/test_tables.py::test_table_repr[json]", "tests/test_tables.py::test_truncate_table[memory]", "tests/test_tables.py::test_truncate_table[json]", "tests/test_tables.py::test_persist_table[memory]", "tests/test_tables.py::test_persist_table[json]", "tests/test_tinydb.py::test_drop_tables[memory]", "tests/test_tinydb.py::test_drop_tables[json]", "tests/test_tinydb.py::test_all[memory]", "tests/test_tinydb.py::test_all[json]", "tests/test_tinydb.py::test_insert[memory]", "tests/test_tinydb.py::test_insert[json]", "tests/test_tinydb.py::test_insert_ids[memory]", "tests/test_tinydb.py::test_insert_ids[json]", "tests/test_tinydb.py::test_insert_with_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_doc_id[json]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[json]", "tests/test_tinydb.py::test_insert_multiple[memory]", "tests/test_tinydb.py::test_insert_multiple[json]", "tests/test_tinydb.py::test_insert_multiple_with_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_ids[json]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[json]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[memory]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[json]", "tests/test_tinydb.py::test_insert_valid_mapping_type[memory]", "tests/test_tinydb.py::test_insert_valid_mapping_type[json]", "tests/test_tinydb.py::test_custom_mapping_type_with_json", "tests/test_tinydb.py::test_remove[memory]", "tests/test_tinydb.py::test_remove[json]", "tests/test_tinydb.py::test_remove_all_fails[memory]", "tests/test_tinydb.py::test_remove_all_fails[json]", "tests/test_tinydb.py::test_remove_multiple[memory]", "tests/test_tinydb.py::test_remove_multiple[json]", "tests/test_tinydb.py::test_remove_ids[memory]", "tests/test_tinydb.py::test_remove_ids[json]", "tests/test_tinydb.py::test_remove_returns_ids[memory]", "tests/test_tinydb.py::test_remove_returns_ids[json]", "tests/test_tinydb.py::test_update[memory]", "tests/test_tinydb.py::test_update[json]", "tests/test_tinydb.py::test_update_all[memory]", "tests/test_tinydb.py::test_update_all[json]", "tests/test_tinydb.py::test_update_returns_ids[memory]", "tests/test_tinydb.py::test_update_returns_ids[json]", "tests/test_tinydb.py::test_update_transform[memory]", "tests/test_tinydb.py::test_update_transform[json]", "tests/test_tinydb.py::test_update_ids[memory]", "tests/test_tinydb.py::test_update_ids[json]", "tests/test_tinydb.py::test_update_multiple[memory]", "tests/test_tinydb.py::test_update_multiple[json]", "tests/test_tinydb.py::test_update_multiple_operation[memory]", "tests/test_tinydb.py::test_update_multiple_operation[json]", "tests/test_tinydb.py::test_upsert[memory]", "tests/test_tinydb.py::test_upsert[json]", "tests/test_tinydb.py::test_upsert_by_id[memory]", "tests/test_tinydb.py::test_upsert_by_id[json]", "tests/test_tinydb.py::test_search[memory]", "tests/test_tinydb.py::test_search[json]", "tests/test_tinydb.py::test_search_path[memory]", "tests/test_tinydb.py::test_search_path[json]", "tests/test_tinydb.py::test_search_no_results_cache[memory]", "tests/test_tinydb.py::test_search_no_results_cache[json]", "tests/test_tinydb.py::test_get[memory]", "tests/test_tinydb.py::test_get[json]", "tests/test_tinydb.py::test_get_ids[memory]", "tests/test_tinydb.py::test_get_ids[json]", "tests/test_tinydb.py::test_get_multiple_ids[memory]", "tests/test_tinydb.py::test_get_multiple_ids[json]", "tests/test_tinydb.py::test_get_invalid[memory]", "tests/test_tinydb.py::test_get_invalid[json]", "tests/test_tinydb.py::test_count[memory]", "tests/test_tinydb.py::test_count[json]", "tests/test_tinydb.py::test_contains[memory]", "tests/test_tinydb.py::test_contains[json]", "tests/test_tinydb.py::test_contains_ids[memory]", "tests/test_tinydb.py::test_contains_ids[json]", "tests/test_tinydb.py::test_contains_invalid[memory]", "tests/test_tinydb.py::test_contains_invalid[json]", "tests/test_tinydb.py::test_get_idempotent[memory]", "tests/test_tinydb.py::test_get_idempotent[json]", "tests/test_tinydb.py::test_multiple_dbs", "tests/test_tinydb.py::test_storage_closed_once", "tests/test_tinydb.py::test_unique_ids", "tests/test_tinydb.py::test_lastid_after_open", "tests/test_tinydb.py::test_doc_ids_json", "tests/test_tinydb.py::test_insert_string", "tests/test_tinydb.py::test_gc", "tests/test_tinydb.py::test_drop_table", "tests/test_tinydb.py::test_empty_write", "tests/test_tinydb.py::test_query_cache", "tests/test_tinydb.py::test_tinydb_is_iterable[memory]", "tests/test_tinydb.py::test_tinydb_is_iterable[json]", "tests/test_tinydb.py::test_repr", "tests/test_tinydb.py::test_delete", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[memory]", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[json]", "tests/test_tinydb.py::test_access_storage", "tests/test_tinydb.py::test_empty_db_len", "tests/test_tinydb.py::test_insert_on_existing_db", "tests/test_tinydb.py::test_storage_access", "tests/test_tinydb.py::test_lambda_query", "tests/test_utils.py::test_lru_cache", "tests/test_utils.py::test_lru_cache_set_multiple", "tests/test_utils.py::test_lru_cache_set_update", "tests/test_utils.py::test_lru_cache_get", "tests/test_utils.py::test_lru_cache_delete", "tests/test_utils.py::test_lru_cache_clear", "tests/test_utils.py::test_lru_cache_unlimited", "tests/test_utils.py::test_lru_cache_unlimited_explicit", "tests/test_utils.py::test_lru_cache_iteration_works", "tests/test_utils.py::test_freeze" ], "all_git_blobs_modes_verified": true, "cloud_launch_ready": false, "commits": { "bug": "32f4d0afbec2910dbddee3574bb37f8b7abbbc0f", "healthy": "278700580526dd378f18f40b641885ec78df63e1", "learner": "32c86a9a38b67bcba98424fa13fb2d1c116e3ac6" }, "existing_squirrel_snapshot_reused": false, "full_transfer_allowlist": [ "/testbed/.coveragerc", "/testbed/.github/stale.yml", "/testbed/.gitignore", "/testbed/.readthedocs.yml", "/testbed/CONTRIBUTING.rst", "/testbed/LICENSE", "/testbed/MANIFEST.in", "/testbed/README.rst", "/testbed/artwork/logo.png", "/testbed/artwork/logo.svg", "/testbed/docs/.gitignore", "/testbed/docs/Makefile", "/testbed/docs/_static/logo.png", "/testbed/docs/_templates/links.html", "/testbed/docs/_templates/sidebarlogo.html", "/testbed/docs/_themes/.gitignore", "/testbed/docs/_themes/LICENSE", "/testbed/docs/_themes/README", "/testbed/docs/_themes/flask/layout.html", "/testbed/docs/_themes/flask/page.html", "/testbed/docs/_themes/flask/relations.html", "/testbed/docs/_themes/flask/static/flasky.css_t", "/testbed/docs/_themes/flask/theme.conf", "/testbed/docs/_themes/flask_theme_support.py", "/testbed/docs/api.rst", "/testbed/docs/changelog.rst", "/testbed/docs/conf.py", "/testbed/docs/contribute.rst", "/testbed/docs/extend.rst", "/testbed/docs/extensions.rst", "/testbed/docs/getting-started.rst", "/testbed/docs/index.rst", "/testbed/docs/intro.rst", "/testbed/docs/make.bat", "/testbed/docs/upgrade.rst", "/testbed/docs/usage.rst", "/testbed/mypy.ini", "/testbed/poetry.lock", "/testbed/pyproject.toml", "/testbed/pytest.ini", "/testbed/tests/__init__.py", "/testbed/tests/conftest.py", "/testbed/tests/test_middlewares.py", "/testbed/tests/test_operations.py", "/testbed/tests/test_queries.py", "/testbed/tests/test_tables.py", "/testbed/tests/test_utils.py", "/testbed/tinydb/__init__.py", "/testbed/tinydb/database.py", "/testbed/tinydb/middlewares.py", "/testbed/tinydb/mypy_plugin.py", "/testbed/tinydb/operations.py", "/testbed/tinydb/py.typed", "/testbed/tinydb/queries.py", "/testbed/tinydb/storages.py", "/testbed/tinydb/table.py", "/testbed/tinydb/utils.py", "/testbed/tinydb/version.py" ], "healthy_stage_meaning": "Direct parent of the mutation; no source or test execution has been performed", "mutation_matches_dataset_and_git_blobs": true, "official_profile": { "eval_sets": [], "profile_class": "Tinydb10644a0e", "profile_lines": [ 1020, 1023 ], "profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f", "profile_source_path": "swesmith/profiles/python.py", "profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286", "upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "upstream_repo": "msiemens/tinydb" }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "private_test_paths": [ "tests/test_storages.py", "tests/test_tinydb.py" ], "private_tests_unchanged": true, "profile_mapping_basis": "Explicit upstream repo and full commit fields parsed from pinned official Python profile AST, not basename inference", "qwen_calibrated": false, "runtime_qualified": false, "source_paths": [ "tinydb/storages.py" ], "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_stages_bytes": 932978, "task_id": "msiemens__tinydb.10644a0e.func_basic__532t36or", "transfer_limitation": "Existing regular files only; new arbitrary file additions need a qualified patch adapter", "upstream_repo": "msiemens/tinydb" }, "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__532t36or", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "7440c35132e4ab53105cfc55bdc3581158a0b90bc463de06862ffe4eabfc6bcd", "is_fork": true, "learner_path": "tasks/861ff22633f62d146ef5c43c/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/32c86a9a38b67bcba98424fa13fb2d1c116e3ac6/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "2a6ee925c9360d16d414592679953e7d200120bd6c135c311e2167530548cab6", "provenance_path": "tasks/861ff22633f62d146ef5c43c/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "32c86a9a38b67bcba98424fa13fb2d1c116e3ac6", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "32f4d0afbec2910dbddee3574bb37f8b7abbbc0f", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__532t36or", "task_sha256": "95bced34b63271a13f92efbad39c5d3ac76017f19cd62719f727b028dfa9b007", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "task_kind": "original-source-mutation"}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788{ "generated_reference": false, "healthy_reference_delta_sha256": "fb64de0dda930e2063f7dd19d6d8ab3be58becf523f9e36969336c6507f7c614", "native_pytest_ids_preserved": true, "original_source_code_license": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/32c86a9a38b67bcba98424fa13fb2d1c116e3ac6/LICENSE" }, "provided_reference": true, "qwen_calibrated": false, "runtime_qualified": false, "source_completion_sha256": "c0ac620a8360881c6ebfcdabc65648f60a852ebe1634d84fa9e21a8f0eb17a02", "source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876", "source_proof_sha256": "d2c5bf721b7b4b20e7e5a17e1e3b1561bc0591edfc6dd28df13782f4e2b121e4", "source_record": { "anti_training_canary": false, "anti_training_reviewed": true, "candidate_id": "swesmith-py:msiemens__tinydb.10644a0e.func_basic__532t36or", "cloud_launch_ready": false, "eligibility": { "reasons": [], "semantic_nonoverlap_established": false, "status": "eligible_for_controls", "training_admissible": false, "warnings": [] }, "healthy_mirror_commit": "278700580526dd378f18f40b641885ec78df63e1", "instruction_sha256": "7440c35132e4ab53105cfc55bdc3581158a0b90bc463de06862ffe4eabfc6bcd", "is_fork": true, "learner_path": "tasks/861ff22633f62d146ef5c43c/learner", "license_evidence": { "source_code": { "actual_upstream_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "actual_upstream_url": "https://raw.githubusercontent.com/msiemens/tinydb/10644a0e07ad180c5b756aba272ee6b0dbd12df8/LICENSE", "reviewed": true, "sha256": "b0e2a2d39271e3d96b717d7be8235ac413d74797bf7f742f0801cfaad6c8c912", "spdx": "MIT", "training_allowed": true, "url": "https://raw.githubusercontent.com/swesmith/msiemens__tinydb.10644a0e/32c86a9a38b67bcba98424fa13fb2d1c116e3ac6/LICENSE" }, "task_bundle": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" } }, "original_source_commit": "10644a0e07ad180c5b756aba272ee6b0dbd12df8", "patch_sha256": "2a6ee925c9360d16d414592679953e7d200120bd6c135c311e2167530548cab6", "provenance_path": "tasks/861ff22633f62d146ef5c43c/source-proof.json", "repository_lineage": [ "swesmith/msiemens__tinydb.10644a0e", "msiemens/tinydb" ], "rfc008_complete": false, "runtime_qualified": false, "semantic_nonoverlap_established": false, "source_commit": "32c86a9a38b67bcba98424fa13fb2d1c116e3ac6", "source_dataset": "SWE-bench/SWE-smith-py", "source_head_commit": "32f4d0afbec2910dbddee3574bb37f8b7abbbc0f", "source_kind": "mutation", "source_repo": "swesmith/msiemens__tinydb.10644a0e", "source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e", "source_split": "train", "target_model_calibrated": false, "task_id": "msiemens__tinydb.10644a0e.func_basic__532t36or", "task_sha256": "95bced34b63271a13f92efbad39c5d3ac76017f19cd62719f727b028dfa9b007", "training_admissible": false, "upstream_identity_reviewed": true, "upstream_repo": "msiemens/tinydb", "usage": "quarantine_only" }, "task_bundle_license": { "reviewed": true, "sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808", "spdx": "MIT", "training_allowed": true, "url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md" }, "training_admissible": false, "trusted_tests_sha256": "ff9a5ef814fab3aeaea8a510213b4330c9b7600d0e4cd9f29754ec6179c0d458"}1234567891011121314151617181920212223242526272829303132333435diff --git a/tinydb/storages.py b/tinydb/storages.pyindex b6a7a6391cb0ec0673803e744e5dbfd94b52cf69..d5a2db7804444a430534219838e55fcfeee7d305 100644--- a/tinydb/storages.py+++ b/tinydb/storages.py@@ -136,23 +136,24 @@ return json.load(self._handle) def write(self, data: Dict[str, Dict[str, Any]]):+ # Move the cursor to the beginning of the file just in case self._handle.seek(0) - try:- serialized = json.dumps(data)- except TypeError:- raise ValueError('Data is not serializable.')+ # Serialize the database state using the user-provided arguments+ serialized = json.dumps(data, **self.kwargs) + # Write the serialized data to the file try: self._handle.write(serialized) except io.UnsupportedOperation: raise IOError('Cannot write to the database. Access mode is "{0}"'.format(self._mode)) + # Ensure the file has been written self._handle.flush() os.fsync(self._handle.fileno()) - new_offset = len(serialized)- self._handle.seek(new_offset)+ # Remove data that is behind the new cursor in case the file has+ # gotten shorter self._handle.truncate() 1234567891011121314151617181920212223242526272829303132333435363738394041#!/bin/bashset -Eeuo pipefailcd /testbed/repocat > /tmp/openenv-reference.diff <<'OPENENV_REFERENCE'diff --git a/tinydb/storages.py b/tinydb/storages.pyindex b6a7a6391cb0ec0673803e744e5dbfd94b52cf69..d5a2db7804444a430534219838e55fcfeee7d305 100644--- a/tinydb/storages.py+++ b/tinydb/storages.py@@ -136,23 +136,24 @@ return json.load(self._handle) def write(self, data: Dict[str, Dict[str, Any]]):+ # Move the cursor to the beginning of the file just in case self._handle.seek(0) - try:- serialized = json.dumps(data)- except TypeError:- raise ValueError('Data is not serializable.')+ # Serialize the database state using the user-provided arguments+ serialized = json.dumps(data, **self.kwargs) + # Write the serialized data to the file try: self._handle.write(serialized) except io.UnsupportedOperation: raise IOError('Cannot write to the database. Access mode is "{0}"'.format(self._mode)) + # Ensure the file has been written self._handle.flush() os.fsync(self._handle.fileno()) - new_offset = len(serialized)- self._handle.seek(new_offset)+ # Remove data that is behind the new cursor in case the file has+ # gotten shorter self._handle.truncate() OPENENV_REFERENCE/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff123456789101112131415161718192021222324version = "1.0"
[agent]timeout_sec = 1800.0
[verifier]timeout_sec = 900.0
[environment]docker_image = "ghcr.io/younesbelkada/scale800@sha256:bce59ccb3d987af46af3296291a49c81579fda562019c08fec0f809446291012"build_timeout_sec = 600.0cpus = 2memory_mb = 8192storage_mb = 16384
[metadata]author_name = "SWE-smith source adapter"category = "bugfix"tags = ["swe", "python", "mutation-repair"]
[environment.env]# The image's PATH with the testbed env first: the project and pytest are installed there, and the agent's# non-interactive shells never run `conda activate`PATH = "/opt/miniconda3/envs/testbed/bin:/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177"""Preserve confirmed requested assertion failures; keep positive checks strict."""
import argparseimport hashlibimport jsonimport reimport xml.etree.ElementTree as ETfrom pathlib import Path
GROUPS = ("pass-to-pass", "fail-to-pass")
def split_nodeid(target): prefix, bracket, parameter = target.partition("[") parts = prefix.split("::") if bracket: parts[-1] += bracket + parameter return parts
def matches(case, target): parts = split_nodeid(target) module = parts[0].removesuffix(".py").replace("/", ".") classname, name = case.get("classname", ""), case.get("name", "") if not (classname == module or classname.startswith(module + ".")): return False selector = parts[-1] if len(parts) > 1 else "" classes = parts[1:-1] if classes and classname != module + "." + ".".join(classes): return False return ( not selector or name == selector or ("[" not in selector and name.startswith(selector + "[")) )
def capture_panels(root): panels, digests = {}, {} for group in GROUPS: path = Path(root) / (group + ".xml") if not path.exists(): panels[group] = None continue with path.open("rb") as stream: raw = stream.read(4 * 1024**2 + 1) if not 0 < len(raw) <= 4 * 1024**2 or re.search( rb"<!\s*(?:DOCTYPE|ENTITY)", raw, re.I ): raise ValueError("Unbounded or unsafe pytest XML") try: tree = ET.fromstring(raw) except ET.ParseError: raise ValueError("Malformed pytest XML") from None cases = list(tree.iter("testcase")) if len(cases) > 20000: raise ValueError("Too many pytest cases") identities = [(case.get("classname"), case.get("name")) for case in cases] if len(identities) != len(set(identities)): raise ValueError("Duplicate pytest case evidence") panels[group] = cases digests[group] = hashlib.sha256(raw).hexdigest() return panels, digests
def strict_assess(panels, expected, native_exit): """The original positive-approval conditions, applied to captured cases.""" all_cases, actual_failure = [], False for group in GROUPS: cases = panels[group] if cases is None: if actual_failure: continue raise ValueError("Missing preceding pytest panel") if actual_failure: raise ValueError( "Pytest evidence continued after the native stop-on-failure" ) targets = expected[group] if any(not any(matches(case, target) for target in targets) for case in cases): raise ValueError("Unexpected pytest case") all_cases.extend(cases) failures = [case for case in cases if case.find("failure") is not None] if any( case.find("error") is not None or case.find("skipped") is not None for case in cases ): raise ValueError("Pytest collection/error/skip is not a completed panel") actual_failure = actual_failure or bool(failures) if not failures and any( not any(matches(case, target) for case in cases) for target in targets ): raise ValueError("Declared pytest target never ran") if actual_failure: if native_exit == 0: raise ValueError("Native verifier exit disagrees with pytest failure") return {"reward": 0, "valid_test_failure": True, "cases": len(all_cases)} if native_exit != 0: raise ValueError("Setup or native verifier failed without a real test failure") if any(panels[group] is None for group in GROUPS): raise ValueError("Missing completed pytest panel") return {"reward": 1, "valid_test_failure": False, "cases": len(all_cases)}
def assess(root, expected, native_exit): if type(native_exit) is not int: raise ValueError("Native verifier exit must be an integer") if not isinstance(expected, dict) or any( not isinstance(expected.get(group), list) or not expected[group] or any(not isinstance(target, str) or not target for target in expected[group]) for group in GROUPS ): raise ValueError("Complete exact native pytest targets required") panels, digests = capture_panels(root) counts = { "cases": 0, "matched_failures": 0, "unexpected_cases": 0, "unmatched_failures": 0, "skipped_cases": 0, "error_cases": 0, "missing_panels": 0, "missing_targets": 0, } for group in GROUPS: cases = panels[group] if cases is None: counts["missing_panels"] += 1 counts["missing_targets"] += len(expected[group]) continue counts["cases"] += len(cases) for case in cases: requested = any(matches(case, target) for target in expected[group]) failure = case.find("failure") is not None counts["matched_failures"] += int(requested and failure) counts["unmatched_failures"] += int(not requested and failure) counts["unexpected_cases"] += int(not requested) counts["skipped_cases"] += int(case.find("skipped") is not None) counts["error_cases"] += int(case.find("error") is not None) counts["missing_targets"] += sum( not any(matches(case, target) for case in cases) for target in expected[group] ) if counts["matched_failures"]: if native_exit == 0: raise ValueError( "Native verifier exit disagrees with requested pytest failure" ) return { "reward": 0, "valid_test_failure": True, "cases": counts["cases"], "diagnostic_counts": counts, "panel_sha256": digests, "decision": "confirmed_requested_failure_precedence", } result = strict_assess(panels, expected, native_exit) result.update(diagnostic_counts=counts, panel_sha256=digests) return result
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--root", required=True) parser.add_argument("--expected", required=True) parser.add_argument("--native-exit", type=int, required=True) args = parser.parse_args() result = assess( args.root, json.loads(Path(args.expected).read_bytes()), args.native_exit ) reward = Path(args.root) / "reward.txt" if reward.read_text().strip() != str(result["reward"]): raise ValueError("Native raw reward disagrees with pytest evidence") (Path(args.root) / "pytest-evidence.json").write_text( json.dumps(result, sort_keys=True) + "\n" )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210{ "fail-to-pass": [ "tests/test_storages.py::test_json_kwargs", "tests/test_tinydb.py::test_insert_invalid_dict" ], "pass-to-pass": [ "tests/test_middlewares.py::test_caching", "tests/test_middlewares.py::test_caching_read", "tests/test_middlewares.py::test_caching_write_many", "tests/test_middlewares.py::test_caching_flush", "tests/test_middlewares.py::test_caching_flush_manually", "tests/test_middlewares.py::test_caching_write", "tests/test_middlewares.py::test_nested", "tests/test_middlewares.py::test_caching_json_write", "tests/test_operations.py::test_delete[memory]", "tests/test_operations.py::test_delete[json]", "tests/test_operations.py::test_add_int[memory]", "tests/test_operations.py::test_add_int[json]", "tests/test_operations.py::test_add_str[memory]", "tests/test_operations.py::test_add_str[json]", "tests/test_operations.py::test_subtract[memory]", "tests/test_operations.py::test_subtract[json]", "tests/test_operations.py::test_set[memory]", "tests/test_operations.py::test_set[json]", "tests/test_operations.py::test_increment[memory]", "tests/test_operations.py::test_increment[json]", "tests/test_operations.py::test_decrement[memory]", "tests/test_operations.py::test_decrement[json]", "tests/test_queries.py::test_no_path", "tests/test_queries.py::test_path_exists", "tests/test_queries.py::test_path_and", "tests/test_queries.py::test_callable_in_path_with_map", "tests/test_queries.py::test_callable_in_path_with_chain", "tests/test_queries.py::test_eq", "tests/test_queries.py::test_ne", "tests/test_queries.py::test_lt", "tests/test_queries.py::test_le", "tests/test_queries.py::test_gt", "tests/test_queries.py::test_ge", "tests/test_queries.py::test_or", "tests/test_queries.py::test_and", "tests/test_queries.py::test_not", "tests/test_queries.py::test_has_key", "tests/test_queries.py::test_regex", "tests/test_queries.py::test_custom", "tests/test_queries.py::test_custom_with_params", "tests/test_queries.py::test_any", "tests/test_queries.py::test_all", "tests/test_queries.py::test_has", "tests/test_queries.py::test_one_of", "tests/test_queries.py::test_hash", "tests/test_queries.py::test_orm_usage", "tests/test_queries.py::test_repr", "tests/test_queries.py::test_subclass", "tests/test_queries.py::test_noop", "tests/test_queries.py::test_equality", "tests/test_queries.py::test_empty_query_error", "tests/test_queries.py::test_fragment", "tests/test_queries.py::test_fragment_with_path", "tests/test_queries.py::test_get_item", "tests/test_storages.py::test_json", "tests/test_storages.py::test_json_readwrite", "tests/test_storages.py::test_json_read", "tests/test_storages.py::test_create_dirs", "tests/test_storages.py::test_json_invalid_directory", "tests/test_storages.py::test_in_memory", "tests/test_storages.py::test_in_memory_close", "tests/test_storages.py::test_custom", "tests/test_storages.py::test_read_once", "tests/test_storages.py::test_custom_with_exception", "tests/test_storages.py::test_yaml", "tests/test_storages.py::test_encoding", "tests/test_tables.py::test_next_id[memory]", "tests/test_tables.py::test_next_id[json]", "tests/test_tables.py::test_tables_list[memory]", "tests/test_tables.py::test_tables_list[json]", "tests/test_tables.py::test_one_table[memory]", "tests/test_tables.py::test_one_table[json]", "tests/test_tables.py::test_multiple_tables[memory]", "tests/test_tables.py::test_multiple_tables[json]", "tests/test_tables.py::test_caching[memory]", "tests/test_tables.py::test_caching[json]", "tests/test_tables.py::test_query_cache[memory]", "tests/test_tables.py::test_query_cache[json]", "tests/test_tables.py::test_query_cache_with_mutable_callable[memory]", "tests/test_tables.py::test_query_cache_with_mutable_callable[json]", "tests/test_tables.py::test_zero_cache_size[memory]", "tests/test_tables.py::test_zero_cache_size[json]", "tests/test_tables.py::test_query_cache_size[memory]", "tests/test_tables.py::test_query_cache_size[json]", "tests/test_tables.py::test_lru_cache[memory]", "tests/test_tables.py::test_lru_cache[json]", "tests/test_tables.py::test_table_is_iterable[memory]", "tests/test_tables.py::test_table_is_iterable[json]", "tests/test_tables.py::test_table_name[memory]", "tests/test_tables.py::test_table_name[json]", "tests/test_tables.py::test_table_repr[memory]", "tests/test_tables.py::test_table_repr[json]", "tests/test_tables.py::test_truncate_table[memory]", "tests/test_tables.py::test_truncate_table[json]", "tests/test_tables.py::test_persist_table[memory]", "tests/test_tables.py::test_persist_table[json]", "tests/test_tinydb.py::test_drop_tables[memory]", "tests/test_tinydb.py::test_drop_tables[json]", "tests/test_tinydb.py::test_all[memory]", "tests/test_tinydb.py::test_all[json]", "tests/test_tinydb.py::test_insert[memory]", "tests/test_tinydb.py::test_insert[json]", "tests/test_tinydb.py::test_insert_ids[memory]", "tests/test_tinydb.py::test_insert_ids[json]", "tests/test_tinydb.py::test_insert_with_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_doc_id[json]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[memory]", "tests/test_tinydb.py::test_insert_with_duplicate_doc_id[json]", "tests/test_tinydb.py::test_insert_multiple[memory]", "tests/test_tinydb.py::test_insert_multiple[json]", "tests/test_tinydb.py::test_insert_multiple_with_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_ids[json]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[memory]", "tests/test_tinydb.py::test_insert_multiple_with_doc_ids[json]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[memory]", "tests/test_tinydb.py::test_insert_invalid_type_raises_error[json]", "tests/test_tinydb.py::test_insert_valid_mapping_type[memory]", "tests/test_tinydb.py::test_insert_valid_mapping_type[json]", "tests/test_tinydb.py::test_custom_mapping_type_with_json", "tests/test_tinydb.py::test_remove[memory]", "tests/test_tinydb.py::test_remove[json]", "tests/test_tinydb.py::test_remove_all_fails[memory]", "tests/test_tinydb.py::test_remove_all_fails[json]", "tests/test_tinydb.py::test_remove_multiple[memory]", "tests/test_tinydb.py::test_remove_multiple[json]", "tests/test_tinydb.py::test_remove_ids[memory]", "tests/test_tinydb.py::test_remove_ids[json]", "tests/test_tinydb.py::test_remove_returns_ids[memory]", "tests/test_tinydb.py::test_remove_returns_ids[json]", "tests/test_tinydb.py::test_update[memory]", "tests/test_tinydb.py::test_update[json]", "tests/test_tinydb.py::test_update_all[memory]", "tests/test_tinydb.py::test_update_all[json]", "tests/test_tinydb.py::test_update_returns_ids[memory]", "tests/test_tinydb.py::test_update_returns_ids[json]", "tests/test_tinydb.py::test_update_transform[memory]", "tests/test_tinydb.py::test_update_transform[json]", "tests/test_tinydb.py::test_update_ids[memory]", "tests/test_tinydb.py::test_update_ids[json]", "tests/test_tinydb.py::test_update_multiple[memory]", "tests/test_tinydb.py::test_update_multiple[json]", "tests/test_tinydb.py::test_update_multiple_operation[memory]", "tests/test_tinydb.py::test_update_multiple_operation[json]", "tests/test_tinydb.py::test_upsert[memory]", "tests/test_tinydb.py::test_upsert[json]", "tests/test_tinydb.py::test_upsert_by_id[memory]", "tests/test_tinydb.py::test_upsert_by_id[json]", "tests/test_tinydb.py::test_search[memory]", "tests/test_tinydb.py::test_search[json]", "tests/test_tinydb.py::test_search_path[memory]", "tests/test_tinydb.py::test_search_path[json]", "tests/test_tinydb.py::test_search_no_results_cache[memory]", "tests/test_tinydb.py::test_search_no_results_cache[json]", "tests/test_tinydb.py::test_get[memory]", "tests/test_tinydb.py::test_get[json]", "tests/test_tinydb.py::test_get_ids[memory]", "tests/test_tinydb.py::test_get_ids[json]", "tests/test_tinydb.py::test_get_multiple_ids[memory]", "tests/test_tinydb.py::test_get_multiple_ids[json]", "tests/test_tinydb.py::test_get_invalid[memory]", "tests/test_tinydb.py::test_get_invalid[json]", "tests/test_tinydb.py::test_count[memory]", "tests/test_tinydb.py::test_count[json]", "tests/test_tinydb.py::test_contains[memory]", "tests/test_tinydb.py::test_contains[json]", "tests/test_tinydb.py::test_contains_ids[memory]", "tests/test_tinydb.py::test_contains_ids[json]", "tests/test_tinydb.py::test_contains_invalid[memory]", "tests/test_tinydb.py::test_contains_invalid[json]", "tests/test_tinydb.py::test_get_idempotent[memory]", "tests/test_tinydb.py::test_get_idempotent[json]", "tests/test_tinydb.py::test_multiple_dbs", "tests/test_tinydb.py::test_storage_closed_once", "tests/test_tinydb.py::test_unique_ids", "tests/test_tinydb.py::test_lastid_after_open", "tests/test_tinydb.py::test_doc_ids_json", "tests/test_tinydb.py::test_insert_string", "tests/test_tinydb.py::test_gc", "tests/test_tinydb.py::test_drop_table", "tests/test_tinydb.py::test_empty_write", "tests/test_tinydb.py::test_query_cache", "tests/test_tinydb.py::test_tinydb_is_iterable[memory]", "tests/test_tinydb.py::test_tinydb_is_iterable[json]", "tests/test_tinydb.py::test_repr", "tests/test_tinydb.py::test_delete", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[memory]", "tests/test_tinydb.py::test_insert_multiple_with_single_dict[json]", "tests/test_tinydb.py::test_access_storage", "tests/test_tinydb.py::test_empty_db_len", "tests/test_tinydb.py::test_insert_on_existing_db", "tests/test_tinydb.py::test_storage_access", "tests/test_tinydb.py::test_lambda_query", "tests/test_utils.py::test_lru_cache", "tests/test_utils.py::test_lru_cache_set_multiple", "tests/test_utils.py::test_lru_cache_set_update", "tests/test_utils.py::test_lru_cache_get", "tests/test_utils.py::test_lru_cache_delete", "tests/test_utils.py::test_lru_cache_clear", "tests/test_utils.py::test_lru_cache_unlimited", "tests/test_utils.py::test_lru_cache_unlimited_explicit", "tests/test_utils.py::test_lru_cache_iteration_works", "tests/test_utils.py::test_freeze" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128"""Trusted private pytest panel runner. Installed only in a fresh grader Job."""
import hashlibimport importlib.utilimport jsonimport osimport shutilimport statimport subprocessfrom pathlib import Path, PurePosixPath
def sha(raw): return hashlib.sha256(raw).hexdigest()
def safe(value): path = PurePosixPath(value) if ( path.is_absolute() or path.as_posix() != value or not path.parts or any(part in {".", "..", ".git"} for part in path.parts) ): raise ValueError("Unsafe trusted test path") return path
def restore(worktree, private, manifest): worktree, private = Path(worktree), Path(private) captured = {} for name, expected in manifest["files"].items(): path = private / safe(name) info = path.lstat() raw = path.read_bytes() if stat.S_ISREG(info.st_mode) else b"" if ( not stat.S_ISREG(info.st_mode) or len(raw) != expected["bytes"] or sha(raw) != expected["sha256"] or stat.S_IMODE(info.st_mode) != expected["mode"] ): raise ValueError("Trusted private test bytes or modes drifted") captured[name] = (raw, expected["mode"]) # Capture and verify every private byte before changing the submitted tree. for name in manifest["directory_roots"]: destination = worktree / safe(name) if destination.is_symlink(): raise ValueError("Submitted test directory is a symlink") for parent in destination.parents: if parent == worktree: break if parent.is_symlink(): raise ValueError("Submitted test parent is a symlink") if destination.exists(): if not destination.is_dir(): raise ValueError("Submitted test directory is not a directory") shutil.rmtree(destination) for name, (raw, mode) in captured.items(): destination = worktree / safe(name) for parent in destination.parents: if parent == worktree: break if parent.is_symlink(): raise ValueError("Submitted test parent is a symlink") if destination.is_symlink(): raise ValueError("Submitted trusted file is a symlink") destination.parent.mkdir(parents=True, exist_ok=True) destination.write_bytes(raw) destination.chmod(mode)
def run(worktree, private_root, output, invoke=None): private_root, output, worktree = Path(private_root), Path(output), Path(worktree) expected = json.loads((private_root / "expected-panels.json").read_bytes()) config = json.loads((private_root / "panel-config.json").read_bytes()) manifest = json.loads((private_root / "trusted-inventory.json").read_bytes()) restore(worktree, private_root / "trusted", manifest) output.mkdir(parents=True, exist_ok=True) for name in ( "reward.txt", "pass-to-pass.xml", "fail-to-pass.xml", "pytest-evidence.json", ): (output / name).unlink(missing_ok=True) environment = dict(os.environ) for key in ("PYTEST_ADDOPTS", "PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTHONPATH"): environment.pop(key, None) commands, native_exit = [], 0 invoke = invoke or subprocess.run for group in ("pass-to-pass", "fail-to-pass"): if ( not isinstance(expected[group], list) or not expected[group] or any( not isinstance(target, str) or not target for target in expected[group] ) ): raise ValueError("Frozen native pytest selectors are incomplete") command = [ *config["official_pytest_argv"], "--override-ini=addopts=", "--junitxml=" + str(output / (group + ".xml")), *expected[group], ] result = invoke(command, cwd=worktree, env=environment, check=False) native_exit = result.returncode commands.append({"group": group, "argv": command, "exit_code": native_exit}) if native_exit != 0: break (output / "pytest-commands.json").write_text( json.dumps(commands, sort_keys=True) + "\n" ) spec = importlib.util.spec_from_file_location( "trusted_pytest_result", private_root / "check_pytest.py" ) checker = importlib.util.module_from_spec(spec) spec.loader.exec_module(checker) result = checker.assess(output, expected, native_exit) (output / "reward.txt").write_text(str(result["reward"]) + "\n") (output / "pytest-evidence.json").write_text( json.dumps(result, sort_keys=True) + "\n" ) return result
if __name__ == "__main__": run("/testbed/repo", "/tests", "/logs/verifier")1234567891011121314151617181920212223{ "dependency_installation_pinned": false, "official_install_cmds": [ "python -m pip install -e ." ], "official_pytest_argv": [ "pytest", "--disable-warnings", "--color=no", "--tb=no", "--verbose" ], "official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose", "panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.", "python_version": "3.10", "source_bound_test_dependency_cmds": [ "python -m pip install 'pytest>=7.2,<8' 'pytest-cov>=4,<5'" ], "test_dependency_source_sha256": { "pyproject.toml": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be", "pytest.ini": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" }}123456#!/bin/bashset -Eeuo pipefailsource /opt/miniconda3/bin/activateconda activate testbedcd /testbed/repoexec python -I /tests/grade.py1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "directory_roots": [ "tests" ], "files": { "pyproject.toml": { "bytes": 1846, "mode": 420, "sha256": "4318e4525086b9ab07b2269c7a6f1ff2003ad01a663b94f56e772d63655166be" }, "pytest.ini": { "bytes": 70, "mode": 420, "sha256": "2c2ccbf97dabef288fd402c4bb1ddba4d3baa35d1f903a3f5735633c1d504b7c" }, "tests/__init__.py": { "bytes": 0, "mode": 420, "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "tests/conftest.py": { "bytes": 625, "mode": 420, "sha256": "502596fae1843322ec533028a76474d39e6fb70587a5749d8c9dd734b35e625b" }, "tests/test_middlewares.py": { "bytes": 2412, "mode": 420, "sha256": "85a748d3d10e7be042ed37318153a6b79c7913a5d9536cad406ccccad380577b" }, "tests/test_operations.py": { "bytes": 1021, "mode": 420, "sha256": "6313d342626a12973a5532b0b9344c5a30a959d7bfa4f6ca07d147317aee469e" }, "tests/test_queries.py": { "bytes": 12331, "mode": 420, "sha256": "7978c6220a192f4256018bf37d76e6b4c644a962fed4d6fca7d8594b2cf63a49" }, "tests/test_storages.py": { "bytes": 6489, "mode": 420, "sha256": "d74695d20e1d1742fa558da49bc2df8e84ca34e64e001070cbccce215bd39fa2" }, "tests/test_tables.py": { "bytes": 4109, "mode": 420, "sha256": "f018615899e7c9c813aba0820c639f9402d3c9865a376eedaf9dc3ee89b85ef3" }, "tests/test_tinydb.py": { "bytes": 18110, "mode": 420, "sha256": "d106d5e94536afe8416c1b8b01bc63381abb97f81a6a120743e7e1963b07b1d1" }, "tests/test_utils.py": { "bytes": 2257, "mode": 420, "sha256": "659bd414226988e81d2811259c112676aa6bdfa3b9fb6fed4631030ae6d73f2e" } }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061[tool.poetry]name = "tinydb"version = "4.8.2"description = "TinyDB is a tiny, document oriented database optimized for your happiness :)"authors = ["Markus Siemens <markus@m-siemens.de>"]license = "MIT"
readme = "README.rst"
homepage = "https://github.com/msiemens/tinydb"documentation = "https://tinydb.readthedocs.org/"
keywords = ["database", "nosql"]
classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Topic :: Database", "Topic :: Database :: Database Engines/Servers", "Topic :: Utilities", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Operating System :: OS Independent", "Typing :: Typed",]
packages = [ { include = "tinydb" }, { include = "tests", format = "sdist" }]
[tool.poetry.urls]"Changelog" = "https://tinydb.readthedocs.io/en/latest/changelog.html""Issues" = "https://github.com/msiemens/tinydb/issues"
[tool.poetry.dependencies]python = "^3.8"
[tool.poetry.dev-dependencies]pytest = "^7.2.0"pytest-pycodestyle = "^2.3.1"pytest-cov = "^4.0.0"pycodestyle = "^2.10.0"sphinx = "^7.0.0"coveralls = "^3.3.1"pyyaml = "^6.0"pytest-mypy = { version = "^0.10.2", markers = "platform_python_implementation != 'PyPy'" }types-PyYAML = "^6.0.0"
[build-system]requires = ["poetry-core"]build-backend = "poetry.core.masonry.api"12[pytest]addopts=--verbose --cov-append --cov-report term --cov tinydbtasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/tests/trusted-inventory.jsonAdded+62
tasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/validation/canaries/original-bug.shAdded+3
tasks/msiemens__tinydb.10644a0e.func_basic__3oacyvpm/validation/openenv.jsonAdded+27
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/LICENSE.sourceAdded+7
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/adapter.jsonAdded+127
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/dependency-setup.shAdded+17
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/environment/DockerfileAdded+3
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/instruction.mdAdded+37
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/metadata.jsonAdded+386
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/provenance.jsonAdded+88
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/provided-gold.diffAdded+15
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/solution/solve.shAdded+21
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/task.tomlAdded+24
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/check_pytest.pyAdded+177
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/expected-panels.jsonAdded+210
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/grade.pyAdded+128
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/panel-config.jsonAdded+23
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/test.shAdded+6
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted-inventory.jsonAdded+62
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/pyproject.tomlAdded+61
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/pytest.iniAdded+2
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/__init__.pyAdded
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/conftest.pyAdded+27
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_middlewares.pyAdded+105
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_operations.pyAdded+37
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_queries.pyAdded+445
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_storages.pyAdded+281
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_tables.pyAdded+179
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_tinydb.pyAdded+716
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/tests/trusted/tests/test_utils.pyAdded+116
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/validation/canaries/original-bug.shAdded+3
tasks/msiemens__tinydb.10644a0e.func_basic__4550j9d7/validation/openenv.jsonAdded+27
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/LICENSE.sourceAdded+7
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/adapter.jsonAdded+127
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/dependency-setup.shAdded+17
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/environment/DockerfileAdded+3
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/instruction.mdAdded+41
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/metadata.jsonAdded+386
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/provenance.jsonAdded+88
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/provided-gold.diffAdded+35
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/solution/solve.shAdded+41
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/task.tomlAdded+24
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/check_pytest.pyAdded+177
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/expected-panels.jsonAdded+210
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/grade.pyAdded+128
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/panel-config.jsonAdded+23
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/test.shAdded+6
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted-inventory.jsonAdded+62
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted/pyproject.tomlAdded+61
tasks/msiemens__tinydb.10644a0e.func_basic__532t36or/tests/trusted/pytest.iniAdded+2