Harbor format: 871 coding_baseline tasks (part 39)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/tests/trusted-inventory.json +132 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/tests/trusted/tox.ini +32 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/canaries/first-hunk-only.sh +28 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/canaries/original-bug.sh +3 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/openenv.json +27 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/LICENSE.source +30 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/adapter.json +127 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/dependency-setup.sh +8 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/environment/Dockerfile +3 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/instruction.md +35 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/metadata.json +368 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/provenance.json +88 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/provided-gold.diff +27 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/solution/solve.sh +33 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/task.toml +24 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/check_pytest.py +91 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/expected-panels.json +184 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/grade.py +128 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/panel-config.json +23 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/test.sh +6 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted-inventory.json +132 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/__init__.py +0 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_invalid.toml +2 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_invalid.yaml +2 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_valid.toml +1 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_valid.yaml +3 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/perf_report.py +87 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_basic.py +454 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_check.py +98 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_cli.py +174 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_error.py +524 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_fill.py +20 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_grouping.py +105 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_match.py +510 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_mutation.py +325 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_path_and_t.py +355 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_reduction.py +153 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_scope_vars.py +106 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_snippets.py +59 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_spec.py +26 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_streaming.py +209 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_target_types.py +272 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_tutorial.py +19 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/pytest.ini +2 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/setup.py +88 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/tox.ini +32 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/canaries/first-hunk-only.sh +21 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/canaries/original-bug.sh +3 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/openenv.json +27 -0
- tasks/mahmoud__glom.fb3c4e76.combine_file__izanr69t/LICENSE.source +30 -0
tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"directory_roots": [
|
| 3 |
+
"glom/test"
|
| 4 |
+
],
|
| 5 |
+
"files": {
|
| 6 |
+
"glom/test/__init__.py": {
|
| 7 |
+
"bytes": 0,
|
| 8 |
+
"mode": 420,
|
| 9 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
| 10 |
+
},
|
| 11 |
+
"glom/test/data/test_invalid.toml": {
|
| 12 |
+
"bytes": 19,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "f59a1d038e1648113ad5f0452ea99b79fc29d1eac035959e95d1c27ff44dc144"
|
| 15 |
+
},
|
| 16 |
+
"glom/test/data/test_invalid.yaml": {
|
| 17 |
+
"bytes": 15,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "a5de9f6a4b0a10d16777fc47f58e96271303682d0c7fbd439a034d824e6f5b08"
|
| 20 |
+
},
|
| 21 |
+
"glom/test/data/test_valid.toml": {
|
| 22 |
+
"bytes": 18,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "a13bb47add7b013b3086e4530f1f8daf2149bc4c3ae97237ff84f95facf4f5c5"
|
| 25 |
+
},
|
| 26 |
+
"glom/test/data/test_valid.yaml": {
|
| 27 |
+
"bytes": 23,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "0d40245ac0403c81a09e8521140c9ef50da30d8031efc6aef25fcb44be24362a"
|
| 30 |
+
},
|
| 31 |
+
"glom/test/perf_report.py": {
|
| 32 |
+
"bytes": 1962,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "da3294405f48e1b4e46b133eb8abb514019b4cc46547bd12c7bea65ef56467ed"
|
| 35 |
+
},
|
| 36 |
+
"glom/test/test_basic.py": {
|
| 37 |
+
"bytes": 14233,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "364581bf0f191b243d73f0cf5558cc9152126fd83c7fca1d97f953bf5478fd85"
|
| 40 |
+
},
|
| 41 |
+
"glom/test/test_check.py": {
|
| 42 |
+
"bytes": 3539,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "0c1b41b64de13ee16b508439b1f5a8fe994e10d9ccc6d64ba6a81fea67ee5fe6"
|
| 45 |
+
},
|
| 46 |
+
"glom/test/test_cli.py": {
|
| 47 |
+
"bytes": 6191,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "457d77b17aadb5b1ed0aa44cec6a3936a8703b47ddb07d4c0e0949859bc442de"
|
| 50 |
+
},
|
| 51 |
+
"glom/test/test_error.py": {
|
| 52 |
+
"bytes": 17299,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "8342c238c3e24925f90e9cd5619353cadccff708b1abe5892582ec8ece168d21"
|
| 55 |
+
},
|
| 56 |
+
"glom/test/test_fill.py": {
|
| 57 |
+
"bytes": 708,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "bba9a52291035bec99fb89969f9b2a50641ded20efdcdb3252ebf547f08ae61f"
|
| 60 |
+
},
|
| 61 |
+
"glom/test/test_grouping.py": {
|
| 62 |
+
"bytes": 3261,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "5cfd0f1f8be4ab7e833463475f6a74ac20e486a769421f5d678612dfc79df15b"
|
| 65 |
+
},
|
| 66 |
+
"glom/test/test_match.py": {
|
| 67 |
+
"bytes": 15407,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "43848620cde516f267baff40fc8f7a32e7701a0cb56c9e020114c88d4805650b"
|
| 70 |
+
},
|
| 71 |
+
"glom/test/test_mutation.py": {
|
| 72 |
+
"bytes": 9793,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "01f869a7165704d71985cda35cff5f50b45c51874a747a414cd11bf45d2fd89a"
|
| 75 |
+
},
|
| 76 |
+
"glom/test/test_path_and_t.py": {
|
| 77 |
+
"bytes": 10105,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "0138a53ea1db7faa8db879f590675c02189e8dd7a976af3122f4e8d14f206720"
|
| 80 |
+
},
|
| 81 |
+
"glom/test/test_reduction.py": {
|
| 82 |
+
"bytes": 4159,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "374466255beea308e8b9429eb7fe4ec77046e1aa3234967c57d9be7f9fbf8064"
|
| 85 |
+
},
|
| 86 |
+
"glom/test/test_scope_vars.py": {
|
| 87 |
+
"bytes": 3400,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "71639cf6909c359a16399015a963b1ea21d1b166982836e0203417f1e9cd1c18"
|
| 90 |
+
},
|
| 91 |
+
"glom/test/test_snippets.py": {
|
| 92 |
+
"bytes": 1478,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "14f42ea07f26b7ba4edc8b9a1b4d85f4975a948fed7afea634bf25f73da2136c"
|
| 95 |
+
},
|
| 96 |
+
"glom/test/test_spec.py": {
|
| 97 |
+
"bytes": 745,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "ef3d891517b4ebe35d8cdaad8b6778775a5260cf40697defc2c50981ff6fbe84"
|
| 100 |
+
},
|
| 101 |
+
"glom/test/test_streaming.py": {
|
| 102 |
+
"bytes": 5664,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "79fb6c7dcce0f50855df62c115822bfffaf1271b6131fdcff7fdd623e4189617"
|
| 105 |
+
},
|
| 106 |
+
"glom/test/test_target_types.py": {
|
| 107 |
+
"bytes": 7621,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "6605a6370d3eab24f7b3fa810aa0525417d0396bcba3ff1d31aedc46b60b58da"
|
| 110 |
+
},
|
| 111 |
+
"glom/test/test_tutorial.py": {
|
| 112 |
+
"bytes": 463,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "0790d2b2dbbadcbc06fa6b9467808f70568743f9d257c0313b7e2e974707e53f"
|
| 115 |
+
},
|
| 116 |
+
"pytest.ini": {
|
| 117 |
+
"bytes": 83,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "a08166d39b849cfb09dbe12650ad9947271eaa18962b08d161abc5fbd37fcb26"
|
| 120 |
+
},
|
| 121 |
+
"setup.py": {
|
| 122 |
+
"bytes": 2793,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "bf3f70521bcc74c8c85c05e65e7655a34629b767a50984985d50320d8fa547f2"
|
| 125 |
+
},
|
| 126 |
+
"tox.ini": {
|
| 127 |
+
"bytes": 977,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "18f0932ef1cf1fa9db666fde1c40ef730ed1408dd2b9ea9e17f8b392f6523747"
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/tests/trusted/tox.ini
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tox]
|
| 2 |
+
envlist = py37,py38,py39,py310,py311,py312,pypy3,coverage-report,packaging
|
| 3 |
+
|
| 4 |
+
[testenv]
|
| 5 |
+
changedir = .tox
|
| 6 |
+
deps = -rrequirements.txt
|
| 7 |
+
commands = coverage run --parallel --rcfile {toxinidir}/.tox-coveragerc -m pytest -vv --doctest-modules {envsitepackagesdir}/glom {posargs}
|
| 8 |
+
|
| 9 |
+
[testenv:coverage-report]
|
| 10 |
+
changedir = .tox
|
| 11 |
+
deps = coverage
|
| 12 |
+
commands = coverage combine --rcfile {toxinidir}/.tox-coveragerc
|
| 13 |
+
coverage xml --rcfile {toxinidir}/.tox-coveragerc
|
| 14 |
+
coverage report --rcfile {toxinidir}/.tox-coveragerc
|
| 15 |
+
coverage html --rcfile {toxinidir}/.tox-coveragerc -d {toxinidir}/htmlcov
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
[testenv:packaging]
|
| 19 |
+
changedir = {toxinidir}
|
| 20 |
+
deps =
|
| 21 |
+
check-manifest==0.50
|
| 22 |
+
commands =
|
| 23 |
+
check-manifest
|
| 24 |
+
|
| 25 |
+
[testenv:syntax-upgrade]
|
| 26 |
+
changedir = {toxinidir}
|
| 27 |
+
deps =
|
| 28 |
+
flynt
|
| 29 |
+
pyupgrade
|
| 30 |
+
commands =
|
| 31 |
+
flynt ./glom
|
| 32 |
+
python -c "import glob; import subprocess; [subprocess.run(['pyupgrade', '--py37-plus', f]) for f in glob.glob('./glom/**/*.py', recursive=True)]"
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/canaries/first-hunk-only.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_PARTIAL'
|
| 5 |
+
diff --git a/glom/matching.py b/glom/matching.py
|
| 6 |
+
index c17e17ef59dcc90ffbe190c658a50dccb2fafceb..798ac402c07ccc59280e61e002a4f28069e0748a 100644
|
| 7 |
+
--- a/glom/matching.py
|
| 8 |
+
+++ b/glom/matching.py
|
| 9 |
+
@@ -289,11 +289,12 @@
|
| 10 |
+
|
| 11 |
+
def _m_repr(self):
|
| 12 |
+
"""should this Or() repr as M |?"""
|
| 13 |
+
- if isinstance(self.children[-1], (_MType, _MExpr)):
|
| 14 |
+
- return False
|
| 15 |
+
- if type(self.children[0]) in (And, Or):
|
| 16 |
+
- return not self.children[0]._m_repr()
|
| 17 |
+
- return True
|
| 18 |
+
+ # only used by And() and Or(), not Not(), so len(children) >= 1
|
| 19 |
+
+ if isinstance(self.children[0], (_MType, _MExpr)):
|
| 20 |
+
+ return True
|
| 21 |
+
+ if type(self.children[0]) in (And, Or, Not):
|
| 22 |
+
+ return self.children[0]._m_repr()
|
| 23 |
+
+ return False
|
| 24 |
+
|
| 25 |
+
def __repr__(self):
|
| 26 |
+
child_reprs = [_bool_child_repr(c) for c in self.children]
|
| 27 |
+
OPENENV_PARTIAL
|
| 28 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/canaries/original-bug.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
:
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g15o8zw3/validation/openenv.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canaries": "validation/canaries",
|
| 3 |
+
"profile": "harbor-semantic-v1",
|
| 4 |
+
"requires_credentials": false,
|
| 5 |
+
"resources": {
|
| 6 |
+
"cpu": 2,
|
| 7 |
+
"disk_mb": 16384,
|
| 8 |
+
"episode_timeout_s": 1800,
|
| 9 |
+
"memory_mb": 8192
|
| 10 |
+
},
|
| 11 |
+
"reward": {
|
| 12 |
+
"floor_margin": 0.1,
|
| 13 |
+
"oracle_tolerance": 0,
|
| 14 |
+
"range": [
|
| 15 |
+
0,
|
| 16 |
+
1
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
"reward_key": "reward",
|
| 20 |
+
"types": {
|
| 21 |
+
"tags": [
|
| 22 |
+
"swe",
|
| 23 |
+
"python",
|
| 24 |
+
"mutation-repair"
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/LICENSE.source
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018, Mahmoud Hashemi
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are
|
| 7 |
+
met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above
|
| 13 |
+
copyright notice, this list of conditions and the following
|
| 14 |
+
disclaimer in the documentation and/or other materials provided
|
| 15 |
+
with the distribution.
|
| 16 |
+
|
| 17 |
+
* The names of the contributors may not be used to endorse or
|
| 18 |
+
promote products derived from this software without specific
|
| 19 |
+
prior written permission.
|
| 20 |
+
|
| 21 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 22 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 23 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 24 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 25 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 26 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 27 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 28 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 29 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/adapter.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"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.",
|
| 3 |
+
"collector_sha256": "352e555112f2de8a1393f939903e4971c9ace0e944843762b707a725c5c72481",
|
| 4 |
+
"dependency_installation_pinned": false,
|
| 5 |
+
"dependency_setup_sha256": "9ddda27f6e3f1110fe05ebb169af5f430f596cda7379dc183f692dd46ea16655",
|
| 6 |
+
"gold_patch_sha256": "9ff14f95989f0a8eca943e81abf51af08833ee4f8d264e57975bf96987079c55",
|
| 7 |
+
"hostile_code_isolation_established": false,
|
| 8 |
+
"known_wrong_semantic_implementations": 0,
|
| 9 |
+
"native_inventory_sha256": "abb26bf0b248738b459150e7a02eb2d0502a37fe8897c05888f6e3fc0b6c6b7c",
|
| 10 |
+
"new_files_deletions_and_executable_modes_supported": true,
|
| 11 |
+
"official_profile": {
|
| 12 |
+
"eval_sets": [],
|
| 13 |
+
"profile_class": "GlomFb3c4e76",
|
| 14 |
+
"profile_lines": [
|
| 15 |
+
411,
|
| 16 |
+
414
|
| 17 |
+
],
|
| 18 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 19 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 20 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 21 |
+
"upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 22 |
+
"upstream_repo": "mahmoud/glom"
|
| 23 |
+
},
|
| 24 |
+
"original_bug_canary_nop_equivalent": true,
|
| 25 |
+
"original_bug_runtime_wrongness_established": false,
|
| 26 |
+
"partial_repair_canary": true,
|
| 27 |
+
"partial_repair_sha256": "bc90d5e80a4f677fafc30466d7b6331afb8c0437febeca41dac8483d991ff052",
|
| 28 |
+
"partial_repair_wrongness_established": false,
|
| 29 |
+
"provided_original_bug_control": true,
|
| 30 |
+
"repo_url": "https://github.com/swesmith/mahmoud__glom.fb3c4e76.git",
|
| 31 |
+
"runtime_image": null,
|
| 32 |
+
"runtime_ready": false,
|
| 33 |
+
"runtime_recipe": {
|
| 34 |
+
"dependency_installation_pinned": false,
|
| 35 |
+
"official_install_cmds": [
|
| 36 |
+
"python -m pip install -e ."
|
| 37 |
+
],
|
| 38 |
+
"official_pytest_argv": [
|
| 39 |
+
"pytest",
|
| 40 |
+
"--disable-warnings",
|
| 41 |
+
"--color=no",
|
| 42 |
+
"--tb=no",
|
| 43 |
+
"--verbose"
|
| 44 |
+
],
|
| 45 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 46 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 47 |
+
"python_version": "3.10",
|
| 48 |
+
"source_bound_test_dependency_cmds": [
|
| 49 |
+
"python -m pip install -r requirements.txt"
|
| 50 |
+
],
|
| 51 |
+
"test_dependency_source_sha256": {
|
| 52 |
+
"requirements.txt": "16d7397649f1e969ac936db498607f1d0793d26b5880e44053c5b804af0ebb27",
|
| 53 |
+
"tox.ini": "18f0932ef1cf1fa9db666fde1c40ef730ed1408dd2b9ea9e17f8b392f6523747"
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"runtime_resource_review_required": false,
|
| 57 |
+
"schema": "python-git-patch-jobs-v1",
|
| 58 |
+
"source_base_commit": "3e0e83c7d368693161b24324f178a71a5b30cd44",
|
| 59 |
+
"source_completion_sha256": "f8e68a0abdcf1982fed4b531b37e426130a0b0cabe5e45e56a2cc2ba3e54594d",
|
| 60 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 61 |
+
"source_pr_url": null,
|
| 62 |
+
"source_record": {
|
| 63 |
+
"anti_training_canary": false,
|
| 64 |
+
"anti_training_reviewed": true,
|
| 65 |
+
"candidate_id": "swesmith-py:mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 66 |
+
"cloud_launch_ready": false,
|
| 67 |
+
"eligibility": {
|
| 68 |
+
"reasons": [],
|
| 69 |
+
"semantic_nonoverlap_established": false,
|
| 70 |
+
"status": "eligible_for_controls",
|
| 71 |
+
"training_admissible": false,
|
| 72 |
+
"warnings": []
|
| 73 |
+
},
|
| 74 |
+
"healthy_mirror_commit": "cefbc05bb4890356f3782b5ae0b33aef27a47536",
|
| 75 |
+
"instruction_sha256": "425be46479397164b8ed15d89fba680aec63e7854af2ac8429f9d4304e208bca",
|
| 76 |
+
"is_fork": true,
|
| 77 |
+
"learner_path": "tasks/9189a3f3c7da6afadbaafbc4/learner",
|
| 78 |
+
"license_evidence": {
|
| 79 |
+
"source_code": {
|
| 80 |
+
"actual_upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 81 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/mahmoud/glom/fb3c4e76f28816aebfd2538980e617742e98a7c2/LICENSE",
|
| 82 |
+
"reviewed": true,
|
| 83 |
+
"sha256": "ba81ea9a55099a9c4491141f9aace8ffd1f169701815582d7a80ed57f7b625d5",
|
| 84 |
+
"spdx": "BSD-2-Clause",
|
| 85 |
+
"training_allowed": true,
|
| 86 |
+
"url": "https://raw.githubusercontent.com/swesmith/mahmoud__glom.fb3c4e76/3e0e83c7d368693161b24324f178a71a5b30cd44/LICENSE"
|
| 87 |
+
},
|
| 88 |
+
"task_bundle": {
|
| 89 |
+
"reviewed": true,
|
| 90 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 91 |
+
"spdx": "MIT",
|
| 92 |
+
"training_allowed": true,
|
| 93 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 94 |
+
}
|
| 95 |
+
},
|
| 96 |
+
"original_source_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 97 |
+
"patch_sha256": "0216e71547675fadb76f9b30a868c38b21d2b9461515313bf1ea40151c648d85",
|
| 98 |
+
"provenance_path": "tasks/9189a3f3c7da6afadbaafbc4/source-proof.json",
|
| 99 |
+
"repository_lineage": [
|
| 100 |
+
"swesmith/mahmoud__glom.fb3c4e76",
|
| 101 |
+
"mahmoud/glom"
|
| 102 |
+
],
|
| 103 |
+
"rfc008_complete": false,
|
| 104 |
+
"runtime_qualified": false,
|
| 105 |
+
"semantic_nonoverlap_established": false,
|
| 106 |
+
"source_commit": "3e0e83c7d368693161b24324f178a71a5b30cd44",
|
| 107 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 108 |
+
"source_head_commit": "718a57998c6a1a55e9d20b1c1ade76b96f2c632e",
|
| 109 |
+
"source_kind": "mutation",
|
| 110 |
+
"source_repo": "swesmith/mahmoud__glom.fb3c4e76",
|
| 111 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 112 |
+
"source_split": "train",
|
| 113 |
+
"target_model_calibrated": false,
|
| 114 |
+
"task_id": "mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 115 |
+
"task_sha256": "5b8a5baf1c44a3f0ca8d681d32b88ea541e6404124fe3d970599cc39926cdd7b",
|
| 116 |
+
"training_admissible": false,
|
| 117 |
+
"upstream_identity_reviewed": true,
|
| 118 |
+
"upstream_repo": "mahmoud/glom",
|
| 119 |
+
"usage": "quarantine_only"
|
| 120 |
+
},
|
| 121 |
+
"source_repo": "swesmith/mahmoud__glom.fb3c4e76",
|
| 122 |
+
"symlink_submodule_changes_supported": false,
|
| 123 |
+
"task_id": "mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 124 |
+
"transfer": "index-independent-worktree-to-Git-binary-patch",
|
| 125 |
+
"transfer_path": "/testbed/submission.patch",
|
| 126 |
+
"upstream_repo": "mahmoud/glom"
|
| 127 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/dependency-setup.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
python -c 'import sys; assert sys.version_info[:2] == (3, 10)'
|
| 7 |
+
python -m pip install -e .
|
| 8 |
+
python -m pip install -r requirements.txt
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Runtime is selected only by an independently qualified immutable amd64 receipt.
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
+
RUN false
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/instruction.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Max and Min aggregation functions not working correctly
|
| 2 |
+
|
| 3 |
+
I found an issue with the Max and Min aggregation functions in glom. They seem to be returning incorrect values.
|
| 4 |
+
|
| 5 |
+
```python
|
| 6 |
+
>>> from glom import glom, Group, Max, Min
|
| 7 |
+
>>> glom([0, 1, 0], Group(Max()))
|
| 8 |
+
-1 # Should be 1
|
| 9 |
+
>>> glom([1, 0, 1], Group(Min()))
|
| 10 |
+
1 # Should be 0
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
The Max function seems to be returning a value that's one less than the actual maximum, and the Min function isn't returning the minimum value at all.
|
| 14 |
+
|
| 15 |
+
Here's a simple reproduction script:
|
| 16 |
+
|
| 17 |
+
```python
|
| 18 |
+
from glom import glom, Group, Max, Min
|
| 19 |
+
|
| 20 |
+
# Test Max
|
| 21 |
+
data = [0, 1, 0]
|
| 22 |
+
result = glom(data, Group(Max()))
|
| 23 |
+
print(f"Max of {data}: {result}") # Prints -1 instead of 1
|
| 24 |
+
|
| 25 |
+
# Test Min
|
| 26 |
+
data = [1, 0, 1]
|
| 27 |
+
result = glom(data, Group(Min()))
|
| 28 |
+
print(f"Min of {data}: {result}") # Prints 1 instead of 0
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
This is breaking any code that relies on these aggregation functions to return the actual maximum and minimum values.
|
| 32 |
+
|
| 33 |
+
## Environment
|
| 34 |
+
|
| 35 |
+
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.
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/metadata.json
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"all_runtime_and_training_flags": false,
|
| 3 |
+
"official_profile": {
|
| 4 |
+
"eval_sets": [],
|
| 5 |
+
"profile_class": "GlomFb3c4e76",
|
| 6 |
+
"profile_lines": [
|
| 7 |
+
411,
|
| 8 |
+
414
|
| 9 |
+
],
|
| 10 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 11 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 12 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 13 |
+
"upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 14 |
+
"upstream_repo": "mahmoud/glom"
|
| 15 |
+
},
|
| 16 |
+
"source_healthy_reference_proof": {
|
| 17 |
+
"FAIL_TO_PASS": [
|
| 18 |
+
"glom/test/test_grouping.py::test_agg",
|
| 19 |
+
"glom/test/test_grouping.py::test_limit"
|
| 20 |
+
],
|
| 21 |
+
"PASS_TO_PASS": [
|
| 22 |
+
"glom/test/test_basic.py::test_initial_integration",
|
| 23 |
+
"glom/test/test_basic.py::test_list_item_lift_and_access",
|
| 24 |
+
"glom/test/test_basic.py::test_coalesce",
|
| 25 |
+
"glom/test/test_basic.py::test_skip",
|
| 26 |
+
"glom/test/test_basic.py::test_stop",
|
| 27 |
+
"glom/test/test_basic.py::test_top_level_default",
|
| 28 |
+
"glom/test/test_basic.py::test_val",
|
| 29 |
+
"glom/test/test_basic.py::test_abstract_iterable",
|
| 30 |
+
"glom/test/test_basic.py::test_call_and_target",
|
| 31 |
+
"glom/test/test_basic.py::test_invoke",
|
| 32 |
+
"glom/test/test_basic.py::test_spec_and_recursion",
|
| 33 |
+
"glom/test/test_basic.py::test_scope",
|
| 34 |
+
"glom/test/test_basic.py::test_seq_getitem",
|
| 35 |
+
"glom/test/test_basic.py::test_beyond_access",
|
| 36 |
+
"glom/test/test_basic.py::test_python_native",
|
| 37 |
+
"glom/test/test_basic.py::test_glom_extra_kwargs",
|
| 38 |
+
"glom/test/test_basic.py::test_inspect",
|
| 39 |
+
"glom/test/test_basic.py::test_ref",
|
| 40 |
+
"glom/test/test_basic.py::test_pipe",
|
| 41 |
+
"glom/test/test_basic.py::test_api_repr",
|
| 42 |
+
"glom/test/test_basic.py::test_bbformat",
|
| 43 |
+
"glom/test/test_basic.py::test_bbrepr",
|
| 44 |
+
"glom/test/test_check.py::test_check_basic",
|
| 45 |
+
"glom/test/test_check.py::test_check_multi",
|
| 46 |
+
"glom/test/test_check.py::test_check_signature",
|
| 47 |
+
"glom/test/test_cli.py::test_cli_blank",
|
| 48 |
+
"glom/test/test_cli.py::test_cli_spec_target_argv_basic",
|
| 49 |
+
"glom/test/test_cli.py::test_cli_spec_argv_target_stdin_basic",
|
| 50 |
+
"glom/test/test_cli.py::test_cli_scalar",
|
| 51 |
+
"glom/test/test_cli.py::test_cli_spec_target_files_basic",
|
| 52 |
+
"glom/test/test_cli.py::test_usage_errors",
|
| 53 |
+
"glom/test/test_cli.py::test_main_basic",
|
| 54 |
+
"glom/test/test_cli.py::test_main_yaml_target",
|
| 55 |
+
"glom/test/test_cli.py::test_main_toml_target",
|
| 56 |
+
"glom/test/test_cli.py::test_main_python_full_spec_python_target",
|
| 57 |
+
"glom/test/test_cli.py::test_main",
|
| 58 |
+
"glom/test/test_error.py::test_good_error",
|
| 59 |
+
"glom/test/test_error.py::test_error",
|
| 60 |
+
"glom/test/test_error.py::test_pae_api",
|
| 61 |
+
"glom/test/test_error.py::test_unfinalized_glomerror_repr",
|
| 62 |
+
"glom/test/test_error.py::test_line_trace",
|
| 63 |
+
"glom/test/test_error.py::test_regular_error_stack",
|
| 64 |
+
"glom/test/test_error.py::test_glom_error_stack",
|
| 65 |
+
"glom/test/test_error.py::test_glom_error_double_stack",
|
| 66 |
+
"glom/test/test_error.py::test_long_target_repr",
|
| 67 |
+
"glom/test/test_error.py::test_branching_stack",
|
| 68 |
+
"glom/test/test_error.py::test_midway_branch",
|
| 69 |
+
"glom/test/test_error.py::test_partially_failing_branch",
|
| 70 |
+
"glom/test/test_error.py::test_coalesce_stack",
|
| 71 |
+
"glom/test/test_error.py::test_nesting_stack",
|
| 72 |
+
"glom/test/test_error.py::test_error_types",
|
| 73 |
+
"glom/test/test_error.py::test_fallback",
|
| 74 |
+
"glom/test/test_error.py::test_all_public_errors",
|
| 75 |
+
"glom/test/test_error.py::test_glom_dev_debug",
|
| 76 |
+
"glom/test/test_error.py::test_unicode_stack",
|
| 77 |
+
"glom/test/test_error.py::test_3_11_byte_code_caret",
|
| 78 |
+
"glom/test/test_fill.py::test",
|
| 79 |
+
"glom/test/test_grouping.py::test_bucketing",
|
| 80 |
+
"glom/test/test_grouping.py::test_corner_cases",
|
| 81 |
+
"glom/test/test_grouping.py::test_reduce",
|
| 82 |
+
"glom/test/test_grouping.py::test_sample",
|
| 83 |
+
"glom/test/test_match.py::test_basic",
|
| 84 |
+
"glom/test/test_match.py::test_match_expressions",
|
| 85 |
+
"glom/test/test_match.py::test_defaults",
|
| 86 |
+
"glom/test/test_match.py::test_match_default",
|
| 87 |
+
"glom/test/test_match.py::test_double_wrapping",
|
| 88 |
+
"glom/test/test_match.py::test_sets",
|
| 89 |
+
"glom/test/test_match.py::test_m_call_match",
|
| 90 |
+
"glom/test/test_match.py::test_and_or_reduction",
|
| 91 |
+
"glom/test/test_match.py::test_precedence",
|
| 92 |
+
"glom/test/test_match.py::test_cruddy_json",
|
| 93 |
+
"glom/test/test_match.py::test_pattern_matching",
|
| 94 |
+
"glom/test/test_match.py::test_examples",
|
| 95 |
+
"glom/test/test_match.py::test_reprs",
|
| 96 |
+
"glom/test/test_match.py::test_shortcircuit",
|
| 97 |
+
"glom/test/test_match.py::test_sample",
|
| 98 |
+
"glom/test/test_match.py::test_regex",
|
| 99 |
+
"glom/test/test_match.py::test_ternary",
|
| 100 |
+
"glom/test/test_match.py::test_sky",
|
| 101 |
+
"glom/test/test_match.py::test_clamp",
|
| 102 |
+
"glom/test/test_match.py::test_json_ref",
|
| 103 |
+
"glom/test/test_match.py::test_nested_struct",
|
| 104 |
+
"glom/test/test_match.py::test_check_ported_tests",
|
| 105 |
+
"glom/test/test_match.py::test_switch",
|
| 106 |
+
"glom/test/test_match.py::test_nested_dict",
|
| 107 |
+
"glom/test/test_mutation.py::test_assign",
|
| 108 |
+
"glom/test/test_mutation.py::test_assign_recursive",
|
| 109 |
+
"glom/test/test_mutation.py::test_assign_spec_val",
|
| 110 |
+
"glom/test/test_mutation.py::test_unregistered_assign",
|
| 111 |
+
"glom/test/test_mutation.py::test_bad_assign_target",
|
| 112 |
+
"glom/test/test_mutation.py::test_sequence_assign",
|
| 113 |
+
"glom/test/test_mutation.py::test_invalid_assign_op_target",
|
| 114 |
+
"glom/test/test_mutation.py::test_assign_missing_signature",
|
| 115 |
+
"glom/test/test_mutation.py::test_assign_missing_dict",
|
| 116 |
+
"glom/test/test_mutation.py::test_assign_missing_object",
|
| 117 |
+
"glom/test/test_mutation.py::test_assign_missing_with_extant_keys",
|
| 118 |
+
"glom/test/test_mutation.py::test_assign_missing_unassignable",
|
| 119 |
+
"glom/test/test_mutation.py::test_s_assign",
|
| 120 |
+
"glom/test/test_mutation.py::test_delete",
|
| 121 |
+
"glom/test/test_mutation.py::test_unregistered_delete",
|
| 122 |
+
"glom/test/test_mutation.py::test_bad_delete_target",
|
| 123 |
+
"glom/test/test_mutation.py::test_sequence_delete",
|
| 124 |
+
"glom/test/test_mutation.py::test_invalid_delete_op_target",
|
| 125 |
+
"glom/test/test_mutation.py::test_delete_ignore_missing",
|
| 126 |
+
"glom/test/test_mutation.py::test_star_broadcast",
|
| 127 |
+
"glom/test/test_path_and_t.py::test_list_path_access",
|
| 128 |
+
"glom/test/test_path_and_t.py::test_path",
|
| 129 |
+
"glom/test/test_path_and_t.py::test_empty_path_access",
|
| 130 |
+
"glom/test/test_path_and_t.py::test_path_t_roundtrip",
|
| 131 |
+
"glom/test/test_path_and_t.py::test_path_access_error_message",
|
| 132 |
+
"glom/test/test_path_and_t.py::test_t_picklability",
|
| 133 |
+
"glom/test/test_path_and_t.py::test_t_subspec",
|
| 134 |
+
"glom/test/test_path_and_t.py::test_a_forbidden",
|
| 135 |
+
"glom/test/test_path_and_t.py::test_s_magic",
|
| 136 |
+
"glom/test/test_path_and_t.py::test_path_len",
|
| 137 |
+
"glom/test/test_path_and_t.py::test_path_getitem",
|
| 138 |
+
"glom/test/test_path_and_t.py::test_path_slices",
|
| 139 |
+
"glom/test/test_path_and_t.py::test_path_values",
|
| 140 |
+
"glom/test/test_path_and_t.py::test_path_items",
|
| 141 |
+
"glom/test/test_path_and_t.py::test_path_star",
|
| 142 |
+
"glom/test/test_path_and_t.py::test_star_broadcast",
|
| 143 |
+
"glom/test/test_path_and_t.py::test_star_warning",
|
| 144 |
+
"glom/test/test_path_and_t.py::test_path_eq",
|
| 145 |
+
"glom/test/test_path_and_t.py::test_path_eq_t",
|
| 146 |
+
"glom/test/test_path_and_t.py::test_startswith",
|
| 147 |
+
"glom/test/test_path_and_t.py::test_from_t_identity",
|
| 148 |
+
"glom/test/test_path_and_t.py::test_t_dict_key",
|
| 149 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic",
|
| 150 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic_reprs",
|
| 151 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic_errors",
|
| 152 |
+
"glom/test/test_path_and_t.py::test_t_dunders",
|
| 153 |
+
"glom/test/test_path_and_t.py::test_path_cache",
|
| 154 |
+
"glom/test/test_reduction.py::test_sum_integers",
|
| 155 |
+
"glom/test/test_reduction.py::test_sum_seqs",
|
| 156 |
+
"glom/test/test_reduction.py::test_fold",
|
| 157 |
+
"glom/test/test_reduction.py::test_fold_bad_iter",
|
| 158 |
+
"glom/test/test_reduction.py::test_flatten",
|
| 159 |
+
"glom/test/test_reduction.py::test_flatten_func",
|
| 160 |
+
"glom/test/test_reduction.py::test_merge",
|
| 161 |
+
"glom/test/test_reduction.py::test_merge_omd",
|
| 162 |
+
"glom/test/test_reduction.py::test_merge_func",
|
| 163 |
+
"glom/test/test_scope_vars.py::test_s_scope_assign",
|
| 164 |
+
"glom/test/test_scope_vars.py::test_globals",
|
| 165 |
+
"glom/test/test_scope_vars.py::test_vars",
|
| 166 |
+
"glom/test/test_scope_vars.py::test_scoped_vars",
|
| 167 |
+
"glom/test/test_scope_vars.py::test_max_skip",
|
| 168 |
+
"glom/test/test_scope_vars.py::test_let",
|
| 169 |
+
"glom/test/test_spec.py::test_spec",
|
| 170 |
+
"glom/test/test_spec.py::test_scope_spec",
|
| 171 |
+
"glom/test/test_streaming.py::test_iter",
|
| 172 |
+
"glom/test/test_streaming.py::test_filter",
|
| 173 |
+
"glom/test/test_streaming.py::test_map",
|
| 174 |
+
"glom/test/test_streaming.py::test_split_flatten",
|
| 175 |
+
"glom/test/test_streaming.py::test_chunked",
|
| 176 |
+
"glom/test/test_streaming.py::test_windowed",
|
| 177 |
+
"glom/test/test_streaming.py::test_unique",
|
| 178 |
+
"glom/test/test_streaming.py::test_slice",
|
| 179 |
+
"glom/test/test_streaming.py::test_while",
|
| 180 |
+
"glom/test/test_streaming.py::test_iter_composition",
|
| 181 |
+
"glom/test/test_streaming.py::test_faulty_iterate",
|
| 182 |
+
"glom/test/test_streaming.py::test_first",
|
| 183 |
+
"glom/test/test_streaming.py::test_all",
|
| 184 |
+
"glom/test/test_target_types.py::test_types_leave_one_out",
|
| 185 |
+
"glom/test/test_target_types.py::test_types_bare",
|
| 186 |
+
"glom/test/test_target_types.py::test_invalid_register",
|
| 187 |
+
"glom/test/test_target_types.py::test_exact_register",
|
| 188 |
+
"glom/test/test_target_types.py::test_duck_register",
|
| 189 |
+
"glom/test/test_target_types.py::test_bypass_getitem",
|
| 190 |
+
"glom/test/test_target_types.py::test_iter_set",
|
| 191 |
+
"glom/test/test_target_types.py::test_iter_str",
|
| 192 |
+
"glom/test/test_target_types.py::test_default_scope_register",
|
| 193 |
+
"glom/test/test_target_types.py::test_faulty_iterate",
|
| 194 |
+
"glom/test/test_target_types.py::test_faulty_op_registration",
|
| 195 |
+
"glom/test/test_target_types.py::test_reregister_type",
|
| 196 |
+
"glom/test/test_tutorial.py::test_tutorial_data",
|
| 197 |
+
"glom/test/test_tutorial.py::test_tutorial"
|
| 198 |
+
],
|
| 199 |
+
"all_git_blobs_modes_verified": true,
|
| 200 |
+
"cloud_launch_ready": false,
|
| 201 |
+
"commits": {
|
| 202 |
+
"bug": "718a57998c6a1a55e9d20b1c1ade76b96f2c632e",
|
| 203 |
+
"healthy": "cefbc05bb4890356f3782b5ae0b33aef27a47536",
|
| 204 |
+
"learner": "3e0e83c7d368693161b24324f178a71a5b30cd44"
|
| 205 |
+
},
|
| 206 |
+
"existing_squirrel_snapshot_reused": false,
|
| 207 |
+
"full_transfer_allowlist": [
|
| 208 |
+
"/testbed/.gitignore",
|
| 209 |
+
"/testbed/.readthedocs.yaml",
|
| 210 |
+
"/testbed/.tox-coveragerc",
|
| 211 |
+
"/testbed/CHANGELOG.md",
|
| 212 |
+
"/testbed/LICENSE",
|
| 213 |
+
"/testbed/MANIFEST.in",
|
| 214 |
+
"/testbed/README.md",
|
| 215 |
+
"/testbed/SECURITY.md",
|
| 216 |
+
"/testbed/docs/Makefile",
|
| 217 |
+
"/testbed/docs/_static/comet.png",
|
| 218 |
+
"/testbed/docs/_static/comet_multi.png",
|
| 219 |
+
"/testbed/docs/_templates/page.html",
|
| 220 |
+
"/testbed/docs/api.rst",
|
| 221 |
+
"/testbed/docs/by_analogy.rst",
|
| 222 |
+
"/testbed/docs/cli.rst",
|
| 223 |
+
"/testbed/docs/conf.py",
|
| 224 |
+
"/testbed/docs/custom_spec_types.rst",
|
| 225 |
+
"/testbed/docs/debugging.rst",
|
| 226 |
+
"/testbed/docs/faq.rst",
|
| 227 |
+
"/testbed/docs/grouping.rst",
|
| 228 |
+
"/testbed/docs/index.rst",
|
| 229 |
+
"/testbed/docs/make.bat",
|
| 230 |
+
"/testbed/docs/matching.rst",
|
| 231 |
+
"/testbed/docs/modes.rst",
|
| 232 |
+
"/testbed/docs/mutation.rst",
|
| 233 |
+
"/testbed/docs/outreach.md",
|
| 234 |
+
"/testbed/docs/requirements-rtd.txt",
|
| 235 |
+
"/testbed/docs/snippets.rst",
|
| 236 |
+
"/testbed/docs/streaming.rst",
|
| 237 |
+
"/testbed/docs/tutorial.rst",
|
| 238 |
+
"/testbed/glom/__init__.py",
|
| 239 |
+
"/testbed/glom/__main__.py",
|
| 240 |
+
"/testbed/glom/_version.py",
|
| 241 |
+
"/testbed/glom/cli.py",
|
| 242 |
+
"/testbed/glom/core.py",
|
| 243 |
+
"/testbed/glom/grouping.py",
|
| 244 |
+
"/testbed/glom/matching.py",
|
| 245 |
+
"/testbed/glom/mutation.py",
|
| 246 |
+
"/testbed/glom/reduction.py",
|
| 247 |
+
"/testbed/glom/streaming.py",
|
| 248 |
+
"/testbed/glom/test/__init__.py",
|
| 249 |
+
"/testbed/glom/test/data/test_invalid.toml",
|
| 250 |
+
"/testbed/glom/test/data/test_invalid.yaml",
|
| 251 |
+
"/testbed/glom/test/data/test_valid.toml",
|
| 252 |
+
"/testbed/glom/test/data/test_valid.yaml",
|
| 253 |
+
"/testbed/glom/test/perf_report.py",
|
| 254 |
+
"/testbed/glom/test/test_basic.py",
|
| 255 |
+
"/testbed/glom/test/test_check.py",
|
| 256 |
+
"/testbed/glom/test/test_cli.py",
|
| 257 |
+
"/testbed/glom/test/test_error.py",
|
| 258 |
+
"/testbed/glom/test/test_fill.py",
|
| 259 |
+
"/testbed/glom/test/test_match.py",
|
| 260 |
+
"/testbed/glom/test/test_mutation.py",
|
| 261 |
+
"/testbed/glom/test/test_path_and_t.py",
|
| 262 |
+
"/testbed/glom/test/test_reduction.py",
|
| 263 |
+
"/testbed/glom/test/test_scope_vars.py",
|
| 264 |
+
"/testbed/glom/test/test_snippets.py",
|
| 265 |
+
"/testbed/glom/test/test_spec.py",
|
| 266 |
+
"/testbed/glom/test/test_streaming.py",
|
| 267 |
+
"/testbed/glom/test/test_target_types.py",
|
| 268 |
+
"/testbed/glom/test/test_tutorial.py",
|
| 269 |
+
"/testbed/glom/tutorial.py",
|
| 270 |
+
"/testbed/pytest.ini",
|
| 271 |
+
"/testbed/requirements.in",
|
| 272 |
+
"/testbed/requirements.txt",
|
| 273 |
+
"/testbed/setup.py",
|
| 274 |
+
"/testbed/tox.ini"
|
| 275 |
+
],
|
| 276 |
+
"healthy_stage_meaning": "Direct parent of the mutation; no source or test execution has been performed",
|
| 277 |
+
"mutation_matches_dataset_and_git_blobs": true,
|
| 278 |
+
"official_profile": {
|
| 279 |
+
"eval_sets": [],
|
| 280 |
+
"profile_class": "GlomFb3c4e76",
|
| 281 |
+
"profile_lines": [
|
| 282 |
+
411,
|
| 283 |
+
414
|
| 284 |
+
],
|
| 285 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 286 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 287 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 288 |
+
"upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 289 |
+
"upstream_repo": "mahmoud/glom"
|
| 290 |
+
},
|
| 291 |
+
"original_source_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 292 |
+
"private_test_paths": [
|
| 293 |
+
"glom/test/test_grouping.py"
|
| 294 |
+
],
|
| 295 |
+
"private_tests_unchanged": true,
|
| 296 |
+
"profile_mapping_basis": "Explicit upstream repo and full commit fields parsed from pinned official Python profile AST, not basename inference",
|
| 297 |
+
"qwen_calibrated": false,
|
| 298 |
+
"runtime_qualified": false,
|
| 299 |
+
"source_paths": [
|
| 300 |
+
"glom/grouping.py"
|
| 301 |
+
],
|
| 302 |
+
"source_repo": "swesmith/mahmoud__glom.fb3c4e76",
|
| 303 |
+
"source_stages_bytes": 1424840,
|
| 304 |
+
"task_id": "mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 305 |
+
"transfer_limitation": "Existing regular files only; new arbitrary file additions need a qualified patch adapter",
|
| 306 |
+
"upstream_repo": "mahmoud/glom"
|
| 307 |
+
},
|
| 308 |
+
"source_record": {
|
| 309 |
+
"anti_training_canary": false,
|
| 310 |
+
"anti_training_reviewed": true,
|
| 311 |
+
"candidate_id": "swesmith-py:mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 312 |
+
"cloud_launch_ready": false,
|
| 313 |
+
"eligibility": {
|
| 314 |
+
"reasons": [],
|
| 315 |
+
"semantic_nonoverlap_established": false,
|
| 316 |
+
"status": "eligible_for_controls",
|
| 317 |
+
"training_admissible": false,
|
| 318 |
+
"warnings": []
|
| 319 |
+
},
|
| 320 |
+
"healthy_mirror_commit": "cefbc05bb4890356f3782b5ae0b33aef27a47536",
|
| 321 |
+
"instruction_sha256": "425be46479397164b8ed15d89fba680aec63e7854af2ac8429f9d4304e208bca",
|
| 322 |
+
"is_fork": true,
|
| 323 |
+
"learner_path": "tasks/9189a3f3c7da6afadbaafbc4/learner",
|
| 324 |
+
"license_evidence": {
|
| 325 |
+
"source_code": {
|
| 326 |
+
"actual_upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 327 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/mahmoud/glom/fb3c4e76f28816aebfd2538980e617742e98a7c2/LICENSE",
|
| 328 |
+
"reviewed": true,
|
| 329 |
+
"sha256": "ba81ea9a55099a9c4491141f9aace8ffd1f169701815582d7a80ed57f7b625d5",
|
| 330 |
+
"spdx": "BSD-2-Clause",
|
| 331 |
+
"training_allowed": true,
|
| 332 |
+
"url": "https://raw.githubusercontent.com/swesmith/mahmoud__glom.fb3c4e76/3e0e83c7d368693161b24324f178a71a5b30cd44/LICENSE"
|
| 333 |
+
},
|
| 334 |
+
"task_bundle": {
|
| 335 |
+
"reviewed": true,
|
| 336 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 337 |
+
"spdx": "MIT",
|
| 338 |
+
"training_allowed": true,
|
| 339 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 340 |
+
}
|
| 341 |
+
},
|
| 342 |
+
"original_source_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 343 |
+
"patch_sha256": "0216e71547675fadb76f9b30a868c38b21d2b9461515313bf1ea40151c648d85",
|
| 344 |
+
"provenance_path": "tasks/9189a3f3c7da6afadbaafbc4/source-proof.json",
|
| 345 |
+
"repository_lineage": [
|
| 346 |
+
"swesmith/mahmoud__glom.fb3c4e76",
|
| 347 |
+
"mahmoud/glom"
|
| 348 |
+
],
|
| 349 |
+
"rfc008_complete": false,
|
| 350 |
+
"runtime_qualified": false,
|
| 351 |
+
"semantic_nonoverlap_established": false,
|
| 352 |
+
"source_commit": "3e0e83c7d368693161b24324f178a71a5b30cd44",
|
| 353 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 354 |
+
"source_head_commit": "718a57998c6a1a55e9d20b1c1ade76b96f2c632e",
|
| 355 |
+
"source_kind": "mutation",
|
| 356 |
+
"source_repo": "swesmith/mahmoud__glom.fb3c4e76",
|
| 357 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 358 |
+
"source_split": "train",
|
| 359 |
+
"target_model_calibrated": false,
|
| 360 |
+
"task_id": "mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 361 |
+
"task_sha256": "5b8a5baf1c44a3f0ca8d681d32b88ea541e6404124fe3d970599cc39926cdd7b",
|
| 362 |
+
"training_admissible": false,
|
| 363 |
+
"upstream_identity_reviewed": true,
|
| 364 |
+
"upstream_repo": "mahmoud/glom",
|
| 365 |
+
"usage": "quarantine_only"
|
| 366 |
+
},
|
| 367 |
+
"task_kind": "original-source-mutation"
|
| 368 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/provenance.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"generated_reference": false,
|
| 3 |
+
"healthy_reference_delta_sha256": "9ff14f95989f0a8eca943e81abf51af08833ee4f8d264e57975bf96987079c55",
|
| 4 |
+
"native_pytest_ids_preserved": true,
|
| 5 |
+
"original_source_code_license": {
|
| 6 |
+
"actual_upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 7 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/mahmoud/glom/fb3c4e76f28816aebfd2538980e617742e98a7c2/LICENSE",
|
| 8 |
+
"reviewed": true,
|
| 9 |
+
"sha256": "ba81ea9a55099a9c4491141f9aace8ffd1f169701815582d7a80ed57f7b625d5",
|
| 10 |
+
"spdx": "BSD-2-Clause",
|
| 11 |
+
"training_allowed": true,
|
| 12 |
+
"url": "https://raw.githubusercontent.com/swesmith/mahmoud__glom.fb3c4e76/3e0e83c7d368693161b24324f178a71a5b30cd44/LICENSE"
|
| 13 |
+
},
|
| 14 |
+
"provided_reference": true,
|
| 15 |
+
"qwen_calibrated": false,
|
| 16 |
+
"runtime_qualified": false,
|
| 17 |
+
"source_completion_sha256": "f8e68a0abdcf1982fed4b531b37e426130a0b0cabe5e45e56a2cc2ba3e54594d",
|
| 18 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 19 |
+
"source_proof_sha256": "e38c96d5a3783843f4e5d189ce8d23be8d9a98acac76ffc60d7f218355490747",
|
| 20 |
+
"source_record": {
|
| 21 |
+
"anti_training_canary": false,
|
| 22 |
+
"anti_training_reviewed": true,
|
| 23 |
+
"candidate_id": "swesmith-py:mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 24 |
+
"cloud_launch_ready": false,
|
| 25 |
+
"eligibility": {
|
| 26 |
+
"reasons": [],
|
| 27 |
+
"semantic_nonoverlap_established": false,
|
| 28 |
+
"status": "eligible_for_controls",
|
| 29 |
+
"training_admissible": false,
|
| 30 |
+
"warnings": []
|
| 31 |
+
},
|
| 32 |
+
"healthy_mirror_commit": "cefbc05bb4890356f3782b5ae0b33aef27a47536",
|
| 33 |
+
"instruction_sha256": "425be46479397164b8ed15d89fba680aec63e7854af2ac8429f9d4304e208bca",
|
| 34 |
+
"is_fork": true,
|
| 35 |
+
"learner_path": "tasks/9189a3f3c7da6afadbaafbc4/learner",
|
| 36 |
+
"license_evidence": {
|
| 37 |
+
"source_code": {
|
| 38 |
+
"actual_upstream_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 39 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/mahmoud/glom/fb3c4e76f28816aebfd2538980e617742e98a7c2/LICENSE",
|
| 40 |
+
"reviewed": true,
|
| 41 |
+
"sha256": "ba81ea9a55099a9c4491141f9aace8ffd1f169701815582d7a80ed57f7b625d5",
|
| 42 |
+
"spdx": "BSD-2-Clause",
|
| 43 |
+
"training_allowed": true,
|
| 44 |
+
"url": "https://raw.githubusercontent.com/swesmith/mahmoud__glom.fb3c4e76/3e0e83c7d368693161b24324f178a71a5b30cd44/LICENSE"
|
| 45 |
+
},
|
| 46 |
+
"task_bundle": {
|
| 47 |
+
"reviewed": true,
|
| 48 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 49 |
+
"spdx": "MIT",
|
| 50 |
+
"training_allowed": true,
|
| 51 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"original_source_commit": "fb3c4e76f28816aebfd2538980e617742e98a7c2",
|
| 55 |
+
"patch_sha256": "0216e71547675fadb76f9b30a868c38b21d2b9461515313bf1ea40151c648d85",
|
| 56 |
+
"provenance_path": "tasks/9189a3f3c7da6afadbaafbc4/source-proof.json",
|
| 57 |
+
"repository_lineage": [
|
| 58 |
+
"swesmith/mahmoud__glom.fb3c4e76",
|
| 59 |
+
"mahmoud/glom"
|
| 60 |
+
],
|
| 61 |
+
"rfc008_complete": false,
|
| 62 |
+
"runtime_qualified": false,
|
| 63 |
+
"semantic_nonoverlap_established": false,
|
| 64 |
+
"source_commit": "3e0e83c7d368693161b24324f178a71a5b30cd44",
|
| 65 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 66 |
+
"source_head_commit": "718a57998c6a1a55e9d20b1c1ade76b96f2c632e",
|
| 67 |
+
"source_kind": "mutation",
|
| 68 |
+
"source_repo": "swesmith/mahmoud__glom.fb3c4e76",
|
| 69 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 70 |
+
"source_split": "train",
|
| 71 |
+
"target_model_calibrated": false,
|
| 72 |
+
"task_id": "mahmoud__glom.fb3c4e76.combine_file__g5ew8sro",
|
| 73 |
+
"task_sha256": "5b8a5baf1c44a3f0ca8d681d32b88ea541e6404124fe3d970599cc39926cdd7b",
|
| 74 |
+
"training_admissible": false,
|
| 75 |
+
"upstream_identity_reviewed": true,
|
| 76 |
+
"upstream_repo": "mahmoud/glom",
|
| 77 |
+
"usage": "quarantine_only"
|
| 78 |
+
},
|
| 79 |
+
"task_bundle_license": {
|
| 80 |
+
"reviewed": true,
|
| 81 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 82 |
+
"spdx": "MIT",
|
| 83 |
+
"training_allowed": true,
|
| 84 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 85 |
+
},
|
| 86 |
+
"training_admissible": false,
|
| 87 |
+
"trusted_tests_sha256": "f127918c1d9f14c9e2ca870c81e9f78fc07ca3c66c4f33dadc51eca2753c81f4"
|
| 88 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/provided-gold.diff
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/glom/grouping.py b/glom/grouping.py
|
| 2 |
+
index a2b07d664dd102c9b25f3942e1011becd7c0b582..122bd0863df47161b8eb663797705f4c3e00a4ab 100644
|
| 3 |
+
--- a/glom/grouping.py
|
| 4 |
+
+++ b/glom/grouping.py
|
| 5 |
+
@@ -209,8 +209,8 @@
|
| 6 |
+
__slots__ = ()
|
| 7 |
+
|
| 8 |
+
def agg(self, target, tree):
|
| 9 |
+
- if self not in tree or target < tree[self]:
|
| 10 |
+
- tree[self] = target - 1
|
| 11 |
+
+ if self not in tree or target > tree[self]:
|
| 12 |
+
+ tree[self] = target
|
| 13 |
+
return tree[self]
|
| 14 |
+
|
| 15 |
+
def __repr__(self):
|
| 16 |
+
@@ -228,9 +228,9 @@
|
| 17 |
+
__slots__ = ()
|
| 18 |
+
|
| 19 |
+
def agg(self, target, tree):
|
| 20 |
+
- if self not in tree or target <= tree[self]:
|
| 21 |
+
+ if self not in tree or target < tree[self]:
|
| 22 |
+
tree[self] = target
|
| 23 |
+
- return target
|
| 24 |
+
+ return tree[self]
|
| 25 |
+
|
| 26 |
+
def __repr__(self):
|
| 27 |
+
return '%s()' % self.__class__.__name__
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/solution/solve.sh
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_REFERENCE'
|
| 5 |
+
diff --git a/glom/grouping.py b/glom/grouping.py
|
| 6 |
+
index a2b07d664dd102c9b25f3942e1011becd7c0b582..122bd0863df47161b8eb663797705f4c3e00a4ab 100644
|
| 7 |
+
--- a/glom/grouping.py
|
| 8 |
+
+++ b/glom/grouping.py
|
| 9 |
+
@@ -209,8 +209,8 @@
|
| 10 |
+
__slots__ = ()
|
| 11 |
+
|
| 12 |
+
def agg(self, target, tree):
|
| 13 |
+
- if self not in tree or target < tree[self]:
|
| 14 |
+
- tree[self] = target - 1
|
| 15 |
+
+ if self not in tree or target > tree[self]:
|
| 16 |
+
+ tree[self] = target
|
| 17 |
+
return tree[self]
|
| 18 |
+
|
| 19 |
+
def __repr__(self):
|
| 20 |
+
@@ -228,9 +228,9 @@
|
| 21 |
+
__slots__ = ()
|
| 22 |
+
|
| 23 |
+
def agg(self, target, tree):
|
| 24 |
+
- if self not in tree or target <= tree[self]:
|
| 25 |
+
+ if self not in tree or target < tree[self]:
|
| 26 |
+
tree[self] = target
|
| 27 |
+
- return target
|
| 28 |
+
+ return tree[self]
|
| 29 |
+
|
| 30 |
+
def __repr__(self):
|
| 31 |
+
return '%s()' % self.__class__.__name__
|
| 32 |
+
OPENENV_REFERENCE
|
| 33 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/task.toml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[agent]
|
| 4 |
+
timeout_sec = 1800.0
|
| 5 |
+
|
| 6 |
+
[verifier]
|
| 7 |
+
timeout_sec = 900.0
|
| 8 |
+
|
| 9 |
+
[environment]
|
| 10 |
+
docker_image = "ghcr.io/younesbelkada/scale800@sha256:ae0d3787e6a25023a58c65371ed124b629126739712f46760068e5f80d38ba36"
|
| 11 |
+
build_timeout_sec = 600.0
|
| 12 |
+
cpus = 2
|
| 13 |
+
memory_mb = 8192
|
| 14 |
+
storage_mb = 16384
|
| 15 |
+
|
| 16 |
+
[metadata]
|
| 17 |
+
author_name = "SWE-smith source adapter"
|
| 18 |
+
category = "bugfix"
|
| 19 |
+
tags = ["swe", "python", "mutation-repair"]
|
| 20 |
+
|
| 21 |
+
[environment.env]
|
| 22 |
+
# The image's PATH with the testbed env first: the project and pytest are installed there, and the agent's
|
| 23 |
+
# non-interactive shells never run `conda activate`
|
| 24 |
+
PATH = "/opt/miniconda3/envs/testbed/bin:/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/check_pytest.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Distinguish real pytest failures from missing/setup/verifier evidence."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import xml.etree.ElementTree as ET
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def matches(case, target):
|
| 11 |
+
parts = target.split("::")
|
| 12 |
+
module = parts[0].removesuffix(".py").replace("/", ".")
|
| 13 |
+
classname = case.get("classname", "")
|
| 14 |
+
name = case.get("name", "")
|
| 15 |
+
if not (classname == module or classname.startswith(module + ".")):
|
| 16 |
+
return False
|
| 17 |
+
selector = parts[-1] if len(parts) > 1 else ""
|
| 18 |
+
classes = parts[1:-1]
|
| 19 |
+
if classes and classname != module + "." + ".".join(classes):
|
| 20 |
+
return False
|
| 21 |
+
return (
|
| 22 |
+
not selector
|
| 23 |
+
or name == selector
|
| 24 |
+
or ("[" not in selector and name.startswith(selector + "["))
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def assess(root, expected, native_exit):
|
| 29 |
+
all_cases = []
|
| 30 |
+
actual_failure = False
|
| 31 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 32 |
+
path = Path(root) / (group + ".xml")
|
| 33 |
+
if not path.exists():
|
| 34 |
+
if actual_failure:
|
| 35 |
+
continue
|
| 36 |
+
raise ValueError("Missing preceding pytest panel")
|
| 37 |
+
if actual_failure:
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"Pytest evidence continued after the native stop-on-failure"
|
| 40 |
+
)
|
| 41 |
+
raw = path.read_bytes()
|
| 42 |
+
if not 0 < len(raw) <= 4 * 1024**2 or re.search(
|
| 43 |
+
rb"<!\s*(?:DOCTYPE|ENTITY)", raw, re.I
|
| 44 |
+
):
|
| 45 |
+
raise ValueError("Unbounded or unsafe pytest XML")
|
| 46 |
+
tree = ET.fromstring(raw)
|
| 47 |
+
cases = list(tree.iter("testcase"))
|
| 48 |
+
if len(cases) > 20000:
|
| 49 |
+
raise ValueError("Too many pytest cases")
|
| 50 |
+
identities = [(c.get("classname"), c.get("name")) for c in cases]
|
| 51 |
+
if len(identities) != len(set(identities)):
|
| 52 |
+
raise ValueError("Duplicate pytest case evidence")
|
| 53 |
+
targets = expected[group]
|
| 54 |
+
if any(not any(matches(case, t) for t in targets) for case in cases):
|
| 55 |
+
raise ValueError("Unexpected pytest case")
|
| 56 |
+
all_cases.extend(cases)
|
| 57 |
+
failures = [c for c in cases if c.find("failure") is not None]
|
| 58 |
+
if any(
|
| 59 |
+
c.find("error") is not None or c.find("skipped") is not None for c in cases
|
| 60 |
+
):
|
| 61 |
+
raise ValueError("Pytest collection/error/skip is not a completed panel")
|
| 62 |
+
actual_failure = actual_failure or bool(failures)
|
| 63 |
+
if not failures and any(
|
| 64 |
+
not any(matches(case, t) for case in cases) for t in targets
|
| 65 |
+
):
|
| 66 |
+
raise ValueError("Declared pytest target never ran")
|
| 67 |
+
if actual_failure:
|
| 68 |
+
if native_exit == 0:
|
| 69 |
+
raise ValueError("Native verifier exit disagrees with pytest failure")
|
| 70 |
+
return {"reward": 0, "valid_test_failure": True, "cases": len(all_cases)}
|
| 71 |
+
if native_exit != 0:
|
| 72 |
+
raise ValueError("Setup or native verifier failed without a real test failure")
|
| 73 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 74 |
+
if not (Path(root) / (group + ".xml")).is_file():
|
| 75 |
+
raise ValueError("Missing completed pytest panel")
|
| 76 |
+
return {"reward": 1, "valid_test_failure": False, "cases": len(all_cases)}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
p = argparse.ArgumentParser()
|
| 81 |
+
p.add_argument("--root", required=True)
|
| 82 |
+
p.add_argument("--expected", required=True)
|
| 83 |
+
p.add_argument("--native-exit", type=int, required=True)
|
| 84 |
+
a = p.parse_args()
|
| 85 |
+
result = assess(a.root, json.loads(Path(a.expected).read_text()), a.native_exit)
|
| 86 |
+
reward = Path(a.root) / "reward.txt"
|
| 87 |
+
if reward.read_text().strip() != str(result["reward"]):
|
| 88 |
+
raise ValueError("Native raw reward disagrees with pytest evidence")
|
| 89 |
+
(Path(a.root) / "pytest-evidence.json").write_text(
|
| 90 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 91 |
+
)
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/expected-panels.json
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fail-to-pass": [
|
| 3 |
+
"glom/test/test_grouping.py::test_agg",
|
| 4 |
+
"glom/test/test_grouping.py::test_limit"
|
| 5 |
+
],
|
| 6 |
+
"pass-to-pass": [
|
| 7 |
+
"glom/test/test_basic.py::test_initial_integration",
|
| 8 |
+
"glom/test/test_basic.py::test_list_item_lift_and_access",
|
| 9 |
+
"glom/test/test_basic.py::test_coalesce",
|
| 10 |
+
"glom/test/test_basic.py::test_skip",
|
| 11 |
+
"glom/test/test_basic.py::test_stop",
|
| 12 |
+
"glom/test/test_basic.py::test_top_level_default",
|
| 13 |
+
"glom/test/test_basic.py::test_val",
|
| 14 |
+
"glom/test/test_basic.py::test_abstract_iterable",
|
| 15 |
+
"glom/test/test_basic.py::test_call_and_target",
|
| 16 |
+
"glom/test/test_basic.py::test_invoke",
|
| 17 |
+
"glom/test/test_basic.py::test_spec_and_recursion",
|
| 18 |
+
"glom/test/test_basic.py::test_scope",
|
| 19 |
+
"glom/test/test_basic.py::test_seq_getitem",
|
| 20 |
+
"glom/test/test_basic.py::test_beyond_access",
|
| 21 |
+
"glom/test/test_basic.py::test_python_native",
|
| 22 |
+
"glom/test/test_basic.py::test_glom_extra_kwargs",
|
| 23 |
+
"glom/test/test_basic.py::test_inspect",
|
| 24 |
+
"glom/test/test_basic.py::test_ref",
|
| 25 |
+
"glom/test/test_basic.py::test_pipe",
|
| 26 |
+
"glom/test/test_basic.py::test_api_repr",
|
| 27 |
+
"glom/test/test_basic.py::test_bbformat",
|
| 28 |
+
"glom/test/test_basic.py::test_bbrepr",
|
| 29 |
+
"glom/test/test_check.py::test_check_basic",
|
| 30 |
+
"glom/test/test_check.py::test_check_multi",
|
| 31 |
+
"glom/test/test_check.py::test_check_signature",
|
| 32 |
+
"glom/test/test_cli.py::test_cli_blank",
|
| 33 |
+
"glom/test/test_cli.py::test_cli_spec_target_argv_basic",
|
| 34 |
+
"glom/test/test_cli.py::test_cli_spec_argv_target_stdin_basic",
|
| 35 |
+
"glom/test/test_cli.py::test_cli_scalar",
|
| 36 |
+
"glom/test/test_cli.py::test_cli_spec_target_files_basic",
|
| 37 |
+
"glom/test/test_cli.py::test_usage_errors",
|
| 38 |
+
"glom/test/test_cli.py::test_main_basic",
|
| 39 |
+
"glom/test/test_cli.py::test_main_yaml_target",
|
| 40 |
+
"glom/test/test_cli.py::test_main_toml_target",
|
| 41 |
+
"glom/test/test_cli.py::test_main_python_full_spec_python_target",
|
| 42 |
+
"glom/test/test_cli.py::test_main",
|
| 43 |
+
"glom/test/test_error.py::test_good_error",
|
| 44 |
+
"glom/test/test_error.py::test_error",
|
| 45 |
+
"glom/test/test_error.py::test_pae_api",
|
| 46 |
+
"glom/test/test_error.py::test_unfinalized_glomerror_repr",
|
| 47 |
+
"glom/test/test_error.py::test_line_trace",
|
| 48 |
+
"glom/test/test_error.py::test_regular_error_stack",
|
| 49 |
+
"glom/test/test_error.py::test_glom_error_stack",
|
| 50 |
+
"glom/test/test_error.py::test_glom_error_double_stack",
|
| 51 |
+
"glom/test/test_error.py::test_long_target_repr",
|
| 52 |
+
"glom/test/test_error.py::test_branching_stack",
|
| 53 |
+
"glom/test/test_error.py::test_midway_branch",
|
| 54 |
+
"glom/test/test_error.py::test_partially_failing_branch",
|
| 55 |
+
"glom/test/test_error.py::test_coalesce_stack",
|
| 56 |
+
"glom/test/test_error.py::test_nesting_stack",
|
| 57 |
+
"glom/test/test_error.py::test_error_types",
|
| 58 |
+
"glom/test/test_error.py::test_fallback",
|
| 59 |
+
"glom/test/test_error.py::test_all_public_errors",
|
| 60 |
+
"glom/test/test_error.py::test_glom_dev_debug",
|
| 61 |
+
"glom/test/test_error.py::test_unicode_stack",
|
| 62 |
+
"glom/test/test_error.py::test_3_11_byte_code_caret",
|
| 63 |
+
"glom/test/test_fill.py::test",
|
| 64 |
+
"glom/test/test_grouping.py::test_bucketing",
|
| 65 |
+
"glom/test/test_grouping.py::test_corner_cases",
|
| 66 |
+
"glom/test/test_grouping.py::test_reduce",
|
| 67 |
+
"glom/test/test_grouping.py::test_sample",
|
| 68 |
+
"glom/test/test_match.py::test_basic",
|
| 69 |
+
"glom/test/test_match.py::test_match_expressions",
|
| 70 |
+
"glom/test/test_match.py::test_defaults",
|
| 71 |
+
"glom/test/test_match.py::test_match_default",
|
| 72 |
+
"glom/test/test_match.py::test_double_wrapping",
|
| 73 |
+
"glom/test/test_match.py::test_sets",
|
| 74 |
+
"glom/test/test_match.py::test_m_call_match",
|
| 75 |
+
"glom/test/test_match.py::test_and_or_reduction",
|
| 76 |
+
"glom/test/test_match.py::test_precedence",
|
| 77 |
+
"glom/test/test_match.py::test_cruddy_json",
|
| 78 |
+
"glom/test/test_match.py::test_pattern_matching",
|
| 79 |
+
"glom/test/test_match.py::test_examples",
|
| 80 |
+
"glom/test/test_match.py::test_reprs",
|
| 81 |
+
"glom/test/test_match.py::test_shortcircuit",
|
| 82 |
+
"glom/test/test_match.py::test_sample",
|
| 83 |
+
"glom/test/test_match.py::test_regex",
|
| 84 |
+
"glom/test/test_match.py::test_ternary",
|
| 85 |
+
"glom/test/test_match.py::test_sky",
|
| 86 |
+
"glom/test/test_match.py::test_clamp",
|
| 87 |
+
"glom/test/test_match.py::test_json_ref",
|
| 88 |
+
"glom/test/test_match.py::test_nested_struct",
|
| 89 |
+
"glom/test/test_match.py::test_check_ported_tests",
|
| 90 |
+
"glom/test/test_match.py::test_switch",
|
| 91 |
+
"glom/test/test_match.py::test_nested_dict",
|
| 92 |
+
"glom/test/test_mutation.py::test_assign",
|
| 93 |
+
"glom/test/test_mutation.py::test_assign_recursive",
|
| 94 |
+
"glom/test/test_mutation.py::test_assign_spec_val",
|
| 95 |
+
"glom/test/test_mutation.py::test_unregistered_assign",
|
| 96 |
+
"glom/test/test_mutation.py::test_bad_assign_target",
|
| 97 |
+
"glom/test/test_mutation.py::test_sequence_assign",
|
| 98 |
+
"glom/test/test_mutation.py::test_invalid_assign_op_target",
|
| 99 |
+
"glom/test/test_mutation.py::test_assign_missing_signature",
|
| 100 |
+
"glom/test/test_mutation.py::test_assign_missing_dict",
|
| 101 |
+
"glom/test/test_mutation.py::test_assign_missing_object",
|
| 102 |
+
"glom/test/test_mutation.py::test_assign_missing_with_extant_keys",
|
| 103 |
+
"glom/test/test_mutation.py::test_assign_missing_unassignable",
|
| 104 |
+
"glom/test/test_mutation.py::test_s_assign",
|
| 105 |
+
"glom/test/test_mutation.py::test_delete",
|
| 106 |
+
"glom/test/test_mutation.py::test_unregistered_delete",
|
| 107 |
+
"glom/test/test_mutation.py::test_bad_delete_target",
|
| 108 |
+
"glom/test/test_mutation.py::test_sequence_delete",
|
| 109 |
+
"glom/test/test_mutation.py::test_invalid_delete_op_target",
|
| 110 |
+
"glom/test/test_mutation.py::test_delete_ignore_missing",
|
| 111 |
+
"glom/test/test_mutation.py::test_star_broadcast",
|
| 112 |
+
"glom/test/test_path_and_t.py::test_list_path_access",
|
| 113 |
+
"glom/test/test_path_and_t.py::test_path",
|
| 114 |
+
"glom/test/test_path_and_t.py::test_empty_path_access",
|
| 115 |
+
"glom/test/test_path_and_t.py::test_path_t_roundtrip",
|
| 116 |
+
"glom/test/test_path_and_t.py::test_path_access_error_message",
|
| 117 |
+
"glom/test/test_path_and_t.py::test_t_picklability",
|
| 118 |
+
"glom/test/test_path_and_t.py::test_t_subspec",
|
| 119 |
+
"glom/test/test_path_and_t.py::test_a_forbidden",
|
| 120 |
+
"glom/test/test_path_and_t.py::test_s_magic",
|
| 121 |
+
"glom/test/test_path_and_t.py::test_path_len",
|
| 122 |
+
"glom/test/test_path_and_t.py::test_path_getitem",
|
| 123 |
+
"glom/test/test_path_and_t.py::test_path_slices",
|
| 124 |
+
"glom/test/test_path_and_t.py::test_path_values",
|
| 125 |
+
"glom/test/test_path_and_t.py::test_path_items",
|
| 126 |
+
"glom/test/test_path_and_t.py::test_path_star",
|
| 127 |
+
"glom/test/test_path_and_t.py::test_star_broadcast",
|
| 128 |
+
"glom/test/test_path_and_t.py::test_star_warning",
|
| 129 |
+
"glom/test/test_path_and_t.py::test_path_eq",
|
| 130 |
+
"glom/test/test_path_and_t.py::test_path_eq_t",
|
| 131 |
+
"glom/test/test_path_and_t.py::test_startswith",
|
| 132 |
+
"glom/test/test_path_and_t.py::test_from_t_identity",
|
| 133 |
+
"glom/test/test_path_and_t.py::test_t_dict_key",
|
| 134 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic",
|
| 135 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic_reprs",
|
| 136 |
+
"glom/test/test_path_and_t.py::test_t_arithmetic_errors",
|
| 137 |
+
"glom/test/test_path_and_t.py::test_t_dunders",
|
| 138 |
+
"glom/test/test_path_and_t.py::test_path_cache",
|
| 139 |
+
"glom/test/test_reduction.py::test_sum_integers",
|
| 140 |
+
"glom/test/test_reduction.py::test_sum_seqs",
|
| 141 |
+
"glom/test/test_reduction.py::test_fold",
|
| 142 |
+
"glom/test/test_reduction.py::test_fold_bad_iter",
|
| 143 |
+
"glom/test/test_reduction.py::test_flatten",
|
| 144 |
+
"glom/test/test_reduction.py::test_flatten_func",
|
| 145 |
+
"glom/test/test_reduction.py::test_merge",
|
| 146 |
+
"glom/test/test_reduction.py::test_merge_omd",
|
| 147 |
+
"glom/test/test_reduction.py::test_merge_func",
|
| 148 |
+
"glom/test/test_scope_vars.py::test_s_scope_assign",
|
| 149 |
+
"glom/test/test_scope_vars.py::test_globals",
|
| 150 |
+
"glom/test/test_scope_vars.py::test_vars",
|
| 151 |
+
"glom/test/test_scope_vars.py::test_scoped_vars",
|
| 152 |
+
"glom/test/test_scope_vars.py::test_max_skip",
|
| 153 |
+
"glom/test/test_scope_vars.py::test_let",
|
| 154 |
+
"glom/test/test_spec.py::test_spec",
|
| 155 |
+
"glom/test/test_spec.py::test_scope_spec",
|
| 156 |
+
"glom/test/test_streaming.py::test_iter",
|
| 157 |
+
"glom/test/test_streaming.py::test_filter",
|
| 158 |
+
"glom/test/test_streaming.py::test_map",
|
| 159 |
+
"glom/test/test_streaming.py::test_split_flatten",
|
| 160 |
+
"glom/test/test_streaming.py::test_chunked",
|
| 161 |
+
"glom/test/test_streaming.py::test_windowed",
|
| 162 |
+
"glom/test/test_streaming.py::test_unique",
|
| 163 |
+
"glom/test/test_streaming.py::test_slice",
|
| 164 |
+
"glom/test/test_streaming.py::test_while",
|
| 165 |
+
"glom/test/test_streaming.py::test_iter_composition",
|
| 166 |
+
"glom/test/test_streaming.py::test_faulty_iterate",
|
| 167 |
+
"glom/test/test_streaming.py::test_first",
|
| 168 |
+
"glom/test/test_streaming.py::test_all",
|
| 169 |
+
"glom/test/test_target_types.py::test_types_leave_one_out",
|
| 170 |
+
"glom/test/test_target_types.py::test_types_bare",
|
| 171 |
+
"glom/test/test_target_types.py::test_invalid_register",
|
| 172 |
+
"glom/test/test_target_types.py::test_exact_register",
|
| 173 |
+
"glom/test/test_target_types.py::test_duck_register",
|
| 174 |
+
"glom/test/test_target_types.py::test_bypass_getitem",
|
| 175 |
+
"glom/test/test_target_types.py::test_iter_set",
|
| 176 |
+
"glom/test/test_target_types.py::test_iter_str",
|
| 177 |
+
"glom/test/test_target_types.py::test_default_scope_register",
|
| 178 |
+
"glom/test/test_target_types.py::test_faulty_iterate",
|
| 179 |
+
"glom/test/test_target_types.py::test_faulty_op_registration",
|
| 180 |
+
"glom/test/test_target_types.py::test_reregister_type",
|
| 181 |
+
"glom/test/test_tutorial.py::test_tutorial_data",
|
| 182 |
+
"glom/test/test_tutorial.py::test_tutorial"
|
| 183 |
+
]
|
| 184 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/grade.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Trusted private pytest panel runner. Installed only in a fresh grader Job."""
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import stat
|
| 9 |
+
import subprocess
|
| 10 |
+
from pathlib import Path, PurePosixPath
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def sha(raw):
|
| 14 |
+
return hashlib.sha256(raw).hexdigest()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def safe(value):
|
| 18 |
+
path = PurePosixPath(value)
|
| 19 |
+
if (
|
| 20 |
+
path.is_absolute()
|
| 21 |
+
or path.as_posix() != value
|
| 22 |
+
or not path.parts
|
| 23 |
+
or any(part in {".", "..", ".git"} for part in path.parts)
|
| 24 |
+
):
|
| 25 |
+
raise ValueError("Unsafe trusted test path")
|
| 26 |
+
return path
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def restore(worktree, private, manifest):
|
| 30 |
+
worktree, private = Path(worktree), Path(private)
|
| 31 |
+
captured = {}
|
| 32 |
+
for name, expected in manifest["files"].items():
|
| 33 |
+
path = private / safe(name)
|
| 34 |
+
info = path.lstat()
|
| 35 |
+
raw = path.read_bytes() if stat.S_ISREG(info.st_mode) else b""
|
| 36 |
+
if (
|
| 37 |
+
not stat.S_ISREG(info.st_mode)
|
| 38 |
+
or len(raw) != expected["bytes"]
|
| 39 |
+
or sha(raw) != expected["sha256"]
|
| 40 |
+
or stat.S_IMODE(info.st_mode) != expected["mode"]
|
| 41 |
+
):
|
| 42 |
+
raise ValueError("Trusted private test bytes or modes drifted")
|
| 43 |
+
captured[name] = (raw, expected["mode"])
|
| 44 |
+
# Capture and verify every private byte before changing the submitted tree.
|
| 45 |
+
for name in manifest["directory_roots"]:
|
| 46 |
+
destination = worktree / safe(name)
|
| 47 |
+
if destination.is_symlink():
|
| 48 |
+
raise ValueError("Submitted test directory is a symlink")
|
| 49 |
+
for parent in destination.parents:
|
| 50 |
+
if parent == worktree:
|
| 51 |
+
break
|
| 52 |
+
if parent.is_symlink():
|
| 53 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 54 |
+
if destination.exists():
|
| 55 |
+
if not destination.is_dir():
|
| 56 |
+
raise ValueError("Submitted test directory is not a directory")
|
| 57 |
+
shutil.rmtree(destination)
|
| 58 |
+
for name, (raw, mode) in captured.items():
|
| 59 |
+
destination = worktree / safe(name)
|
| 60 |
+
for parent in destination.parents:
|
| 61 |
+
if parent == worktree:
|
| 62 |
+
break
|
| 63 |
+
if parent.is_symlink():
|
| 64 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 65 |
+
if destination.is_symlink():
|
| 66 |
+
raise ValueError("Submitted trusted file is a symlink")
|
| 67 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
destination.write_bytes(raw)
|
| 69 |
+
destination.chmod(mode)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def run(worktree, private_root, output, invoke=None):
|
| 73 |
+
private_root, output, worktree = Path(private_root), Path(output), Path(worktree)
|
| 74 |
+
expected = json.loads((private_root / "expected-panels.json").read_bytes())
|
| 75 |
+
config = json.loads((private_root / "panel-config.json").read_bytes())
|
| 76 |
+
manifest = json.loads((private_root / "trusted-inventory.json").read_bytes())
|
| 77 |
+
restore(worktree, private_root / "trusted", manifest)
|
| 78 |
+
output.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
for name in (
|
| 80 |
+
"reward.txt",
|
| 81 |
+
"pass-to-pass.xml",
|
| 82 |
+
"fail-to-pass.xml",
|
| 83 |
+
"pytest-evidence.json",
|
| 84 |
+
):
|
| 85 |
+
(output / name).unlink(missing_ok=True)
|
| 86 |
+
environment = dict(os.environ)
|
| 87 |
+
for key in ("PYTEST_ADDOPTS", "PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTHONPATH"):
|
| 88 |
+
environment.pop(key, None)
|
| 89 |
+
commands, native_exit = [], 0
|
| 90 |
+
invoke = invoke or subprocess.run
|
| 91 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 92 |
+
if (
|
| 93 |
+
not isinstance(expected[group], list)
|
| 94 |
+
or not expected[group]
|
| 95 |
+
or any(
|
| 96 |
+
not isinstance(target, str) or not target for target in expected[group]
|
| 97 |
+
)
|
| 98 |
+
):
|
| 99 |
+
raise ValueError("Frozen native pytest selectors are incomplete")
|
| 100 |
+
command = [
|
| 101 |
+
*config["official_pytest_argv"],
|
| 102 |
+
"--override-ini=addopts=",
|
| 103 |
+
"--junitxml=" + str(output / (group + ".xml")),
|
| 104 |
+
*expected[group],
|
| 105 |
+
]
|
| 106 |
+
result = invoke(command, cwd=worktree, env=environment, check=False)
|
| 107 |
+
native_exit = result.returncode
|
| 108 |
+
commands.append({"group": group, "argv": command, "exit_code": native_exit})
|
| 109 |
+
if native_exit != 0:
|
| 110 |
+
break
|
| 111 |
+
(output / "pytest-commands.json").write_text(
|
| 112 |
+
json.dumps(commands, sort_keys=True) + "\n"
|
| 113 |
+
)
|
| 114 |
+
spec = importlib.util.spec_from_file_location(
|
| 115 |
+
"trusted_pytest_result", private_root / "check_pytest.py"
|
| 116 |
+
)
|
| 117 |
+
checker = importlib.util.module_from_spec(spec)
|
| 118 |
+
spec.loader.exec_module(checker)
|
| 119 |
+
result = checker.assess(output, expected, native_exit)
|
| 120 |
+
(output / "reward.txt").write_text(str(result["reward"]) + "\n")
|
| 121 |
+
(output / "pytest-evidence.json").write_text(
|
| 122 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 123 |
+
)
|
| 124 |
+
return result
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
run("/testbed/repo", "/tests", "/logs/verifier")
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/panel-config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dependency_installation_pinned": false,
|
| 3 |
+
"official_install_cmds": [
|
| 4 |
+
"python -m pip install -e ."
|
| 5 |
+
],
|
| 6 |
+
"official_pytest_argv": [
|
| 7 |
+
"pytest",
|
| 8 |
+
"--disable-warnings",
|
| 9 |
+
"--color=no",
|
| 10 |
+
"--tb=no",
|
| 11 |
+
"--verbose"
|
| 12 |
+
],
|
| 13 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 14 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 15 |
+
"python_version": "3.10",
|
| 16 |
+
"source_bound_test_dependency_cmds": [
|
| 17 |
+
"python -m pip install -r requirements.txt"
|
| 18 |
+
],
|
| 19 |
+
"test_dependency_source_sha256": {
|
| 20 |
+
"requirements.txt": "16d7397649f1e969ac936db498607f1d0793d26b5880e44053c5b804af0ebb27",
|
| 21 |
+
"tox.ini": "18f0932ef1cf1fa9db666fde1c40ef730ed1408dd2b9ea9e17f8b392f6523747"
|
| 22 |
+
}
|
| 23 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/test.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
exec python -I /tests/grade.py
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"directory_roots": [
|
| 3 |
+
"glom/test"
|
| 4 |
+
],
|
| 5 |
+
"files": {
|
| 6 |
+
"glom/test/__init__.py": {
|
| 7 |
+
"bytes": 0,
|
| 8 |
+
"mode": 420,
|
| 9 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
| 10 |
+
},
|
| 11 |
+
"glom/test/data/test_invalid.toml": {
|
| 12 |
+
"bytes": 19,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "f59a1d038e1648113ad5f0452ea99b79fc29d1eac035959e95d1c27ff44dc144"
|
| 15 |
+
},
|
| 16 |
+
"glom/test/data/test_invalid.yaml": {
|
| 17 |
+
"bytes": 15,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "a5de9f6a4b0a10d16777fc47f58e96271303682d0c7fbd439a034d824e6f5b08"
|
| 20 |
+
},
|
| 21 |
+
"glom/test/data/test_valid.toml": {
|
| 22 |
+
"bytes": 18,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "a13bb47add7b013b3086e4530f1f8daf2149bc4c3ae97237ff84f95facf4f5c5"
|
| 25 |
+
},
|
| 26 |
+
"glom/test/data/test_valid.yaml": {
|
| 27 |
+
"bytes": 23,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "0d40245ac0403c81a09e8521140c9ef50da30d8031efc6aef25fcb44be24362a"
|
| 30 |
+
},
|
| 31 |
+
"glom/test/perf_report.py": {
|
| 32 |
+
"bytes": 1962,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "da3294405f48e1b4e46b133eb8abb514019b4cc46547bd12c7bea65ef56467ed"
|
| 35 |
+
},
|
| 36 |
+
"glom/test/test_basic.py": {
|
| 37 |
+
"bytes": 14233,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "364581bf0f191b243d73f0cf5558cc9152126fd83c7fca1d97f953bf5478fd85"
|
| 40 |
+
},
|
| 41 |
+
"glom/test/test_check.py": {
|
| 42 |
+
"bytes": 3539,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "0c1b41b64de13ee16b508439b1f5a8fe994e10d9ccc6d64ba6a81fea67ee5fe6"
|
| 45 |
+
},
|
| 46 |
+
"glom/test/test_cli.py": {
|
| 47 |
+
"bytes": 6191,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "457d77b17aadb5b1ed0aa44cec6a3936a8703b47ddb07d4c0e0949859bc442de"
|
| 50 |
+
},
|
| 51 |
+
"glom/test/test_error.py": {
|
| 52 |
+
"bytes": 17299,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "8342c238c3e24925f90e9cd5619353cadccff708b1abe5892582ec8ece168d21"
|
| 55 |
+
},
|
| 56 |
+
"glom/test/test_fill.py": {
|
| 57 |
+
"bytes": 708,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "bba9a52291035bec99fb89969f9b2a50641ded20efdcdb3252ebf547f08ae61f"
|
| 60 |
+
},
|
| 61 |
+
"glom/test/test_grouping.py": {
|
| 62 |
+
"bytes": 3261,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "5cfd0f1f8be4ab7e833463475f6a74ac20e486a769421f5d678612dfc79df15b"
|
| 65 |
+
},
|
| 66 |
+
"glom/test/test_match.py": {
|
| 67 |
+
"bytes": 15407,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "43848620cde516f267baff40fc8f7a32e7701a0cb56c9e020114c88d4805650b"
|
| 70 |
+
},
|
| 71 |
+
"glom/test/test_mutation.py": {
|
| 72 |
+
"bytes": 9793,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "01f869a7165704d71985cda35cff5f50b45c51874a747a414cd11bf45d2fd89a"
|
| 75 |
+
},
|
| 76 |
+
"glom/test/test_path_and_t.py": {
|
| 77 |
+
"bytes": 10105,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "0138a53ea1db7faa8db879f590675c02189e8dd7a976af3122f4e8d14f206720"
|
| 80 |
+
},
|
| 81 |
+
"glom/test/test_reduction.py": {
|
| 82 |
+
"bytes": 4159,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "374466255beea308e8b9429eb7fe4ec77046e1aa3234967c57d9be7f9fbf8064"
|
| 85 |
+
},
|
| 86 |
+
"glom/test/test_scope_vars.py": {
|
| 87 |
+
"bytes": 3400,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "71639cf6909c359a16399015a963b1ea21d1b166982836e0203417f1e9cd1c18"
|
| 90 |
+
},
|
| 91 |
+
"glom/test/test_snippets.py": {
|
| 92 |
+
"bytes": 1478,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "14f42ea07f26b7ba4edc8b9a1b4d85f4975a948fed7afea634bf25f73da2136c"
|
| 95 |
+
},
|
| 96 |
+
"glom/test/test_spec.py": {
|
| 97 |
+
"bytes": 745,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "ef3d891517b4ebe35d8cdaad8b6778775a5260cf40697defc2c50981ff6fbe84"
|
| 100 |
+
},
|
| 101 |
+
"glom/test/test_streaming.py": {
|
| 102 |
+
"bytes": 5664,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "79fb6c7dcce0f50855df62c115822bfffaf1271b6131fdcff7fdd623e4189617"
|
| 105 |
+
},
|
| 106 |
+
"glom/test/test_target_types.py": {
|
| 107 |
+
"bytes": 7621,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "6605a6370d3eab24f7b3fa810aa0525417d0396bcba3ff1d31aedc46b60b58da"
|
| 110 |
+
},
|
| 111 |
+
"glom/test/test_tutorial.py": {
|
| 112 |
+
"bytes": 463,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "0790d2b2dbbadcbc06fa6b9467808f70568743f9d257c0313b7e2e974707e53f"
|
| 115 |
+
},
|
| 116 |
+
"pytest.ini": {
|
| 117 |
+
"bytes": 83,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "a08166d39b849cfb09dbe12650ad9947271eaa18962b08d161abc5fbd37fcb26"
|
| 120 |
+
},
|
| 121 |
+
"setup.py": {
|
| 122 |
+
"bytes": 2793,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "bf3f70521bcc74c8c85c05e65e7655a34629b767a50984985d50320d8fa547f2"
|
| 125 |
+
},
|
| 126 |
+
"tox.ini": {
|
| 127 |
+
"bytes": 977,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "18f0932ef1cf1fa9db666fde1c40ef730ed1408dd2b9ea9e17f8b392f6523747"
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/__init__.py
ADDED
|
File without changes
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_invalid.toml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# invalid
|
| 2 |
+
toml = {
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_invalid.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- Invalid
|
| 2 |
+
Yaml:
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_valid.toml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Hello = ["World"]
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/data/test_valid.yaml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
Hello:
|
| 3 |
+
- World
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/perf_report.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
slow gloms that came up organically, used as performance metrics
|
| 3 |
+
"""
|
| 4 |
+
import time
|
| 5 |
+
import gc
|
| 6 |
+
|
| 7 |
+
import attr
|
| 8 |
+
|
| 9 |
+
from glom import glom, T
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
STR_SPEC = [{
|
| 14 |
+
'id': ('id', str),
|
| 15 |
+
'name': 'short_name',
|
| 16 |
+
'external_id': 'external_id',
|
| 17 |
+
'created_date': 'created_date',
|
| 18 |
+
}]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
T_SPEC = [{
|
| 22 |
+
'id': (T.id, str),
|
| 23 |
+
'name': T.short_name,
|
| 24 |
+
'external_id': T.external_id,
|
| 25 |
+
'created_date': T.created_date,
|
| 26 |
+
}]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def func(data):
|
| 30 |
+
return [{
|
| 31 |
+
'id': str(t.id),
|
| 32 |
+
'name': t.short_name,
|
| 33 |
+
'external_id': t.external_id,
|
| 34 |
+
'created_date': t.created_date
|
| 35 |
+
} for t in data]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def setup_list_of_dict(num=100):
|
| 39 |
+
"""
|
| 40 |
+
a common use case is list-of-dicts object processing
|
| 41 |
+
to prepare internal objects for JSON serialization
|
| 42 |
+
"""
|
| 43 |
+
Obj = attr.make_class(
|
| 44 |
+
'Obj', ['id', 'short_name', 'external_id', 'created_date'])
|
| 45 |
+
|
| 46 |
+
data = [
|
| 47 |
+
Obj(i, 'name' + str(i), 'external' + str(i), 'now') for i in range(num)]
|
| 48 |
+
|
| 49 |
+
return data
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def run(spec, data):
|
| 53 |
+
start = time.time()
|
| 54 |
+
glom(data, spec)
|
| 55 |
+
end = time.time()
|
| 56 |
+
print(f"{(end - start) / len(data) * 1e6} us per object")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def ratio(spec, func, data):
|
| 60 |
+
glom_dur = []
|
| 61 |
+
py_dur = []
|
| 62 |
+
for i in range(10):
|
| 63 |
+
t1 = time.perf_counter_ns()
|
| 64 |
+
glom(data, spec)
|
| 65 |
+
t2 = time.perf_counter_ns()
|
| 66 |
+
func(data)
|
| 67 |
+
t3 = time.perf_counter_ns()
|
| 68 |
+
glom_dur.append(t2 - t1)
|
| 69 |
+
py_dur.append(t3 - t2)
|
| 70 |
+
|
| 71 |
+
glom_avg = sum(sorted(glom_dur)[2:-2])
|
| 72 |
+
py_avg = sum(sorted(py_dur)[2:-2])
|
| 73 |
+
|
| 74 |
+
return 1.0 * glom_avg / py_avg
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
import cProfile
|
| 79 |
+
data = setup_list_of_dict(100000)
|
| 80 |
+
run(STR_SPEC, data)
|
| 81 |
+
run(STR_SPEC, data)
|
| 82 |
+
print(ratio(STR_SPEC, func, setup_list_of_dict(1000)))
|
| 83 |
+
print(ratio(STR_SPEC, func, setup_list_of_dict(1000)))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# suggest using scalene to profile with:
|
| 87 |
+
# $ scalene glom/test/perf_report.py --profile-all --reduced-profile --cpu-only --outfile SCALENE-CPU.txt
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_basic.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from xml.etree import ElementTree as ElementTree
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from glom import glom, SKIP, STOP, Path, Inspect, Coalesce, CoalesceError, Val, Call, T, S, Invoke, Spec, Ref
|
| 7 |
+
from glom import Auto, Fill, Iter, A, Vars, Val, Literal, GlomError, Pipe
|
| 8 |
+
|
| 9 |
+
import glom.core as glom_core
|
| 10 |
+
from glom.core import UP, ROOT, bbformat, bbrepr
|
| 11 |
+
from glom.mutation import PathAssignError
|
| 12 |
+
|
| 13 |
+
from glom import OMIT, Let, Literal # backwards compat
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_initial_integration():
|
| 17 |
+
class Example:
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
example = Example()
|
| 21 |
+
subexample = Example()
|
| 22 |
+
subexample.name = 'good_name'
|
| 23 |
+
example.mapping = {'key': subexample}
|
| 24 |
+
|
| 25 |
+
val = {'a': {'b': 'c'}, # basic dictionary nesting
|
| 26 |
+
'example': example, # basic object
|
| 27 |
+
'd': {'e': ['f'], # list in dictionary
|
| 28 |
+
'g': 'h'},
|
| 29 |
+
'i': [{'j': 'k', 'l': 'm'}], # list of dictionaries
|
| 30 |
+
'n': 'o'}
|
| 31 |
+
|
| 32 |
+
spec = {'a': (Inspect(recursive=True), 'a', 'b'), # inspect just prints here
|
| 33 |
+
'name': 'example.mapping.key.name', # test object access
|
| 34 |
+
'e': 'd.e', # d.e[0] or d.e: (callable to fetch 0)
|
| 35 |
+
'i': ('i', [{'j': 'j'}]), # TODO: support True for cases when the value should simply be mapped into the field name?
|
| 36 |
+
'n': ('n', lambda n: n.upper()),
|
| 37 |
+
'p': Coalesce('xxx',
|
| 38 |
+
'yyy',
|
| 39 |
+
default='zzz')}
|
| 40 |
+
|
| 41 |
+
ret = glom(val, spec)
|
| 42 |
+
|
| 43 |
+
print('in: ', val)
|
| 44 |
+
print('got:', ret)
|
| 45 |
+
expected = {'a': 'c',
|
| 46 |
+
'name': 'good_name',
|
| 47 |
+
'e': ['f'],
|
| 48 |
+
'i': [{'j': 'k'}],
|
| 49 |
+
'n': 'O',
|
| 50 |
+
'p': 'zzz'}
|
| 51 |
+
print('exp:', expected)
|
| 52 |
+
|
| 53 |
+
assert ret == expected
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_list_item_lift_and_access():
|
| 57 |
+
val = {'d': {'e': ['f']}}
|
| 58 |
+
|
| 59 |
+
assert glom(val, ('d.e', lambda x: x[0])) == 'f'
|
| 60 |
+
assert glom(val, ('d.e', [(lambda x: {'f': x[0]}, 'f')])) == ['f']
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def test_coalesce():
|
| 64 |
+
val = {'a': {'b': 'c'}, # basic dictionary nesting
|
| 65 |
+
'd': {'e': ['f'], # list in dictionary
|
| 66 |
+
'g': 'h'},
|
| 67 |
+
'i': [{'j': 'k', 'l': 'm'}], # list of dictionaries
|
| 68 |
+
'n': 'o'}
|
| 69 |
+
|
| 70 |
+
assert glom(val, 'a.b') == 'c'
|
| 71 |
+
assert glom(val, Coalesce('xxx', 'yyy', 'a.b')) == 'c'
|
| 72 |
+
|
| 73 |
+
# check that defaulting works
|
| 74 |
+
spec = Coalesce('xxx', 'yyy', default='zzz')
|
| 75 |
+
assert glom(val, spec) == 'zzz'
|
| 76 |
+
assert repr(spec) == "Coalesce('xxx', 'yyy', default='zzz')"
|
| 77 |
+
|
| 78 |
+
# check that default_factory works
|
| 79 |
+
sentinel_list = []
|
| 80 |
+
factory = lambda: sentinel_list
|
| 81 |
+
assert glom(val, Coalesce('xxx', 'yyy', default_factory=factory)) is sentinel_list
|
| 82 |
+
|
| 83 |
+
with pytest.raises(ValueError):
|
| 84 |
+
Coalesce('x', 'y', default=1, default_factory=list)
|
| 85 |
+
|
| 86 |
+
# check that arbitrary values can be skipped
|
| 87 |
+
assert glom(val, Coalesce('xxx', 'yyy', 'a.b', default='zzz', skip='c')) == 'zzz'
|
| 88 |
+
|
| 89 |
+
# check that arbitrary exceptions can be ignored
|
| 90 |
+
assert glom(val, Coalesce(lambda x: 1/0, 'a.b', skip_exc=ZeroDivisionError)) == 'c'
|
| 91 |
+
|
| 92 |
+
target = {'a': 1, 'b': 3, 'c': 4}
|
| 93 |
+
spec = Coalesce('a', 'b', 'c', skip=lambda x: x % 2)
|
| 94 |
+
assert glom(target, spec) == 4
|
| 95 |
+
|
| 96 |
+
spec = Coalesce('a', 'b', 'c', skip=(1,))
|
| 97 |
+
assert glom(target, spec) == 3
|
| 98 |
+
|
| 99 |
+
with pytest.raises(TypeError):
|
| 100 |
+
Coalesce(bad_kwarg=True)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_skip():
|
| 105 |
+
assert OMIT is SKIP # backwards compat
|
| 106 |
+
|
| 107 |
+
target = {'a': {'b': 'c'}, # basic dictionary nesting
|
| 108 |
+
'd': {'e': ['f'], # list in dictionary
|
| 109 |
+
'g': 'h'},
|
| 110 |
+
'i': [{'j': 'k', 'l': 'm'}], # list of dictionaries
|
| 111 |
+
'n': 'o'}
|
| 112 |
+
|
| 113 |
+
res = glom(target, {'a': 'a.b',
|
| 114 |
+
'z': Coalesce('x', 'y', default=SKIP)})
|
| 115 |
+
assert res['a'] == 'c' # sanity check
|
| 116 |
+
|
| 117 |
+
assert 'x' not in target
|
| 118 |
+
assert 'y' not in target
|
| 119 |
+
assert 'z' not in res
|
| 120 |
+
|
| 121 |
+
# test that skip works on lists
|
| 122 |
+
target = range(7)
|
| 123 |
+
res = glom(target, [lambda t: t if t % 2 else SKIP])
|
| 124 |
+
assert res == [1, 3, 5]
|
| 125 |
+
|
| 126 |
+
# test that skip works on chains (enable conditional applications of transforms)
|
| 127 |
+
target = range(7)
|
| 128 |
+
# double each value if it's even, but convert all values to floats
|
| 129 |
+
res = glom(target, [(lambda x: x * 2 if x % 2 == 0 else SKIP, float)])
|
| 130 |
+
assert res == [0.0, 1.0, 4.0, 3.0, 8.0, 5.0, 12.0]
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def test_stop():
|
| 134 |
+
# test that stop works on iterables
|
| 135 |
+
target = iter([0, 1, 2, STOP, 3, 4])
|
| 136 |
+
assert glom(target, [T]) == [0, 1, 2]
|
| 137 |
+
|
| 138 |
+
# test that stop works on chains (but doesn't stop iteration up the stack)
|
| 139 |
+
target = ['a', ' b', ' c ', ' ', ' done']
|
| 140 |
+
assert glom(target, [(lambda x: x.strip(),
|
| 141 |
+
lambda x: x if x else STOP,
|
| 142 |
+
lambda x: x[0])]) == ['a', 'b', 'c', '', 'd']
|
| 143 |
+
return
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def test_top_level_default():
|
| 147 |
+
expected = object()
|
| 148 |
+
val = glom({}, 'a.b.c', default=expected)
|
| 149 |
+
assert val is expected
|
| 150 |
+
|
| 151 |
+
val = glom({}, lambda x: 1/0, skip_exc=ZeroDivisionError)
|
| 152 |
+
assert val is None
|
| 153 |
+
|
| 154 |
+
val = glom({}, lambda x: 1/0, skip_exc=ZeroDivisionError, default=expected)
|
| 155 |
+
assert val is expected
|
| 156 |
+
|
| 157 |
+
with pytest.raises(KeyError):
|
| 158 |
+
# p degenerate case if you ask me
|
| 159 |
+
glom({}, 'x', skip_exc=KeyError, default=glom_core._MISSING)
|
| 160 |
+
|
| 161 |
+
return
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def test_val():
|
| 165 |
+
assert Literal is Val
|
| 166 |
+
expected = {'value': 'c',
|
| 167 |
+
'type': 'a.b'}
|
| 168 |
+
target = {'a': {'b': 'c'}}
|
| 169 |
+
val = glom(target, {'value': 'a.b',
|
| 170 |
+
'type': Val('a.b')})
|
| 171 |
+
|
| 172 |
+
assert val == expected
|
| 173 |
+
|
| 174 |
+
assert glom(None, Val('success')) == 'success'
|
| 175 |
+
assert repr(Val(3.14)) == 'Val(3.14)'
|
| 176 |
+
assert repr(Val(3.14)) == 'Val(3.14)'
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def test_abstract_iterable():
|
| 180 |
+
assert isinstance([], glom_core._AbstractIterable)
|
| 181 |
+
|
| 182 |
+
class MyIterable:
|
| 183 |
+
def __iter__(self):
|
| 184 |
+
return iter([1, 2, 3])
|
| 185 |
+
mi = MyIterable()
|
| 186 |
+
assert list(mi) == [1, 2, 3]
|
| 187 |
+
|
| 188 |
+
assert isinstance(mi, glom_core._AbstractIterable)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def test_call_and_target():
|
| 192 |
+
class F:
|
| 193 |
+
def __init__(s, a, b, c): s.a, s.b, s.c = a, b, c
|
| 194 |
+
|
| 195 |
+
call_f = Call(F, kwargs=dict(a=T, b=T, c=T))
|
| 196 |
+
assert repr(call_f)
|
| 197 |
+
val = glom(1, call_f)
|
| 198 |
+
assert (val.a, val.b, val.c) == (1, 1, 1)
|
| 199 |
+
class F:
|
| 200 |
+
def __init__(s, a): s.a = a
|
| 201 |
+
val = glom({'one': F('two')}, Call(F, args=(T['one'].a,)))
|
| 202 |
+
assert val.a == 'two'
|
| 203 |
+
assert glom({'a': 1}, Call(F, kwargs=T)).a == 1
|
| 204 |
+
assert glom([1], Call(F, args=T)).a == 1
|
| 205 |
+
assert glom(F, T(T)).a == F
|
| 206 |
+
assert glom([F, 1], T[0](T[1]).a) == 1
|
| 207 |
+
assert glom([[1]], S[UP][Val(T)][0][0]) == 1
|
| 208 |
+
assert glom([[1]], S[UP][UP][UP][Val(T)]) == [[1]] # tops out
|
| 209 |
+
|
| 210 |
+
assert list(glom({'a': 'b'}, Call(T.values))) == ['b']
|
| 211 |
+
|
| 212 |
+
with pytest.raises(TypeError, match='expected func to be a callable or T'):
|
| 213 |
+
Call(func=object())
|
| 214 |
+
|
| 215 |
+
assert glom(lambda: 'hi', Call()) == 'hi'
|
| 216 |
+
return
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def test_invoke():
|
| 220 |
+
args = []
|
| 221 |
+
def test(*a, **kw):
|
| 222 |
+
args.append(a)
|
| 223 |
+
args.append(kw)
|
| 224 |
+
return 'test'
|
| 225 |
+
|
| 226 |
+
assert glom('a', Invoke(len).specs(T)) == 1
|
| 227 |
+
data = {
|
| 228 |
+
'args': (1, 2),
|
| 229 |
+
'args2': (4, 5),
|
| 230 |
+
'kwargs': {'a': 'a'},
|
| 231 |
+
'c': 'C',
|
| 232 |
+
}
|
| 233 |
+
spec = Invoke(test).star(args='args'
|
| 234 |
+
).constants(3, b='b').specs(c='c'
|
| 235 |
+
).star(args='args2', kwargs='kwargs')
|
| 236 |
+
repr(spec) # no exceptions
|
| 237 |
+
assert repr(Invoke(len).specs(T)) == 'Invoke(len).specs(T)'
|
| 238 |
+
assert (repr(Invoke.specfunc(next).constants(len).constants(1))
|
| 239 |
+
== 'Invoke.specfunc(next).constants(len).constants(1)')
|
| 240 |
+
assert glom(data, spec) == 'test'
|
| 241 |
+
assert args == [
|
| 242 |
+
(1, 2, 3, 4, 5),
|
| 243 |
+
{'a': 'a', 'b': 'b', 'c': 'C'}]
|
| 244 |
+
args = []
|
| 245 |
+
assert glom(test, Invoke.specfunc(T)) == 'test'
|
| 246 |
+
assert args == [(), {}]
|
| 247 |
+
repr_spec = Invoke.specfunc(T).star(args='args'
|
| 248 |
+
).constants(3, b='b').specs(c='c'
|
| 249 |
+
).star(args='args2', kwargs='kwargs')
|
| 250 |
+
assert repr(eval(repr(repr_spec), locals(), globals())) == repr(repr_spec)
|
| 251 |
+
|
| 252 |
+
with pytest.raises(TypeError, match='expected func to be a callable or Spec instance'):
|
| 253 |
+
Invoke(object())
|
| 254 |
+
with pytest.raises(TypeError, match='expected one or both of args/kwargs'):
|
| 255 |
+
Invoke(T).star()
|
| 256 |
+
|
| 257 |
+
# test interleaved pos args
|
| 258 |
+
def ret_args(*a, **kw):
|
| 259 |
+
return a, kw
|
| 260 |
+
|
| 261 |
+
spec = Invoke(ret_args).constants(1).specs({}).constants(3)
|
| 262 |
+
assert glom({}, spec) == ((1, {}, 3), {})
|
| 263 |
+
# .endswith because ret_arg's repr includes a memory location
|
| 264 |
+
assert repr(spec).endswith(').constants(1).specs({}).constants(3)')
|
| 265 |
+
|
| 266 |
+
# test overridden kwargs
|
| 267 |
+
should_stay_empty = []
|
| 268 |
+
spec = Invoke(ret_args).constants(a=1).specs(a=should_stay_empty.append).constants(a=3)
|
| 269 |
+
assert glom({}, spec) == ((), {'a': 3})
|
| 270 |
+
assert len(should_stay_empty) == 0
|
| 271 |
+
assert repr(spec).endswith(').constants(a=3)')
|
| 272 |
+
|
| 273 |
+
# bit of coverage
|
| 274 |
+
target = (lambda: 'hi', {})
|
| 275 |
+
spec = Invoke(T[0])
|
| 276 |
+
assert glom(target, spec) == 'hi'
|
| 277 |
+
# and a bit more
|
| 278 |
+
spec = spec.star(kwargs=T[1])
|
| 279 |
+
assert repr(spec) == 'Invoke(T[0]).star(kwargs=T[1])'
|
| 280 |
+
assert glom(target, spec) == 'hi'
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def test_spec_and_recursion():
|
| 285 |
+
assert repr(Spec('a.b.c')) == "Spec('a.b.c')"
|
| 286 |
+
|
| 287 |
+
# Call doesn't normally recurse, but Spec can make it do so
|
| 288 |
+
assert glom(
|
| 289 |
+
['a', 'b', 'c'],
|
| 290 |
+
Call(list, args=(
|
| 291 |
+
Spec(Call(reversed, args=(Spec(T),))),)
|
| 292 |
+
)) == ['c', 'b', 'a']
|
| 293 |
+
assert glom(['cat', {'cat': 1}], T[1][T[0]]) == 1
|
| 294 |
+
assert glom(
|
| 295 |
+
[['ab', 'cd', 'ef'], ''.join],
|
| 296 |
+
Call(T[1], args=(Auto((T[0], [T[1:]])),))) == 'bdf'
|
| 297 |
+
|
| 298 |
+
# test that spec works on the left of a dict spec
|
| 299 |
+
assert glom({'a': 'A'}, {Spec('a'): 'a', 'a': 'a'}) == {'A': 'A', 'a': 'A'}
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def test_scope():
|
| 303 |
+
assert glom(None, S['foo'], scope={'foo': 'bar'}) == 'bar'
|
| 304 |
+
|
| 305 |
+
target = range(3)
|
| 306 |
+
spec = [(S, lambda S: S['multiplier'] * S[T])]
|
| 307 |
+
scope = {'multiplier': 2}
|
| 308 |
+
assert glom(target, spec, scope=scope) == [0, 2, 4]
|
| 309 |
+
scope = {'multiplier': 2.5}
|
| 310 |
+
assert glom(target, spec, scope=scope) == [0.0, 2.5, 5.0]
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def test_seq_getitem():
|
| 314 |
+
assert glom({'items': [0, 1, 2, 3]}, 'items.1') == 1
|
| 315 |
+
assert glom({'items': (9, 8, 7, 6)}, 'items.-3') == 8
|
| 316 |
+
|
| 317 |
+
with pytest.raises(glom_core.PathAccessError):
|
| 318 |
+
assert glom({'items': (9, 8, 7, 6)}, 'items.fun')
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
# examples from http://sedimental.org/glom_restructured_data.html
|
| 322 |
+
|
| 323 |
+
def test_beyond_access():
|
| 324 |
+
# 1
|
| 325 |
+
target = {'galaxy': {'system': {'planet': 'jupiter'}}}
|
| 326 |
+
spec = 'galaxy.system.planet'
|
| 327 |
+
|
| 328 |
+
output = glom(target, spec)
|
| 329 |
+
assert output == 'jupiter'
|
| 330 |
+
|
| 331 |
+
# 2
|
| 332 |
+
target = {'system': {'planets': [{'name': 'earth'}, {'name': 'jupiter'}]}}
|
| 333 |
+
|
| 334 |
+
output = glom(target, ('system.planets', ['name']))
|
| 335 |
+
assert output == ['earth', 'jupiter']
|
| 336 |
+
|
| 337 |
+
# 3
|
| 338 |
+
target = {'system': {'planets': [{'name': 'earth', 'moons': 1},
|
| 339 |
+
{'name': 'jupiter', 'moons': 69}]}}
|
| 340 |
+
spec = {'names': ('system.planets', ['name']),
|
| 341 |
+
'moons': ('system.planets', ['moons'])}
|
| 342 |
+
|
| 343 |
+
output = glom(target, spec)
|
| 344 |
+
assert output == {'names': ['earth', 'jupiter'], 'moons': [1, 69]}
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def test_python_native():
|
| 348 |
+
# 4
|
| 349 |
+
target = {'system': {'planets': [{'name': 'earth', 'moons': 1},
|
| 350 |
+
{'name': 'jupiter', 'moons': 69}]}}
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
output = glom(target, {'moon_count': ('system.planets', ['moons'], sum)})
|
| 354 |
+
assert output == {'moon_count': 70}
|
| 355 |
+
|
| 356 |
+
# 5
|
| 357 |
+
spec = T['system']['planets'][-1].values()
|
| 358 |
+
|
| 359 |
+
output = glom(target, spec)
|
| 360 |
+
assert set(output) == {'jupiter', 69} # for ordering reasons
|
| 361 |
+
|
| 362 |
+
with pytest.raises(glom_core.GlomError):
|
| 363 |
+
spec = T['system']['comets'][-1].values()
|
| 364 |
+
output = glom(target, spec)
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def test_glom_extra_kwargs():
|
| 368 |
+
# for coverage
|
| 369 |
+
with pytest.raises(TypeError):
|
| 370 |
+
glom({'a': 'a'}, 'a', invalid_kwarg='yes')
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def test_inspect():
|
| 374 |
+
# test repr
|
| 375 |
+
assert repr(Inspect()) == '<INSPECT>'
|
| 376 |
+
|
| 377 |
+
target = {'a': {'b': 'c'}}
|
| 378 |
+
|
| 379 |
+
import pdb
|
| 380 |
+
# test breakpoint
|
| 381 |
+
assert Inspect(breakpoint=True).breakpoint == pdb.set_trace
|
| 382 |
+
with pytest.raises(TypeError):
|
| 383 |
+
Inspect(breakpoint='lol')
|
| 384 |
+
|
| 385 |
+
tracker = []
|
| 386 |
+
spec = {'a': Inspect('a.b', echo=False, breakpoint=lambda: tracker.append(True))}
|
| 387 |
+
|
| 388 |
+
glom(target, spec)
|
| 389 |
+
|
| 390 |
+
assert len(tracker) == 1
|
| 391 |
+
|
| 392 |
+
# test post_mortem
|
| 393 |
+
assert Inspect(post_mortem=True).post_mortem == pdb.post_mortem
|
| 394 |
+
with pytest.raises(TypeError):
|
| 395 |
+
Inspect(post_mortem='lol')
|
| 396 |
+
|
| 397 |
+
tracker = []
|
| 398 |
+
spec = {'a': Inspect('nope.nope', post_mortem=lambda: tracker.append(True))}
|
| 399 |
+
|
| 400 |
+
assert glom(target, spec, default='default') == 'default'
|
| 401 |
+
assert len(tracker) == 1
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def test_ref():
|
| 405 |
+
assert glom([[[]]], Ref('item', [Ref('item')])) == [[[]]]
|
| 406 |
+
with pytest.raises(Exception): # check that it recurses downards and dies on int iteration
|
| 407 |
+
glom([[[1]]], Ref('item', [Ref('item')]))
|
| 408 |
+
assert repr(Ref('item', (T[1], Ref('item')))) == "Ref('item', (T[1], Ref('item')))"
|
| 409 |
+
|
| 410 |
+
etree2dicts = Ref('ElementTree',
|
| 411 |
+
{"tag": "tag", "text": "text", "attrib": "attrib", "children": (iter, [Ref('ElementTree')])})
|
| 412 |
+
etree2tuples = Fill(Ref('ElementTree', (T.tag, (Iter(Ref('ElementTree')), list) )))
|
| 413 |
+
etree = ElementTree.fromstring('''
|
| 414 |
+
<html>
|
| 415 |
+
<head>
|
| 416 |
+
<title>the title</title>
|
| 417 |
+
</head>
|
| 418 |
+
<body id="the-body">
|
| 419 |
+
<p>A paragraph</p>
|
| 420 |
+
</body>
|
| 421 |
+
</html>''')
|
| 422 |
+
glom(etree, etree2dicts)
|
| 423 |
+
res = glom(etree, etree2tuples)
|
| 424 |
+
# TODO: list(res[1][0]) gives back:
|
| 425 |
+
# UnregisteredTarget: UnregisteredTarget('iterate', <type 'Element'>, ...
|
| 426 |
+
# This is even more visible with Iter(Ref('ElementTree')).all()
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def test_pipe():
|
| 430 |
+
assert glom(1, Pipe("__class__", "__name__", str.upper)) == 'INT'
|
| 431 |
+
assert repr(Pipe(1, Pipe([2], dict))) == 'Pipe(1, Pipe([2], dict))'
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
_IS_PYPY = '__pypy__' in sys.builtin_module_names
|
| 435 |
+
@pytest.mark.skipif(_IS_PYPY, reason='pypy othertype.__repr__ is never object.__repr__')
|
| 436 |
+
def test_api_repr():
|
| 437 |
+
import glom
|
| 438 |
+
|
| 439 |
+
spec_types_wo_reprs = []
|
| 440 |
+
for k, v in glom.__dict__.items():
|
| 441 |
+
if not callable(getattr(v, 'glomit', None)):
|
| 442 |
+
continue
|
| 443 |
+
if v.__repr__ is object.__repr__:
|
| 444 |
+
spec_types_wo_reprs.append(k) # pragma: no cover
|
| 445 |
+
|
| 446 |
+
assert set(spec_types_wo_reprs) == set()
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def test_bbformat():
|
| 450 |
+
assert bbformat("{0.__name__}", int) == "int"
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def test_bbrepr():
|
| 454 |
+
assert bbrepr({int: dict}) == "{int: dict}"
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_check.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
|
| 3 |
+
from glom import glom, Check, CheckError, Coalesce, SKIP, STOP, T
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
unicode
|
| 7 |
+
except NameError:
|
| 8 |
+
unicode = str
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_check_basic():
|
| 12 |
+
assert glom([0, SKIP], [T]) == [0] # sanity check SKIP
|
| 13 |
+
|
| 14 |
+
target = [{'id': 0}, {'id': 1}, {'id': 2}]
|
| 15 |
+
|
| 16 |
+
# check that skipping non-passing values works
|
| 17 |
+
assert glom(target, ([Coalesce(Check('id', equal_to=0), default=SKIP)], T[0])) == {'id': 0}
|
| 18 |
+
assert glom(target, ([Check('id', equal_to=0, default=SKIP)], T[0])) == {'id': 0}
|
| 19 |
+
|
| 20 |
+
# check that stopping iteration on non-passing values works
|
| 21 |
+
assert glom(target, [Check('id', equal_to=0, default=STOP)]) == [{'id': 0}]
|
| 22 |
+
|
| 23 |
+
# check that stopping chain execution on non-passing values works
|
| 24 |
+
spec = (Check(validate=lambda x: len(x) > 0, default=STOP), T[0])
|
| 25 |
+
assert glom('hello', spec) == 'h'
|
| 26 |
+
assert glom('', spec) == '' # would fail with IndexError if STOP didn't work
|
| 27 |
+
|
| 28 |
+
assert repr(Check()) == 'Check()'
|
| 29 |
+
assert repr(Check(T.a)) == 'Check(T.a)'
|
| 30 |
+
assert repr(Check(equal_to=1)) == 'Check(equal_to=1)'
|
| 31 |
+
assert repr(Check(instance_of=dict)) == 'Check(instance_of=dict)'
|
| 32 |
+
assert repr(Check(T(len), validate=sum)) == 'Check(T(len), validate=sum)'
|
| 33 |
+
|
| 34 |
+
target = [1, 'a']
|
| 35 |
+
assert glom(target, [Check(type=unicode, default=SKIP)]) == ['a']
|
| 36 |
+
assert glom(target, [Check(type=(unicode, int))]) == [1, 'a']
|
| 37 |
+
assert glom(target, [Check(instance_of=unicode, default=SKIP)]) == ['a']
|
| 38 |
+
assert glom(target, [Check(instance_of=(unicode, int))]) == [1, 'a']
|
| 39 |
+
|
| 40 |
+
target = ['1']
|
| 41 |
+
assert glom(target, [Check(validate=(int, float))])
|
| 42 |
+
assert glom(target, [Check()]) # bare check does a truthy check
|
| 43 |
+
|
| 44 |
+
failing_checks = [({'a': {'b': 1}}, {'a': ('a', 'b', Check(type=str))},
|
| 45 |
+
'''target at path ['a', 'b'] failed check, got error: "expected type to be 'str', found type 'int'"'''),
|
| 46 |
+
({'a': {'b': 1}}, {'a': ('a', Check('b', type=str))},
|
| 47 |
+
'''target at path ['a'] failed check, subtarget at 'b' got error: "expected type to be 'str', found type 'int'"'''),
|
| 48 |
+
(1, Check(type=(unicode, bool))),
|
| 49 |
+
(1, Check(instance_of=unicode)),
|
| 50 |
+
(1, Check(instance_of=(unicode, bool))),
|
| 51 |
+
(1, Check(equal_to=0)),
|
| 52 |
+
(1, Check(one_of=(0,))),
|
| 53 |
+
(1, Check(one_of=(0, 2))),
|
| 54 |
+
('-3.14', Check(validate=int)),
|
| 55 |
+
('', Check(validate=lambda x: False)),]
|
| 56 |
+
|
| 57 |
+
for fc in failing_checks:
|
| 58 |
+
if len(fc) == 2:
|
| 59 |
+
target, check = fc
|
| 60 |
+
msg = None
|
| 61 |
+
else:
|
| 62 |
+
target, check, msg = fc
|
| 63 |
+
|
| 64 |
+
with raises(CheckError) as exc_info:
|
| 65 |
+
glom(target, check)
|
| 66 |
+
|
| 67 |
+
if msg is not None:
|
| 68 |
+
assert str(exc_info.value).find(msg) != -1
|
| 69 |
+
assert repr(exc_info.value)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def test_check_multi():
|
| 73 |
+
target = 1
|
| 74 |
+
with raises(CheckError) as exc_info:
|
| 75 |
+
glom(target, Check(instance_of=float, validate=lambda x: x > 3.14))
|
| 76 |
+
|
| 77 |
+
assert "2 errors" in str(exc_info.value)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_check_signature():
|
| 82 |
+
with raises(ValueError):
|
| 83 |
+
Check(instance_of=())
|
| 84 |
+
with raises(ValueError):
|
| 85 |
+
Check(type=())
|
| 86 |
+
|
| 87 |
+
with raises(TypeError):
|
| 88 |
+
Check(fake_kwarg=True)
|
| 89 |
+
|
| 90 |
+
with raises(ValueError):
|
| 91 |
+
Check(one_of=1)
|
| 92 |
+
with raises(ValueError):
|
| 93 |
+
Check(one_of=())
|
| 94 |
+
with raises(TypeError):
|
| 95 |
+
Check(one_of=(1, 2), equal_to=3)
|
| 96 |
+
|
| 97 |
+
with raises(ValueError):
|
| 98 |
+
Check(validate='bad, not callable, value')
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_cli.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from face import CommandChecker, CommandLineError
|
| 6 |
+
|
| 7 |
+
from glom import cli
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
BASIC_TARGET = '{"a": {"b": "c"}}'
|
| 11 |
+
BASIC_SPEC = '{"a": "a.b"}'
|
| 12 |
+
BASIC_OUT = '{"a": "c"}\n'
|
| 13 |
+
|
| 14 |
+
@pytest.fixture
|
| 15 |
+
def cc():
|
| 16 |
+
cmd = cli.get_command()
|
| 17 |
+
# TODO: don't mix stderr
|
| 18 |
+
return CommandChecker(cmd, mix_stderr=True)
|
| 19 |
+
|
| 20 |
+
@pytest.fixture
|
| 21 |
+
def basic_spec_path(tmp_path):
|
| 22 |
+
spec_path = str(tmp_path) + '/basic_spec.txt'
|
| 23 |
+
with open(spec_path, 'w') as f:
|
| 24 |
+
f.write(BASIC_SPEC)
|
| 25 |
+
return spec_path
|
| 26 |
+
|
| 27 |
+
@pytest.fixture
|
| 28 |
+
def basic_target_path(tmp_path):
|
| 29 |
+
target_path = str(tmp_path) + '/basic_target.txt'
|
| 30 |
+
with open(target_path, 'w') as f:
|
| 31 |
+
f.write(BASIC_TARGET)
|
| 32 |
+
return target_path
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_cli_blank(cc):
|
| 36 |
+
res = cc.run(['glom'])
|
| 37 |
+
assert res.stdout == '{}\n'
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_cli_spec_target_argv_basic(cc):
|
| 41 |
+
res = cc.run(['glom', '--indent', '0', BASIC_SPEC, BASIC_TARGET])
|
| 42 |
+
assert res.stdout == BASIC_OUT
|
| 43 |
+
|
| 44 |
+
# json format, too
|
| 45 |
+
res = cc.run(['glom', '--indent', '0', '--spec-format', 'json', BASIC_SPEC, BASIC_TARGET])
|
| 46 |
+
assert res.stdout == BASIC_OUT
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def test_cli_spec_argv_target_stdin_basic(cc):
|
| 50 |
+
res = cc.run(['glom', '--indent', '0', BASIC_SPEC],
|
| 51 |
+
input=BASIC_TARGET)
|
| 52 |
+
assert res.stdout == BASIC_OUT
|
| 53 |
+
|
| 54 |
+
res = cc.run(['glom', '--indent', '0', BASIC_SPEC, '-'],
|
| 55 |
+
input=BASIC_TARGET)
|
| 56 |
+
assert res.stdout == BASIC_OUT
|
| 57 |
+
|
| 58 |
+
res = cc.run(['glom', '--indent', '0', '--target-file', '-', BASIC_SPEC],
|
| 59 |
+
input=BASIC_TARGET)
|
| 60 |
+
assert res.stdout == BASIC_OUT
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def test_cli_scalar(cc):
|
| 64 |
+
res = cc.run(['glom', 'a.b.c', '{"a": {"b": {"c": "d"}}}'])
|
| 65 |
+
assert res.stdout == '"d"\n'
|
| 66 |
+
|
| 67 |
+
res = cc.run(['glom', '--scalar', 'a.b.c', '{"a": {"b": {"c": "d"}}}'])
|
| 68 |
+
assert res.stdout == 'd'
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_cli_spec_target_files_basic(cc, basic_spec_path, basic_target_path):
|
| 72 |
+
res = cc.run(['glom', '--indent', '0', '--target-file',
|
| 73 |
+
basic_target_path, '--spec-file', basic_spec_path])
|
| 74 |
+
assert res.stdout == BASIC_OUT
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_usage_errors(cc, basic_spec_path, basic_target_path):
|
| 78 |
+
# bad target json
|
| 79 |
+
res = cc.fail_1(['glom', BASIC_SPEC, '{' + BASIC_TARGET])
|
| 80 |
+
assert 'could not load target data' in res.stdout # TODO: stderr
|
| 81 |
+
|
| 82 |
+
# bad target yaml
|
| 83 |
+
res = cc.fail_1(['glom', '--target-format', 'yaml', BASIC_SPEC, '{' + BASIC_TARGET])
|
| 84 |
+
assert 'could not load target data' in res.stdout # TODO: stderr
|
| 85 |
+
|
| 86 |
+
# bad target toml
|
| 87 |
+
res = cc.fail_1(['glom', '--target-format', 'toml', BASIC_SPEC, '{' + BASIC_TARGET])
|
| 88 |
+
assert 'could not load target data' in res.stdout # TODO: stderr
|
| 89 |
+
|
| 90 |
+
# TODO: bad target python?
|
| 91 |
+
|
| 92 |
+
# bad target format TODO: fail_2
|
| 93 |
+
res = cc.fail_1(['glom', '--target-format', 'lol', BASIC_SPEC, BASIC_TARGET])
|
| 94 |
+
assert 'target-format to be one of' in res.stdout # TODO: stderr
|
| 95 |
+
|
| 96 |
+
# bad spec format TODO: fail_2
|
| 97 |
+
res = cc.fail_1(['glom', '--spec-format', 'lol', BASIC_SPEC, BASIC_TARGET])
|
| 98 |
+
assert 'spec-format to be one of' in res.stdout # TODO: stderr
|
| 99 |
+
|
| 100 |
+
# test conflicting spec file and spec posarg
|
| 101 |
+
res = cc.fail_1(['glom', '--spec-file', basic_spec_path, BASIC_SPEC, BASIC_TARGET])
|
| 102 |
+
assert 'spec' in res.stdout
|
| 103 |
+
assert 'not both' in res.stdout # TODO: stderr
|
| 104 |
+
|
| 105 |
+
# test conflicting target file and target posarg
|
| 106 |
+
res = cc.fail_1(['glom', '--target-file', basic_target_path, BASIC_SPEC, BASIC_TARGET])
|
| 107 |
+
assert 'target' in res.stdout
|
| 108 |
+
assert 'not both' in res.stdout # TODO: stderr
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# TODO: if spec-file is present, maybe single posarg should become target?
|
| 112 |
+
res = cc.fail_1(['glom', '--spec-file', basic_spec_path + 'abra', '--target-file', basic_target_path])
|
| 113 |
+
assert 'could not read spec file' in res.stdout # TODO: stderr
|
| 114 |
+
|
| 115 |
+
res = cc.fail_1(['glom', '--spec-file', basic_spec_path, '--target-file', basic_target_path + 'abra'])
|
| 116 |
+
assert 'could not read target file' in res.stdout # TODO: stderr
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_main_basic():
|
| 120 |
+
argv = ['__', 'a.b.fail', '{"a": {"b": "c"}}']
|
| 121 |
+
assert cli.main(argv) == 1
|
| 122 |
+
|
| 123 |
+
argv = ['__', 'a.b.c', '{"a": {"b": {"c": "d"}}}']
|
| 124 |
+
assert cli.main(argv) == 0
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def test_main_yaml_target():
|
| 128 |
+
cwd = os.path.dirname(os.path.abspath(__file__))
|
| 129 |
+
# Handles the filepath if running tox
|
| 130 |
+
if '.tox' in cwd:
|
| 131 |
+
cwd = os.path.join(cwd.split('.tox')[0] + '/glom/test/')
|
| 132 |
+
path = os.path.join(cwd, 'data/test_valid.yaml')
|
| 133 |
+
argv = ['__', '--target-file', path, '--target-format', 'yml', 'Hello']
|
| 134 |
+
assert cli.main(argv) == 0
|
| 135 |
+
|
| 136 |
+
path = os.path.join(cwd, 'data/test_invalid.yaml')
|
| 137 |
+
argv = ['__', '--target-file', path, '--target-format', 'yml', 'Hello']
|
| 138 |
+
# Makes sure correct improper yaml exception is raised
|
| 139 |
+
with pytest.raises(CommandLineError) as excinfo:
|
| 140 |
+
cli.main(argv)
|
| 141 |
+
assert 'expected <block end>, but found' in str(excinfo.value)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_main_toml_target():
|
| 145 |
+
cwd = os.path.dirname(os.path.abspath(__file__))
|
| 146 |
+
# Handles the filepath if running tox
|
| 147 |
+
if '.tox' in cwd:
|
| 148 |
+
cwd = os.path.join(cwd.split('.tox')[0] + '/glom/test/')
|
| 149 |
+
path = os.path.join(cwd, 'data/test_valid.toml')
|
| 150 |
+
argv = ['__', '--target-file', path, '--target-format', 'toml', 'Hello']
|
| 151 |
+
assert cli.main(argv) == 0
|
| 152 |
+
|
| 153 |
+
path = os.path.join(cwd, 'data/test_invalid.toml')
|
| 154 |
+
argv = ['__', '--target-file', path, '--target-format', 'toml', 'Hello']
|
| 155 |
+
# Makes sure correct improper toml exception is raised
|
| 156 |
+
with pytest.raises(CommandLineError) as excinfo:
|
| 157 |
+
cli.main(argv)
|
| 158 |
+
assert 'Invalid initial character for a key part' in str(excinfo.value)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_main_python_full_spec_python_target():
|
| 162 |
+
argv = ['__', '--target-format', 'python', '--spec-format', 'python-full', 'T[T[3].bit_length()]', '{1: 2, 2: 3, 3: 4}']
|
| 163 |
+
assert cli.main(argv) == 0
|
| 164 |
+
|
| 165 |
+
argv = ['__', '--target-format', 'python', '--spec-format', 'python-full', '(T.values(), [T])', '{1: 2, 2: 3, 3: 4}']
|
| 166 |
+
assert cli.main(argv) == 0
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_main(tmp_path):
|
| 170 |
+
# TODO: pytest-cov knows how to make coverage work across
|
| 171 |
+
# subprocess boundaries...
|
| 172 |
+
os.chdir(str(tmp_path))
|
| 173 |
+
res = subprocess.check_output(['glom', 'a', '{"a": 3}'])
|
| 174 |
+
assert res.decode('utf8') in ('3\n', '3\r\n') # unix or windows line end okay
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_error.py
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import sys
|
| 4 |
+
import traceback
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
from glom import glom, S, T, GlomError, Switch, Coalesce, Or, Path
|
| 9 |
+
from glom.core import format_oneline_trace, format_target_spec_trace, bbrepr, ROOT, LAST_CHILD_SCOPE
|
| 10 |
+
from glom.matching import M, MatchError, TypeMatchError, Match
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# basic tests:
|
| 14 |
+
|
| 15 |
+
def test_good_error():
|
| 16 |
+
target = {'data': [0, 1, 2]}
|
| 17 |
+
|
| 18 |
+
with pytest.raises(GlomError):
|
| 19 |
+
glom(target, ('data.3'))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_error():
|
| 23 |
+
target = {'data': [0, 1, 2]}
|
| 24 |
+
|
| 25 |
+
with pytest.raises(GlomError):
|
| 26 |
+
glom(target, ('data', '3'))
|
| 27 |
+
with pytest.raises(GlomError):
|
| 28 |
+
glom(target, ('data', [(T.real, T.bit_length, T.image)]))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_pae_api():
|
| 32 |
+
target = {'value': {'data': [0, 1, 2]}}
|
| 33 |
+
|
| 34 |
+
with pytest.raises(GlomError) as exc_info:
|
| 35 |
+
glom(target, (T['value'], 'data.3'))
|
| 36 |
+
|
| 37 |
+
assert exc_info.value.path == Path('data', '3')
|
| 38 |
+
assert exc_info.value.path.__class__ is Path
|
| 39 |
+
assert exc_info.value.exc.__class__ is IndexError
|
| 40 |
+
assert exc_info.value.part_idx == 1
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_unfinalized_glomerror_repr():
|
| 44 |
+
assert 'GlomError()' in repr(GlomError())
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# trace unit tests:
|
| 48 |
+
|
| 49 |
+
def test_line_trace():
|
| 50 |
+
stacklifier = ([{'data': S}],)
|
| 51 |
+
scope = glom([1], stacklifier)[0]['data'][ROOT][LAST_CHILD_SCOPE]
|
| 52 |
+
fmtd_stack = format_oneline_trace(scope)
|
| 53 |
+
assert fmtd_stack == '/tuple!list/list<0>/dict!int/S'
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# full traceback testing:
|
| 57 |
+
|
| 58 |
+
def _norm_stack(formatted_stack, exc):
|
| 59 |
+
|
| 60 |
+
normalized = []
|
| 61 |
+
for line in formatted_stack.splitlines():
|
| 62 |
+
if line.strip().startswith('File'):
|
| 63 |
+
file_name = line.split('"')[1]
|
| 64 |
+
short_file_name = os.path.split(file_name.strip('"'))[1]
|
| 65 |
+
line = line.replace(file_name, short_file_name)
|
| 66 |
+
line = line.partition('line')[0] + 'line ___,' + line.partition('line')[2].partition(',')[2]
|
| 67 |
+
line = line.partition('0x')[0] # scrub memory addresses
|
| 68 |
+
|
| 69 |
+
line = line.rstrip() # trailing whitespace shouldn't matter
|
| 70 |
+
|
| 71 |
+
# qualify python2's unqualified error type names
|
| 72 |
+
exc_type_name = exc.__class__.__name__
|
| 73 |
+
if exc_type_name in line:
|
| 74 |
+
mod_name = str(getattr(exc.__class__, '__module__', '') or '')
|
| 75 |
+
exc_type_qual_name = exc_type_name
|
| 76 |
+
if 'builtin' not in mod_name:
|
| 77 |
+
exc_type_qual_name = mod_name + '.' + exc_type_name
|
| 78 |
+
if exc_type_qual_name not in line:
|
| 79 |
+
line = line.replace(exc_type_name, exc_type_qual_name)
|
| 80 |
+
|
| 81 |
+
normalized.append(line)
|
| 82 |
+
|
| 83 |
+
stack = "\n".join(normalized) + '\n'
|
| 84 |
+
stack = stack.replace(',)', ')') # py37 likes to do Exception('msg',)
|
| 85 |
+
return stack
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _make_stack(spec, **kwargs):
|
| 89 |
+
target = kwargs.pop('target', [None])
|
| 90 |
+
assert not kwargs
|
| 91 |
+
_orig_some_str = getattr(traceback, '_some_str', None)
|
| 92 |
+
|
| 93 |
+
def _debug_some_str(value, *a, **kw):
|
| 94 |
+
# all to debug some CI flakiness
|
| 95 |
+
try:
|
| 96 |
+
return str(value)
|
| 97 |
+
except BaseException as be: # pragma: no cover
|
| 98 |
+
try:
|
| 99 |
+
print(f' !! failed to stringify {type(value).__name__} object, got {be}')
|
| 100 |
+
traceback.print_exc()
|
| 101 |
+
except:
|
| 102 |
+
print(' !! unable to print trace')
|
| 103 |
+
return f'<unprintable {type(value).__name__} object got {be}>'
|
| 104 |
+
|
| 105 |
+
traceback._some_str = _debug_some_str
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
try:
|
| 109 |
+
glom(target, spec)
|
| 110 |
+
except GlomError as e:
|
| 111 |
+
stack = _norm_stack(traceback.format_exc(), e)
|
| 112 |
+
finally:
|
| 113 |
+
traceback._some_str = _orig_some_str
|
| 114 |
+
return stack
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# quick way to get a function in this file, which doesn't have a glom
|
| 118 |
+
# package file path prefix on it. this prevents the function getting
|
| 119 |
+
# removed in the stack flattening.
|
| 120 |
+
from boltons.funcutils import FunctionBuilder
|
| 121 |
+
fb = FunctionBuilder(name='_raise_exc',
|
| 122 |
+
body='raise Exception("unique message")',
|
| 123 |
+
args=['t'])
|
| 124 |
+
_raise_exc = fb.get_func()
|
| 125 |
+
|
| 126 |
+
# NB: if we keep this approach, eventually
|
| 127 |
+
# boltons.funcutils.FunctionBuilder will put lines into the linecache,
|
| 128 |
+
# and comparisons may break
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_regular_error_stack():
|
| 132 |
+
actual = _make_stack({'results': [{'value': _raise_exc}]})
|
| 133 |
+
expected = """\
|
| 134 |
+
Traceback (most recent call last):
|
| 135 |
+
File "test_error.py", line ___, in _make_stack
|
| 136 |
+
glom(target, spec)
|
| 137 |
+
File "core.py", line ___, in glom
|
| 138 |
+
raise err
|
| 139 |
+
glom.core.GlomError.wrap(Exception): error raised while processing, details below.
|
| 140 |
+
Target-spec trace (most recent last):
|
| 141 |
+
- Target: [None]
|
| 142 |
+
- Spec: {'results': [{'value': <function _raise_exc at
|
| 143 |
+
- Spec: [{'value': <function _raise_exc at
|
| 144 |
+
- Target: None
|
| 145 |
+
- Spec: {'value': <function _raise_exc at
|
| 146 |
+
- Spec: <function _raise_exc at
|
| 147 |
+
File "<boltons.funcutils.FunctionBuilder-0>", line ___, in _raise_exc
|
| 148 |
+
Exception: unique message
|
| 149 |
+
"""
|
| 150 |
+
# _raise_exc being present in the second-to-last line above tests
|
| 151 |
+
# that errors in user-defined functions result in frames being
|
| 152 |
+
# visible
|
| 153 |
+
assert expected == actual
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def test_glom_error_stack():
|
| 157 |
+
# NoneType has not attribute value
|
| 158 |
+
expected = """\
|
| 159 |
+
Traceback (most recent call last):
|
| 160 |
+
File "test_error.py", line ___, in _make_stack
|
| 161 |
+
glom(target, spec)
|
| 162 |
+
File "core.py", line ___, in glom
|
| 163 |
+
raise err
|
| 164 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 165 |
+
Target-spec trace (most recent last):
|
| 166 |
+
- Target: [None]
|
| 167 |
+
- Spec: {'results': [{'valué': 'value'}]}
|
| 168 |
+
- Spec: [{'valué': 'value'}]
|
| 169 |
+
- Target: None
|
| 170 |
+
- Spec: {'valué': 'value'}
|
| 171 |
+
- Spec: 'value'
|
| 172 |
+
glom.core.PathAccessError: could not access 'value', part 0 of Path('value'), got error: AttributeError("'NoneType' object has no attribute 'value'")
|
| 173 |
+
"""
|
| 174 |
+
#import glom.core
|
| 175 |
+
#glom.core.GLOM_DEBUG = True
|
| 176 |
+
actual = _make_stack({'results': [{'valué': 'value'}]})
|
| 177 |
+
print(actual)
|
| 178 |
+
|
| 179 |
+
assert actual == expected
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
# used by the test below, but at the module level.
|
| 183 |
+
# originally added to make stack traces more uniform between
|
| 184 |
+
# python versions (py3 tries to qualify lambdas and
|
| 185 |
+
# other functions inside of local scopes.)
|
| 186 |
+
|
| 187 |
+
def _uses_another_glom():
|
| 188 |
+
try:
|
| 189 |
+
ret = glom(['Nested'], {'internal': ['val']})
|
| 190 |
+
except Exception as exc:
|
| 191 |
+
raise
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _subglom_wrap(t):
|
| 195 |
+
return _uses_another_glom()
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def test_glom_error_double_stack():
|
| 199 |
+
actual = _make_stack({'results': [{'value': _subglom_wrap}]})
|
| 200 |
+
expected = """\
|
| 201 |
+
Traceback (most recent call last):
|
| 202 |
+
File "test_error.py", line ___, in _make_stack
|
| 203 |
+
glom(target, spec)
|
| 204 |
+
File "core.py", line ___, in glom
|
| 205 |
+
raise err
|
| 206 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 207 |
+
Target-spec trace (most recent last):
|
| 208 |
+
- Target: [None]
|
| 209 |
+
- Spec: {'results': [{'value': <function _subglom_wrap at
|
| 210 |
+
- Spec: [{'value': <function _subglom_wrap at
|
| 211 |
+
- Target: None
|
| 212 |
+
- Spec: {'value': <function _subglom_wrap at
|
| 213 |
+
- Spec: <function _subglom_wrap at
|
| 214 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 215 |
+
Target-spec trace (most recent last):
|
| 216 |
+
- Target: ['Nested']
|
| 217 |
+
- Spec: {'internal': ['val']}
|
| 218 |
+
- Spec: ['val']
|
| 219 |
+
- Target: 'Nested'
|
| 220 |
+
- Spec: 'val'
|
| 221 |
+
glom.core.PathAccessError: could not access 'val', part 0 of Path('val'), got error: AttributeError("'str' object has no attribute 'val'")
|
| 222 |
+
"""
|
| 223 |
+
assert expected == actual
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def test_long_target_repr():
|
| 227 |
+
import glom as glom_mod
|
| 228 |
+
assert not glom_mod.core.GLOM_DEBUG
|
| 229 |
+
actual = _make_stack(target=[None] * 1000, spec='1001')
|
| 230 |
+
assert '(len=1000)' in actual
|
| 231 |
+
|
| 232 |
+
class ObjectWithLongRepr:
|
| 233 |
+
def __repr__(self):
|
| 234 |
+
return '<{} {}>'.format(self.__class__.__name__, 'w' + ('ooooo' * 250))
|
| 235 |
+
|
| 236 |
+
actual = _make_stack(target=ObjectWithLongRepr(), spec='badattr')
|
| 237 |
+
assert '...' in actual
|
| 238 |
+
assert '(len=' not in actual # no length on a single object
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_branching_stack():
|
| 242 |
+
# ends-in-branch
|
| 243 |
+
actual = _make_stack(Match(Switch(
|
| 244 |
+
[(1, 1), ('a', 'a'), (T.a, T.a)])))
|
| 245 |
+
expected = """\
|
| 246 |
+
Traceback (most recent call last):
|
| 247 |
+
File "test_error.py", line ___, in _make_stack
|
| 248 |
+
glom(target, spec)
|
| 249 |
+
File "core.py", line ___, in glom
|
| 250 |
+
raise err
|
| 251 |
+
glom.matching.MatchError: error raised while processing, details below.
|
| 252 |
+
Target-spec trace (most recent last):
|
| 253 |
+
- Target: [None]
|
| 254 |
+
- Spec: Match(Switch([(1, 1), ('a', 'a'), (T.a, T.a)]))
|
| 255 |
+
+ Spec: Switch([(1, 1), ('a', 'a'), (T.a, T.a)])
|
| 256 |
+
|\\ Spec: 1
|
| 257 |
+
|X glom.matching.MatchError: [None] does not match 1
|
| 258 |
+
|\\ Spec: 'a'
|
| 259 |
+
|X glom.matching.MatchError: [None] does not match 'a'
|
| 260 |
+
|\\ Spec: T.a
|
| 261 |
+
|X glom.core.PathAccessError: could not access 'a', part 0 of T.a, got error: AttributeError("'list' object has no attribute 'a'")
|
| 262 |
+
glom.matching.MatchError: no matches for target in Switch
|
| 263 |
+
"""
|
| 264 |
+
assert actual == expected
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_midway_branch():
|
| 268 |
+
# midway branch, but then continues
|
| 269 |
+
actual = _make_stack(Match(Switch(
|
| 270 |
+
[(1, 1), ('a', 'a'), ([None], T.a)])))
|
| 271 |
+
expected = """\
|
| 272 |
+
Traceback (most recent call last):
|
| 273 |
+
File "test_error.py", line ___, in _make_stack
|
| 274 |
+
glom(target, spec)
|
| 275 |
+
File "core.py", line ___, in glom
|
| 276 |
+
raise err
|
| 277 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 278 |
+
Target-spec trace (most recent last):
|
| 279 |
+
- Target: [None]
|
| 280 |
+
- Spec: Match(Switch([(1, 1), ('a', 'a'), ([None], T.a)]))
|
| 281 |
+
+ Spec: Switch([(1, 1), ('a', 'a'), ([None], T.a)])
|
| 282 |
+
|\\ Spec: 1
|
| 283 |
+
|X glom.matching.MatchError: [None] does not match 1
|
| 284 |
+
|\\ Spec: 'a'
|
| 285 |
+
|X glom.matching.MatchError: [None] does not match 'a'
|
| 286 |
+
|\\ Spec: [None]
|
| 287 |
+
|| Spec: T.a
|
| 288 |
+
glom.core.PathAccessError: could not access 'a', part 0 of T.a, got error: AttributeError("'list' object has no attribute 'a'")
|
| 289 |
+
"""
|
| 290 |
+
assert actual == expected
|
| 291 |
+
# branch and another branch
|
| 292 |
+
actual = _make_stack(Match(Switch(
|
| 293 |
+
[(1, 1), ('a', 'a'), ([None], Switch(
|
| 294 |
+
[(1, 1), ('a', 'a'), ([None], T.a)]))])))
|
| 295 |
+
expected = """\
|
| 296 |
+
Traceback (most recent call last):
|
| 297 |
+
File "test_error.py", line ___, in _make_stack
|
| 298 |
+
glom(target, spec)
|
| 299 |
+
File "core.py", line ___, in glom
|
| 300 |
+
raise err
|
| 301 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 302 |
+
Target-spec trace (most recent last):
|
| 303 |
+
- Target: [None]
|
| 304 |
+
- Spec: Match(Switch([(1, 1), ('a', 'a'), ([None], Switch([(1, 1), ('a', '...
|
| 305 |
+
+ Spec: Switch([(1, 1), ('a', 'a'), ([None], Switch([(1, 1), ('a', 'a'), (...
|
| 306 |
+
|\\ Spec: 1
|
| 307 |
+
|X glom.matching.MatchError: [None] does not match 1
|
| 308 |
+
|\\ Spec: 'a'
|
| 309 |
+
|X glom.matching.MatchError: [None] does not match 'a'
|
| 310 |
+
|\\ Spec: [None]
|
| 311 |
+
|+ Spec: Switch([(1, 1), ('a', 'a'), ([None], T.a)])
|
| 312 |
+
||\\ Spec: 1
|
| 313 |
+
||X glom.matching.MatchError: [None] does not match 1
|
| 314 |
+
||\\ Spec: 'a'
|
| 315 |
+
||X glom.matching.MatchError: [None] does not match 'a'
|
| 316 |
+
||\\ Spec: [None]
|
| 317 |
+
||| Spec: T.a
|
| 318 |
+
glom.core.PathAccessError: could not access 'a', part 0 of T.a, got error: AttributeError("'list' object has no attribute 'a'")
|
| 319 |
+
"""
|
| 320 |
+
assert actual == expected
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def test_partially_failing_branch():
|
| 324 |
+
# what happens when part of an Or() etc fails,
|
| 325 |
+
# but another part succeeds and then an error happens further down?
|
| 326 |
+
assert _make_stack((Or('a', T), Or('b', T), 'c'), target=None) == """\
|
| 327 |
+
Traceback (most recent call last):
|
| 328 |
+
File "test_error.py", line ___, in _make_stack
|
| 329 |
+
glom(target, spec)
|
| 330 |
+
File "core.py", line ___, in glom
|
| 331 |
+
raise err
|
| 332 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 333 |
+
Target-spec trace (most recent last):
|
| 334 |
+
- Target: None
|
| 335 |
+
- Spec: (Or('a', T), Or('b', T), 'c')
|
| 336 |
+
- Spec: Or('a', T)
|
| 337 |
+
- Spec: Or('b', T)
|
| 338 |
+
- Spec: 'c'
|
| 339 |
+
glom.core.PathAccessError: could not access 'c', part 0 of Path('c'), got error: AttributeError("'NoneType' object has no attribute 'c'")
|
| 340 |
+
"""
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def test_coalesce_stack():
|
| 344 |
+
val = {'a': {'b': 'c'}, # basic dictionary nesting
|
| 345 |
+
'd': {'e': ['f'], # list in dictionary
|
| 346 |
+
'g': 'h'},
|
| 347 |
+
'i': [{'j': 'k', 'l': 'm'}], # list of dictionaries
|
| 348 |
+
'n': 'o'}
|
| 349 |
+
actual = _make_stack(Coalesce('xxx', 'yyy'), target=val)
|
| 350 |
+
expected = """\
|
| 351 |
+
Traceback (most recent call last):
|
| 352 |
+
File "test_error.py", line ___, in _make_stack
|
| 353 |
+
glom(target, spec)
|
| 354 |
+
File "core.py", line ___, in glom
|
| 355 |
+
raise err
|
| 356 |
+
glom.core.CoalesceError: error raised while processing, details below.
|
| 357 |
+
Target-spec trace (most recent last):
|
| 358 |
+
- Target: {'a': {'b': 'c'}, 'd': {'e': ['f'], 'g': 'h'}, 'i': [{'j... (len=4)
|
| 359 |
+
+ Spec: Coalesce('xxx', 'yyy')
|
| 360 |
+
|\\ Spec: 'xxx'
|
| 361 |
+
|X glom.core.PathAccessError: could not access 'xxx', part 0 of Path('xxx'), got error: KeyError('xxx')
|
| 362 |
+
|\\ Spec: 'yyy'
|
| 363 |
+
|X glom.core.PathAccessError: could not access 'yyy', part 0 of Path('yyy'), got error: KeyError('yyy')
|
| 364 |
+
glom.core.CoalesceError: no valid values found. Tried ('xxx', 'yyy') and got (PathAccessError, PathAccessError) (at path [])
|
| 365 |
+
"""
|
| 366 |
+
assert actual == expected
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def test_nesting_stack():
|
| 370 |
+
# check behavior when a glom stack is nested via data structure not python call stack
|
| 371 |
+
assert _make_stack(('a', 'b', 'c'), target={'a': {'b': {}}}) == """\
|
| 372 |
+
Traceback (most recent call last):
|
| 373 |
+
File "test_error.py", line ___, in _make_stack
|
| 374 |
+
glom(target, spec)
|
| 375 |
+
File "core.py", line ___, in glom
|
| 376 |
+
raise err
|
| 377 |
+
glom.core.PathAccessError: error raised while processing, details below.
|
| 378 |
+
Target-spec trace (most recent last):
|
| 379 |
+
- Target: {'a': {'b': {}}}
|
| 380 |
+
- Spec: ('a', 'b', 'c')
|
| 381 |
+
- Spec: 'a'
|
| 382 |
+
- Target: {'b': {}}
|
| 383 |
+
- Spec: 'b'
|
| 384 |
+
- Target: {}
|
| 385 |
+
- Spec: 'c'
|
| 386 |
+
glom.core.PathAccessError: could not access 'c', part 0 of Path('c'), got error: KeyError('c')
|
| 387 |
+
"""
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
ERROR_CLASSES = (
|
| 391 |
+
ValueError, NameError, AttributeError, ZeroDivisionError, SyntaxError, ImportError)
|
| 392 |
+
|
| 393 |
+
def test_error_types():
|
| 394 |
+
"""test that try / except work normally through glom"""
|
| 395 |
+
for err_class in ERROR_CLASSES:
|
| 396 |
+
def err_raise(t):
|
| 397 |
+
raise err_class()
|
| 398 |
+
with pytest.raises(err_class):
|
| 399 |
+
glom(None, err_raise)
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def test_fallback():
|
| 403 |
+
"""
|
| 404 |
+
test that in cases of weird badly behaved exception types,
|
| 405 |
+
the handler falls back from wrapping to just letting the exception
|
| 406 |
+
through
|
| 407 |
+
"""
|
| 408 |
+
class BadExc(Exception):
|
| 409 |
+
def __init__(self, first):
|
| 410 |
+
if not first:
|
| 411 |
+
1/0
|
| 412 |
+
self.first = False
|
| 413 |
+
super().__init__(self.first)
|
| 414 |
+
|
| 415 |
+
bad_exc = BadExc(True)
|
| 416 |
+
|
| 417 |
+
def raise_bad(t):
|
| 418 |
+
raise bad_exc
|
| 419 |
+
|
| 420 |
+
try:
|
| 421 |
+
glom(None, raise_bad)
|
| 422 |
+
except Exception as e:
|
| 423 |
+
assert e is bad_exc
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
def test_all_public_errors():
|
| 427 |
+
"""test that all errors importable from the top-level glom module
|
| 428 |
+
pass a basic set of standards.
|
| 429 |
+
|
| 430 |
+
When adding a new public error type, this test will be fail unless
|
| 431 |
+
that type is also tested below.
|
| 432 |
+
"""
|
| 433 |
+
import glom
|
| 434 |
+
import copy
|
| 435 |
+
|
| 436 |
+
err_types = [t for t in
|
| 437 |
+
[getattr(glom, name) for name in dir(glom)]
|
| 438 |
+
if isinstance(t, type) and issubclass(t, Exception)]
|
| 439 |
+
non_glomerrors = [t for t in err_types if not issubclass(t, glom.GlomError)]
|
| 440 |
+
assert not non_glomerrors, "expected all public exception types to subclass GlomError"
|
| 441 |
+
|
| 442 |
+
err_types = sorted([t for t in err_types if not t is glom.GlomError],
|
| 443 |
+
key=lambda t: t.__name__)
|
| 444 |
+
|
| 445 |
+
results = []
|
| 446 |
+
|
| 447 |
+
def _test_exc(exc_type, target, spec):
|
| 448 |
+
with pytest.raises(exc_type) as exc_info:
|
| 449 |
+
glom.glom(target, spec)
|
| 450 |
+
results.append((target, spec, exc_info.value))
|
| 451 |
+
return exc_info.value
|
| 452 |
+
|
| 453 |
+
_test_exc(glom.CheckError, {}, glom.Check(equal_to=[]))
|
| 454 |
+
|
| 455 |
+
_test_exc(glom.FoldError, 2, glom.Flatten())
|
| 456 |
+
|
| 457 |
+
_test_exc(glom.BadSpec, range(5), glom.grouping.Group([{T: T}]))
|
| 458 |
+
|
| 459 |
+
_test_exc(glom.PathAccessError, {}, 'a.b.c')
|
| 460 |
+
|
| 461 |
+
_test_exc(glom.UnregisteredTarget, 'kurt', [glom.T])
|
| 462 |
+
|
| 463 |
+
_test_exc(glom.CoalesceError, {}, glom.Coalesce('a', 'b'))
|
| 464 |
+
|
| 465 |
+
_test_exc(glom.PathAssignError, object(), glom.Assign('a', 'b'))
|
| 466 |
+
|
| 467 |
+
_test_exc(glom.PathDeleteError, object(), glom.Delete('a'))
|
| 468 |
+
|
| 469 |
+
_test_exc(MatchError, 1, M == 2)
|
| 470 |
+
|
| 471 |
+
_test_exc(TypeMatchError, 1, Match(str))
|
| 472 |
+
|
| 473 |
+
for (target, spec, exc) in results:
|
| 474 |
+
assert copy.copy(exc) is not exc
|
| 475 |
+
exc_str = str(exc)
|
| 476 |
+
exc_type_name = exc.__class__.__name__
|
| 477 |
+
assert exc_type_name in exc_str
|
| 478 |
+
assert bbrepr(exc).startswith(exc_type_name)
|
| 479 |
+
|
| 480 |
+
assert bbrepr(target)[:80] in exc_str
|
| 481 |
+
assert bbrepr(spec)[:80] in exc_str
|
| 482 |
+
|
| 483 |
+
tested_types = [type(exc) for _, _, exc in results]
|
| 484 |
+
untested_types = set(err_types) - set(tested_types)
|
| 485 |
+
|
| 486 |
+
assert not untested_types, "did not test all public exception types"
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def test_glom_dev_debug():
|
| 490 |
+
with pytest.raises(GlomError) as exc_info:
|
| 491 |
+
glom({'a': 'yesandno'}, 'a.b.c')
|
| 492 |
+
|
| 493 |
+
assert ' - Target:' in str(exc_info.value)
|
| 494 |
+
assert 'yesandno' in str(exc_info.value)
|
| 495 |
+
assert len(exc_info.traceback) == 2
|
| 496 |
+
|
| 497 |
+
with pytest.raises(GlomError) as exc_info:
|
| 498 |
+
glom({'a': 'yesandno'}, 'a.b.c', glom_debug=True)
|
| 499 |
+
|
| 500 |
+
assert ' - Target:' not in str(exc_info.value)
|
| 501 |
+
assert len(exc_info.traceback) > 2
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
def test_unicode_stack():
|
| 505 |
+
val = {'resumé': 'beyoncé'}
|
| 506 |
+
stack = _make_stack(target=val, spec='a.é.i.o')
|
| 507 |
+
assert 'beyonc' in stack
|
| 508 |
+
assert 'é' in stack
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
def test_3_11_byte_code_caret():
|
| 512 |
+
"""the ~~^ used to mark the current byte code position should be removed"""
|
| 513 |
+
assert _make_stack(target=1, spec=[]) == """\
|
| 514 |
+
Traceback (most recent call last):
|
| 515 |
+
File "test_error.py", line ___, in _make_stack
|
| 516 |
+
glom(target, spec)
|
| 517 |
+
File "core.py", line ___, in glom
|
| 518 |
+
raise err
|
| 519 |
+
glom.core.GlomError.wrap(IndexError): error raised while processing, details below.
|
| 520 |
+
Target-spec trace (most recent last):
|
| 521 |
+
- Target: 1
|
| 522 |
+
- Spec: []
|
| 523 |
+
IndexError: list index out of range
|
| 524 |
+
"""
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_fill.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from glom import Auto, Fill, T, glom
|
| 2 |
+
|
| 3 |
+
def test():
|
| 4 |
+
assert glom('abc', Fill((T[0], {T[1]: T[2]}))) == ('a', {'b': 'c'})
|
| 5 |
+
assert glom('123', Fill({T[0], frozenset([T[1], T[2]])})) == {'1', frozenset(['2', '3'])}
|
| 6 |
+
assert glom('xyz', Fill([T[0], T[1], T[2]]))
|
| 7 |
+
assert glom('abc', Fill(lambda t: t.upper())) == 'ABC'
|
| 8 |
+
assert glom('a', Fill(1)) == 1
|
| 9 |
+
assert Fill((T, T, T)).fill(1) == (1, 1, 1)
|
| 10 |
+
|
| 11 |
+
target = {'data': [0, 2, 4]}
|
| 12 |
+
assert glom(target, Fill((T['data'][-1], Auto('data.-2')))) == (4, 2)
|
| 13 |
+
|
| 14 |
+
assert repr(Auto()) == 'Auto()'
|
| 15 |
+
assert repr(Auto(T)) == 'Auto(T)'
|
| 16 |
+
|
| 17 |
+
assert repr(Fill()) == 'Fill()'
|
| 18 |
+
assert repr(Fill(T)) == 'Fill(T)'
|
| 19 |
+
|
| 20 |
+
assert repr(Fill(len)) == 'Fill(len)'
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_grouping.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
|
| 3 |
+
from glom import glom, T, SKIP, STOP, Auto, BadSpec, Val
|
| 4 |
+
from glom.grouping import Group, First, Avg, Max, Min, Sample, Limit
|
| 5 |
+
|
| 6 |
+
from glom.reduction import Merge, Flatten, Sum, Count
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_bucketing():
|
| 10 |
+
assert glom(range(4), Group({T % 2: [T]})) == {0: [0, 2], 1: [1, 3]}
|
| 11 |
+
assert (glom(range(6), Group({T % 3: {T % 2: [T / 10.0]}})) ==
|
| 12 |
+
{0: {0: [0.0], 1: [0.3]}, 1: {1: [0.1], 0: [0.4]}, 2: {0: [0.2], 1: [0.5]}})
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_corner_cases():
|
| 17 |
+
target = range(5)
|
| 18 |
+
|
| 19 |
+
# immediate stop dict
|
| 20 |
+
assert glom(target, Group({Val(STOP): [T]})) == {}
|
| 21 |
+
|
| 22 |
+
# immediate stop list
|
| 23 |
+
assert glom(target, Group([Val(STOP)])) == []
|
| 24 |
+
|
| 25 |
+
# dict key SKIP
|
| 26 |
+
assert glom(target, Group({(lambda t: SKIP if t < 3 else t): T})) == {3: 3, 4: 4}
|
| 27 |
+
|
| 28 |
+
# dict val SKIP
|
| 29 |
+
assert glom(target, Group({T: lambda t: t if t % 2 else SKIP})) == {3: 3, 1: 1}
|
| 30 |
+
|
| 31 |
+
# list val SKIP
|
| 32 |
+
assert glom(target, Group([lambda t: t if t % 2 else SKIP])) == [1, 3]
|
| 33 |
+
|
| 34 |
+
# embedded auto spec (lol @ 0 being 0 bit length)
|
| 35 |
+
assert glom(target, Group({Auto(('bit_length', T())): [T]})) == {0: [0], 1: [1], 2: [2, 3], 3: [4]}
|
| 36 |
+
|
| 37 |
+
# no dicts inside lists in Group mode
|
| 38 |
+
with raises(BadSpec):
|
| 39 |
+
assert glom(target, Group([{T: T}]))
|
| 40 |
+
|
| 41 |
+
# check only supported types
|
| 42 |
+
with raises(BadSpec):
|
| 43 |
+
assert glom(target, Group('no string support yet'))
|
| 44 |
+
|
| 45 |
+
# bucket ints by their bit length and then odd/even, limited to 3 per bucket
|
| 46 |
+
spec = Group({T.bit_length(): {lambda t: t % 2: Limit(3)}})
|
| 47 |
+
res = glom(range(20), spec)
|
| 48 |
+
assert res == {0: {0: [0]},
|
| 49 |
+
1: {1: [1]},
|
| 50 |
+
2: {0: [2], 1: [3]},
|
| 51 |
+
3: {0: [4, 6], 1: [5, 7]},
|
| 52 |
+
4: {0: [8, 10, 12], 1: [9, 11, 13]}}
|
| 53 |
+
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_agg():
|
| 58 |
+
t = list(range(10))
|
| 59 |
+
assert glom(t, Group(First())) == 0
|
| 60 |
+
assert glom(t, Group(T)) == 9 # this is basically Last
|
| 61 |
+
|
| 62 |
+
assert glom(t, Group(Avg())) == sum(t) / len(t)
|
| 63 |
+
assert glom(t, Group(Sum())) == sum(t)
|
| 64 |
+
|
| 65 |
+
assert glom([0, 1, 0], Group(Max())) == 1
|
| 66 |
+
assert glom([1, 0, 1], Group(Min())) == 0
|
| 67 |
+
|
| 68 |
+
assert repr(Group(First())) == 'Group(First())'
|
| 69 |
+
assert repr(Avg()) == 'Avg()'
|
| 70 |
+
assert repr(Max()) == 'Max()'
|
| 71 |
+
assert repr(Min()) == 'Min()'
|
| 72 |
+
assert repr(Sum()) == 'Sum()'
|
| 73 |
+
assert repr(Count()) == 'Count()'
|
| 74 |
+
|
| 75 |
+
assert glom(range(10), Group({lambda t: t % 2: Count()})) == {
|
| 76 |
+
0: 5, 1: 5}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def test_limit():
|
| 80 |
+
t = list(range(10))
|
| 81 |
+
assert glom(t, Group(Limit(1, T))) == 0
|
| 82 |
+
assert glom(t, Group(Limit(3, Max()))) == 2
|
| 83 |
+
assert glom(t, Group(Limit(3, [T]))) == [0, 1, 2]
|
| 84 |
+
|
| 85 |
+
assert repr(Group(Limit(3, Max()))) == 'Group(Limit(3, Max()))'
|
| 86 |
+
|
| 87 |
+
with raises(BadSpec):
|
| 88 |
+
assert glom(t, Limit(1)) # needs to be wrapped in Group for now
|
| 89 |
+
return
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_reduce():
|
| 93 |
+
assert glom([[1], [2, 3]], Group(Flatten())) == [1, 2, 3]
|
| 94 |
+
assert glom([{'a': 1}, {'b': 2}], Group(Merge())) == {'a': 1, 'b': 2}
|
| 95 |
+
assert glom([[[1]], [[2, 3], [4]]], Group(Flatten(Flatten()))) == [1, 2, 3, 4]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def test_sample():
|
| 99 |
+
spec = Group(Sample(5))
|
| 100 |
+
assert glom([1, 2, 3], spec) == [1, 2, 3]
|
| 101 |
+
|
| 102 |
+
assert repr(spec) == 'Group(Sample(5))'
|
| 103 |
+
|
| 104 |
+
s = glom([1, 2, 3], Group(Sample(2)))
|
| 105 |
+
assert s in [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_match.py
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from glom import glom, S, Val, T, A, Fill, Ref, Coalesce, STOP, Switch
|
| 7 |
+
from glom.matching import (
|
| 8 |
+
Match, M, MatchError, TypeMatchError, And, Or, Not,
|
| 9 |
+
Optional, Required, Regex)
|
| 10 |
+
from glom.core import Auto, SKIP, Ref
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
unicode
|
| 14 |
+
except NameError:
|
| 15 |
+
unicode = str
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _chk(spec, good_target, bad_target):
|
| 20 |
+
glom(good_target, spec)
|
| 21 |
+
with pytest.raises(MatchError):
|
| 22 |
+
glom(bad_target, spec)
|
| 23 |
+
|
| 24 |
+
def test_basic():
|
| 25 |
+
_chk(Match(1), 1, 2)
|
| 26 |
+
_chk(Match(int), 1, 1.0)
|
| 27 |
+
# test unordered sequence comparisons
|
| 28 |
+
_chk(Match([int]), [1], ["1"])
|
| 29 |
+
_chk(Match({int}), {1}, [1])
|
| 30 |
+
_chk(Match(frozenset({float})), frozenset({}), frozenset({"1"}))
|
| 31 |
+
_chk(Match(len), [1], [])
|
| 32 |
+
with pytest.raises(MatchError):
|
| 33 |
+
glom(None, Match(len))
|
| 34 |
+
with pytest.raises(MatchError):
|
| 35 |
+
glom([1], Match([])) # empty shouldn't match
|
| 36 |
+
glom({"a": 1, "b": 2}, Match({str: int}))
|
| 37 |
+
glom(2, M == 2)
|
| 38 |
+
glom(int, M == int)
|
| 39 |
+
glom(1.0, M > 0)
|
| 40 |
+
glom(1.0, M >= 1)
|
| 41 |
+
glom(1.0, M < 2)
|
| 42 |
+
glom(1.0, M <= 1)
|
| 43 |
+
glom(1.0, M != None)
|
| 44 |
+
glom(1.0, (M > 0) & float)
|
| 45 |
+
glom(1.0, (M > 100) | float)
|
| 46 |
+
|
| 47 |
+
assert Match(('a', 'b')).matches(('a', 'b', 'c')) is False
|
| 48 |
+
|
| 49 |
+
# test idiom for enum
|
| 50 |
+
with pytest.raises(MatchError):
|
| 51 |
+
glom("c", Match("a"))
|
| 52 |
+
glom("c", Not(Match("a")))
|
| 53 |
+
with pytest.raises(MatchError):
|
| 54 |
+
glom("c", Match(Or("a", "b")))
|
| 55 |
+
|
| 56 |
+
with pytest.raises(ValueError):
|
| 57 |
+
And()
|
| 58 |
+
|
| 59 |
+
with pytest.raises(TypeError):
|
| 60 |
+
And('a', bad_kwarg=True)
|
| 61 |
+
|
| 62 |
+
with pytest.raises(ValueError):
|
| 63 |
+
Or()
|
| 64 |
+
|
| 65 |
+
with pytest.raises(TypeError):
|
| 66 |
+
Or('a', bad_kwarg=True)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
_chk(Match(Or("a", "b")), "a", "c")
|
| 70 |
+
glom({None: 1}, Match({object: object}))
|
| 71 |
+
_chk(Match((int, str)), (1, "cat"), (1, 2))
|
| 72 |
+
with pytest.raises(MatchError):
|
| 73 |
+
glom({1: 2}, Match({(): int}))
|
| 74 |
+
with pytest.raises(MatchError):
|
| 75 |
+
glom(1, Match({}))
|
| 76 |
+
Match(M > 0).verify(1.0)
|
| 77 |
+
|
| 78 |
+
assert Match(M).matches(False) is False
|
| 79 |
+
assert Match(M).matches(True) is True
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_match_expressions():
|
| 83 |
+
assert glom(1, M == M) == 1
|
| 84 |
+
assert glom(1, M == 1) == 1
|
| 85 |
+
assert glom(1, M >= 1) == 1
|
| 86 |
+
assert glom(1, M <= 1) == 1
|
| 87 |
+
with pytest.raises(MatchError):
|
| 88 |
+
glom(1, M > 1)
|
| 89 |
+
with pytest.raises(MatchError):
|
| 90 |
+
glom(1, M < 1)
|
| 91 |
+
with pytest.raises(MatchError):
|
| 92 |
+
glom(1, M != 1)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_defaults():
|
| 96 |
+
assert glom(1, Match(2, default=3)) == 3
|
| 97 |
+
assert glom(1, Or(M == 2, default=3)) == 3
|
| 98 |
+
assert glom(1, And(M == 2, default=3)) == 3
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_match_default():
|
| 102 |
+
default = []
|
| 103 |
+
res = glom(None, Match(list, default=default))
|
| 104 |
+
assert res == default
|
| 105 |
+
default = []
|
| 106 |
+
res = glom(None, Match(list, default=Val(default)))
|
| 107 |
+
assert res is default
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_double_wrapping():
|
| 111 |
+
for outer in (Required, Optional):
|
| 112 |
+
with pytest.raises(TypeError):
|
| 113 |
+
outer(Optional('key'))
|
| 114 |
+
|
| 115 |
+
with pytest.raises(ValueError):
|
| 116 |
+
Required('key')
|
| 117 |
+
|
| 118 |
+
return
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def test_sets():
|
| 122 |
+
with pytest.raises(MatchError):
|
| 123 |
+
glom({1}, Match({}))
|
| 124 |
+
with pytest.raises(MatchError):
|
| 125 |
+
glom(frozenset([1]), Match(frozenset()))
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def test_m_call_match():
|
| 129 |
+
"""test that M __call__ can be used to wrap a subspec for comparison"""
|
| 130 |
+
target = {}
|
| 131 |
+
target['a'] = target
|
| 132 |
+
assert glom(target, M == M(T['a'])) == target
|
| 133 |
+
assert glom(target, M(T['a']) == M) == target
|
| 134 |
+
assert repr(M(T['a'])) == "M(T['a'])"
|
| 135 |
+
|
| 136 |
+
with pytest.raises(TypeError):
|
| 137 |
+
M('failure') # TODO: may change in future, see TODO in M.__call__
|
| 138 |
+
|
| 139 |
+
with pytest.raises(MatchError):
|
| 140 |
+
glom({'a': False}, M(T['a']))
|
| 141 |
+
|
| 142 |
+
# let's take the operators for a spin
|
| 143 |
+
valid_target_spec_pairs = [({'a': 1, 'b': 2}, M(T['a']) < M(T['b'])),
|
| 144 |
+
({'a': 2, 'b': 1}, M(T['a']) > M(T['b'])),
|
| 145 |
+
({'a': 2, 'b': 1}, M(T['a']) != M(T['b'])),
|
| 146 |
+
({'a': 2, 'b': 1}, M(T['a']) >= M(T['b'])),
|
| 147 |
+
({'a': 2, 'b': 2}, M(T['a']) >= M(T['b'])),
|
| 148 |
+
({'a': 2, 'b': 2}, M(T['a']) <= M(T['b'])),
|
| 149 |
+
({'a': 1, 'b': 2}, M(T['a']) <= M(T['b']))]
|
| 150 |
+
|
| 151 |
+
for target, spec in valid_target_spec_pairs:
|
| 152 |
+
assert glom(target, spec) is target
|
| 153 |
+
|
| 154 |
+
return
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def test_and_or_reduction():
|
| 158 |
+
and_spec = And(T['a'], T['b']) & T['c']
|
| 159 |
+
|
| 160 |
+
assert repr(and_spec) == "And(T['a'], T['b'], T['c'])"
|
| 161 |
+
|
| 162 |
+
or_spec = Or(T['a'], T['b']) | T['c']
|
| 163 |
+
|
| 164 |
+
assert repr(or_spec) == "Or(T['a'], T['b'], T['c'])"
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_precedence():
|
| 168 |
+
"""test corner cases of dict key precedence"""
|
| 169 |
+
glom({(0, 1): 3},
|
| 170 |
+
Match({
|
| 171 |
+
(0, 1): Val(1), # this should match
|
| 172 |
+
(0, int): Val(2), # optional
|
| 173 |
+
(0, M == 1): Val(3), # optional
|
| 174 |
+
})
|
| 175 |
+
)
|
| 176 |
+
with pytest.raises(ValueError):
|
| 177 |
+
Optional(int) # int is already optional so not valid to wrap
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_cruddy_json():
|
| 181 |
+
_chk(
|
| 182 |
+
Match({'int_id?': Auto((int, (M > 0)))}),
|
| 183 |
+
{'int_id?': '1'},
|
| 184 |
+
{'int_id?': '-1'})
|
| 185 |
+
# embed a build
|
| 186 |
+
squished_json = Match({
|
| 187 |
+
'smooshed_json': Auto(
|
| 188 |
+
(json.loads, Match({
|
| 189 |
+
'sub': Auto((json.loads, M == 1))})))
|
| 190 |
+
})
|
| 191 |
+
glom({'smooshed_json': json.dumps({'sub': json.dumps(1)})}, squished_json)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def test_pattern_matching():
|
| 195 |
+
pattern_matcher = Or(
|
| 196 |
+
And(Match(1), Val('one')),
|
| 197 |
+
And(Match(2), Val('two')),
|
| 198 |
+
And(Match(float), Val('float'))
|
| 199 |
+
)
|
| 200 |
+
assert glom(1, pattern_matcher) == 'one'
|
| 201 |
+
assert glom(1.1, pattern_matcher) == 'float'
|
| 202 |
+
|
| 203 |
+
# obligatory fibonacci
|
| 204 |
+
|
| 205 |
+
fib = (M > 2) & (lambda n: glom(n - 1, fib) + glom(n - 2, fib)) | T
|
| 206 |
+
|
| 207 |
+
assert glom(5, fib) == 8
|
| 208 |
+
|
| 209 |
+
factorial = (
|
| 210 |
+
lambda t: t + 1, Ref('fact', (
|
| 211 |
+
lambda t: t - 1,
|
| 212 |
+
(M == 0) & Fill(1) |
|
| 213 |
+
(S(r=Ref('fact')),
|
| 214 |
+
S, lambda s: s['r'] * s[T]))))
|
| 215 |
+
|
| 216 |
+
assert glom(4, factorial) == 4 * 3 * 2
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def test_examples():
|
| 220 |
+
assert glom(8, (M > 7) & Val(7)) == 7
|
| 221 |
+
assert glom(range(10), [(M > 7) & Val(7) | T]) == [0, 1, 2, 3, 4, 5, 6, 7, 7, 7]
|
| 222 |
+
assert glom(range(10), [(M > 7) & Val(SKIP) | T]) == [0, 1, 2, 3, 4, 5, 6, 7]
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def test_reprs():
|
| 226 |
+
repr(M)
|
| 227 |
+
repr(M == 1)
|
| 228 |
+
repr(M | M == 1)
|
| 229 |
+
repr(M & M == 1)
|
| 230 |
+
repr(~M)
|
| 231 |
+
repr(And(1, 2))
|
| 232 |
+
repr(Or(1, 2))
|
| 233 |
+
repr(Not(1))
|
| 234 |
+
repr(MatchError("uh oh"))
|
| 235 |
+
repr(TypeMatchError("uh oh {0}", dict))
|
| 236 |
+
assert repr(And(M == 1, float)) == "(M == 1) & float"
|
| 237 |
+
assert repr(eval(repr(And(M == 1, float)))) == "(M == 1) & float"
|
| 238 |
+
|
| 239 |
+
assert repr(Regex('[ab]')) == "Regex('[ab]')"
|
| 240 |
+
assert repr(Regex('[ab]', flags=1)) == "Regex('[ab]', flags=1)"
|
| 241 |
+
assert 'search' in repr(Regex('[ab]', func=re.search))
|
| 242 |
+
assert repr(And(1)) == 'And(1)'
|
| 243 |
+
assert repr(~And(1)) == 'Not(And(1))'
|
| 244 |
+
assert repr(~Or(M) & Or(M)) == '~(M) & M'
|
| 245 |
+
assert repr(Not(M < 3)) == '~(M < 3)'
|
| 246 |
+
assert repr(~(M < 4)) == '~(M < 4)'
|
| 247 |
+
assert repr(~M | "default") == "~M | 'default'"
|
| 248 |
+
assert repr(Or(M, default=1)) == "Or(M, default=1)"
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def test_shortcircuit():
|
| 252 |
+
assert glom(False, Fill(M | "default")) == "default"
|
| 253 |
+
assert glom(True, Fill(M | "default")) == True
|
| 254 |
+
assert glom(True, Fill(M & "default")) == "default"
|
| 255 |
+
with pytest.raises(MatchError):
|
| 256 |
+
glom(False, Fill(M & "default"))
|
| 257 |
+
assert glom(False, ~M) == False
|
| 258 |
+
assert glom(True, Fill(~M | "default")) == "default"
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def test_sample():
|
| 262 |
+
"""
|
| 263 |
+
test meant to cover a more realistic use
|
| 264 |
+
"""
|
| 265 |
+
import datetime
|
| 266 |
+
|
| 267 |
+
data = {
|
| 268 |
+
'name': 'item',
|
| 269 |
+
'date_added': datetime.datetime.now(),
|
| 270 |
+
'desc': 'a data item',
|
| 271 |
+
'tags': ['data', 'new'],
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
spec = Match({
|
| 275 |
+
'name': str,
|
| 276 |
+
Optional('date_added'): datetime.datetime,
|
| 277 |
+
'desc': str,
|
| 278 |
+
'tags': [str,]})
|
| 279 |
+
|
| 280 |
+
def good():
|
| 281 |
+
glom(data, spec)
|
| 282 |
+
def bad():
|
| 283 |
+
with pytest.raises(MatchError):
|
| 284 |
+
glom(data, spec)
|
| 285 |
+
|
| 286 |
+
good() # should match
|
| 287 |
+
del data['date_added']
|
| 288 |
+
good() # should still match w/out optional
|
| 289 |
+
del data['desc']
|
| 290 |
+
bad()
|
| 291 |
+
data['desc'] = 'a data item'
|
| 292 |
+
data['extra'] = 'will fail on extra'
|
| 293 |
+
bad()
|
| 294 |
+
spec.spec[str] = str # now extra str-key/str-val are okay
|
| 295 |
+
good()
|
| 296 |
+
data['extra2'] = 2 # but extra str-key/non-str-val are bad
|
| 297 |
+
bad()
|
| 298 |
+
# reset data
|
| 299 |
+
data = {
|
| 300 |
+
'name': 'item',
|
| 301 |
+
'date_added': datetime.datetime.now(),
|
| 302 |
+
'desc': 'a data item',
|
| 303 |
+
'tags': ['data', 'new'],
|
| 304 |
+
}
|
| 305 |
+
del spec.spec[str]
|
| 306 |
+
spec.spec[Required(str)] = str # now there MUST be at least one str
|
| 307 |
+
bad()
|
| 308 |
+
data['extra'] = 'extra'
|
| 309 |
+
good()
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def test_regex():
|
| 313 |
+
assert glom('abc', (Regex('(?P<test>.*)'), S['test'])) == 'abc'
|
| 314 |
+
# test wrong target type failure path
|
| 315 |
+
with pytest.raises(MatchError):
|
| 316 |
+
glom(1, Regex('1'))
|
| 317 |
+
# test invalid arg path
|
| 318 |
+
with pytest.raises(ValueError):
|
| 319 |
+
Regex(1, func="invalid")
|
| 320 |
+
# test explicit re match func and target value failure path
|
| 321 |
+
with pytest.raises(MatchError):
|
| 322 |
+
glom('aabcc', Regex('abc', func=re.match))
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def test_ternary():
|
| 326 |
+
assert glom('abc', Match(Or(None, 'abc'))) == 'abc'
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def test_sky():
|
| 330 |
+
"""test adapted from github.com/shopkick/opensky"""
|
| 331 |
+
|
| 332 |
+
def as_type(sub_schema, typ):
|
| 333 |
+
'after checking sub_schema, pass the result to typ()'
|
| 334 |
+
return And(sub_schema, Auto(typ))
|
| 335 |
+
|
| 336 |
+
assert glom('abc', as_type(M == 'abc', list)) == list('abc')
|
| 337 |
+
|
| 338 |
+
def none_or(sub_schema):
|
| 339 |
+
'allow None or sub_schema'
|
| 340 |
+
return Match(Or(None, sub_schema))
|
| 341 |
+
|
| 342 |
+
assert glom(None, none_or('abc')) == None
|
| 343 |
+
assert glom('abc', none_or('abc')) == 'abc'
|
| 344 |
+
with pytest.raises(MatchError):
|
| 345 |
+
glom(123, none_or('abc'))
|
| 346 |
+
|
| 347 |
+
def in_range(sub_schema, _min, _max):
|
| 348 |
+
'check that sub_schema is between _min and _max'
|
| 349 |
+
return Match(And(sub_schema, _min < M, M < _max))
|
| 350 |
+
# TODO: make _min < M < _max work
|
| 351 |
+
|
| 352 |
+
assert glom(1, in_range(int, 0, 2))
|
| 353 |
+
with pytest.raises(MatchError):
|
| 354 |
+
glom(-1, in_range(int, 0, 2))
|
| 355 |
+
|
| 356 |
+
def default_if_none(sub_schema, default_factory):
|
| 357 |
+
return Or(
|
| 358 |
+
And(M == None, Auto(lambda t: default_factory())), sub_schema)
|
| 359 |
+
|
| 360 |
+
assert glom(1, default_if_none(T, list)) == 1
|
| 361 |
+
assert glom(None, default_if_none(T, list)) == []
|
| 362 |
+
|
| 363 |
+
def nullable_list_of(*items):
|
| 364 |
+
return default_if_none(Match(list(items)), list)
|
| 365 |
+
|
| 366 |
+
assert glom(None, nullable_list_of(str)) == []
|
| 367 |
+
assert glom(['a'], nullable_list_of(str)) == ['a']
|
| 368 |
+
with pytest.raises(MatchError):
|
| 369 |
+
glom([1], nullable_list_of(str))
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def test_clamp():
|
| 373 |
+
assert glom(range(10), [(M < 7) | Val(7)]) == [0, 1, 2, 3, 4, 5, 6, 7, 7, 7]
|
| 374 |
+
assert glom(range(10), [(M < 7) | Val(SKIP)]) == [0, 1, 2, 3, 4, 5, 6]
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def test_json_ref():
|
| 378 |
+
assert glom(
|
| 379 |
+
{'a': {'b': [0, 1]}},
|
| 380 |
+
Ref('json',
|
| 381 |
+
Match(Or(
|
| 382 |
+
And(dict, {Ref('json'): Ref('json')}),
|
| 383 |
+
And(list, [Ref('json')]),
|
| 384 |
+
And(0, Val(None)),
|
| 385 |
+
object)))) == {'a': {'b': [None, 1]}}
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def test_nested_struct():
|
| 389 |
+
"""adapted from use case"""
|
| 390 |
+
import json
|
| 391 |
+
|
| 392 |
+
_json = lambda spec: Auto((json.loads, _str_json, Match(spec)))
|
| 393 |
+
|
| 394 |
+
_str_json = Ref('json',
|
| 395 |
+
Match(Or(
|
| 396 |
+
And(dict, {Ref('json'): Ref('json')}),
|
| 397 |
+
And(list, [Ref('json')]),
|
| 398 |
+
And(str, Auto(str)),
|
| 399 |
+
object)))
|
| 400 |
+
|
| 401 |
+
rule_spec = Match({
|
| 402 |
+
'rule_id': Or('', Regex(r'\d+')),
|
| 403 |
+
'rule_name': str,
|
| 404 |
+
'effect': Or('approve', 'custom_approvers'),
|
| 405 |
+
'rule_approvers': _json([{'pk': int, 'level': int}]),
|
| 406 |
+
'rule_data': _json([ # list of condition-objects
|
| 407 |
+
{
|
| 408 |
+
Optional('value', 'null'): _json(
|
| 409 |
+
Or(None, int, float, str, [int, float, str])),
|
| 410 |
+
'field': Auto(int), # id of row from FilterField
|
| 411 |
+
'operator': str, # corresponds to FilterOperator.display_name
|
| 412 |
+
}]),
|
| 413 |
+
Optional('save_as_new', False): Or(str, bool),
|
| 414 |
+
})
|
| 415 |
+
|
| 416 |
+
rule = dict(
|
| 417 |
+
rule_id='1',
|
| 418 |
+
rule_name='test rule',
|
| 419 |
+
effect='approve',
|
| 420 |
+
rule_approvers=json.dumps([{'pk': 2, 'level': 1}]),
|
| 421 |
+
rule_data=json.dumps([
|
| 422 |
+
{'value': json.dumps([1, 2]), 'field': 2, 'operator': '>'},
|
| 423 |
+
{'field': 2, 'operator': '=='}])
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
glom(rule, rule_spec)
|
| 427 |
+
rule['save_as_new'] = 'true'
|
| 428 |
+
glom(rule, rule_spec)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def test_check_ported_tests():
|
| 432 |
+
"""
|
| 433 |
+
Tests ported from Check() to make sure all the functionality has an analogue.
|
| 434 |
+
"""
|
| 435 |
+
target = [{'id': 0}, {'id': 1}, {'id': 2}]
|
| 436 |
+
|
| 437 |
+
# check that skipping non-passing values works
|
| 438 |
+
assert glom(target, [Coalesce(M(T['id']) == 0, default=SKIP)]) == [{'id': 0}]
|
| 439 |
+
|
| 440 |
+
# TODO: should M(subspec, default='') work? I lean no.
|
| 441 |
+
# NB: this is not a very idiomatic use of Match, just brought over for Check reasons
|
| 442 |
+
assert glom(target, [Match({'id': And(int, M == 1)}, default=SKIP)]) == [{'id': 1}]
|
| 443 |
+
assert glom(target, [Match({'id': And(int, M <= 1)}, default=STOP)]) == [{'id': 0}, {'id': 1}]
|
| 444 |
+
|
| 445 |
+
# check that stopping chain execution on non-passing values works
|
| 446 |
+
spec = (Or(Match(len), Val(STOP)), T[0])
|
| 447 |
+
assert glom('hello', spec, glom_debug=True) == 'h'
|
| 448 |
+
assert glom('', spec) == '' # would fail with IndexError if STOP didn't work
|
| 449 |
+
|
| 450 |
+
target = [1, 'a']
|
| 451 |
+
assert glom(target, [Match(unicode, default=SKIP)]) == ['a']
|
| 452 |
+
assert glom(target, Match([Or(unicode, int)])) == [1, 'a']
|
| 453 |
+
|
| 454 |
+
target = ['1']
|
| 455 |
+
assert glom(target, [(M(T), int)]) == [1]
|
| 456 |
+
assert glom(target, M(T)) == ['1']
|
| 457 |
+
|
| 458 |
+
failing_checks = [({'a': {'b': 1}}, {'a': ('a', 'b', Match(str))},
|
| 459 |
+
'''expected type str, not int'''), # TODO: bbrepr at least, maybe include path like Check did
|
| 460 |
+
({'a': {'b': 1}}, {'a': ('a', Match({'b': str}))},
|
| 461 |
+
'''expected type str, not int'''), # TODO: include subspec path ('b')
|
| 462 |
+
(1, Match(Or(unicode, bool))),
|
| 463 |
+
(1, Match(unicode)),
|
| 464 |
+
(1, Match(0)),
|
| 465 |
+
(1, Match(Or(0, 2))),
|
| 466 |
+
('-3.14', Match(lambda x: int(x) > 0)),
|
| 467 |
+
# ('-3.14', M(lambda x: int(x) > 0)),
|
| 468 |
+
# TODO: M doesn't behave quite like Match because it's mode-free
|
| 469 |
+
]
|
| 470 |
+
|
| 471 |
+
for fc in failing_checks:
|
| 472 |
+
if len(fc) == 2:
|
| 473 |
+
target, check = fc
|
| 474 |
+
msg = None
|
| 475 |
+
else:
|
| 476 |
+
target, check, msg = fc
|
| 477 |
+
|
| 478 |
+
with pytest.raises(MatchError) as exc_info:
|
| 479 |
+
glom(target, check)
|
| 480 |
+
|
| 481 |
+
if msg is not None:
|
| 482 |
+
actual_msg = str(exc_info.value)
|
| 483 |
+
assert actual_msg.find(msg) != -1
|
| 484 |
+
assert repr(exc_info.value)
|
| 485 |
+
|
| 486 |
+
return
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def test_switch():
|
| 490 |
+
data = {'a': 1, 'b': 2}
|
| 491 |
+
cases = [('c', lambda t: 3), ('a', 'a')]
|
| 492 |
+
cases2 = dict(cases)
|
| 493 |
+
assert glom(data, Switch(cases)) == 1
|
| 494 |
+
assert glom(data, Switch(cases2)) == 1
|
| 495 |
+
assert glom({'c': None}, Switch(cases)) == 3
|
| 496 |
+
assert glom({'c': None}, Switch(cases2)) == 3
|
| 497 |
+
assert glom(None, Switch(cases, default=4)) == 4
|
| 498 |
+
assert glom(None, Switch({'z': 26}, default=4)) == 4
|
| 499 |
+
with pytest.raises(MatchError):
|
| 500 |
+
glom(None, Switch(cases))
|
| 501 |
+
with pytest.raises(ValueError):
|
| 502 |
+
Switch({})
|
| 503 |
+
with pytest.raises(TypeError):
|
| 504 |
+
Switch("wrong type")
|
| 505 |
+
assert glom(None, Switch({S(a=1): S['a']})) == 1
|
| 506 |
+
repr(Switch(cases))
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
def test_nested_dict():
|
| 510 |
+
assert glom({1: 2}, Match({A.t: S.t})) == {1: 1}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_mutation.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from glom import glom, Path, T, S, Spec, Glommer, PathAssignError, PathAccessError
|
| 4 |
+
from glom import assign, Assign, delete, Delete, PathDeleteError, Or
|
| 5 |
+
from glom import core
|
| 6 |
+
from glom.core import UnregisteredTarget
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_assign():
|
| 10 |
+
class Foo:
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
assert glom({}, Assign(T['a'], 1)) == {'a': 1}
|
| 14 |
+
assert glom({'a': {}}, Assign(T['a']['a'], 1)) == {'a': {'a': 1}}
|
| 15 |
+
assert glom({'a': {}}, Assign('a.a', 1)) == {'a': {'a': 1}}
|
| 16 |
+
assert glom(Foo(), Assign(T.a, 1)).a == 1
|
| 17 |
+
assert glom({}, Assign('a', 1)) == {'a': 1}
|
| 18 |
+
assert glom(Foo(), Assign('a', 1)).a == 1
|
| 19 |
+
assert glom({'a': Foo()}, Assign('a.a', 1))['a'].a == 1
|
| 20 |
+
def r():
|
| 21 |
+
r = {}
|
| 22 |
+
r['r'] = r
|
| 23 |
+
return r
|
| 24 |
+
assert glom(r(), Assign('r.r.r.r.r.r.r.r.r', 1)) == {'r': 1}
|
| 25 |
+
assert glom(r(), Assign(T['r']['r']['r']['r'], 1)) == {'r': 1}
|
| 26 |
+
assert glom(r(), Assign(Path('r', 'r', T['r']), 1)) == {'r': 1}
|
| 27 |
+
assert assign(r(), Path('r', 'r', T['r']), 1) == {'r': 1}
|
| 28 |
+
with pytest.raises(TypeError, match='path argument must be'):
|
| 29 |
+
Assign(1, 'a')
|
| 30 |
+
with pytest.raises(ValueError, match='path must have at least one element'):
|
| 31 |
+
Assign(T, 1)
|
| 32 |
+
|
| 33 |
+
assert repr(Assign(T.a, 1)) == 'Assign(T.a, 1)'
|
| 34 |
+
assign_spec = Assign(T.a, 1, missing=dict)
|
| 35 |
+
assert repr(assign_spec) == "Assign(T.a, 1, missing=dict)"
|
| 36 |
+
assert repr(assign_spec) == repr(eval(repr(assign_spec)))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_assign_recursive():
|
| 40 |
+
val = {}
|
| 41 |
+
val[1] = [val]
|
| 42 |
+
recur_out = glom({}, Assign(T['a'], val))['a']
|
| 43 |
+
assert recur_out[1][0] is recur_out
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_assign_spec_val():
|
| 47 |
+
output = glom({'b': 'c'}, Assign('a', Spec('b')))
|
| 48 |
+
assert output['a'] == output['b'] == 'c'
|
| 49 |
+
output = glom({'b': 'c'}, Assign('a', Or('d', 'b')))
|
| 50 |
+
assert output['a'] == output['b'] == 'c'
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_unregistered_assign():
|
| 54 |
+
# test with bare target registry
|
| 55 |
+
glommer = Glommer(register_default_types=False)
|
| 56 |
+
|
| 57 |
+
with pytest.raises(UnregisteredTarget, match='assign'):
|
| 58 |
+
glommer.glom({}, Assign('a', 'b'))
|
| 59 |
+
|
| 60 |
+
# test for unassignable tuple
|
| 61 |
+
with pytest.raises(UnregisteredTarget, match='assign'):
|
| 62 |
+
glom({'a': ()}, Assign('a.0', 'b'))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_bad_assign_target():
|
| 66 |
+
class BadTarget:
|
| 67 |
+
def __setattr__(self, name, val):
|
| 68 |
+
raise Exception("and you trusted me?")
|
| 69 |
+
|
| 70 |
+
# sanity check
|
| 71 |
+
spec = Assign('a', 'b')
|
| 72 |
+
ok_target = lambda: None
|
| 73 |
+
glom(ok_target, spec)
|
| 74 |
+
assert ok_target.a == 'b'
|
| 75 |
+
|
| 76 |
+
with pytest.raises(PathAssignError, match='could not assign'):
|
| 77 |
+
glom(BadTarget(), spec)
|
| 78 |
+
|
| 79 |
+
with pytest.raises(PathAccessError, match='could not access'):
|
| 80 |
+
assign({}, 'a.b.c', 'moot')
|
| 81 |
+
return
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_sequence_assign():
|
| 85 |
+
target = {'alist': [0, 1, 2]}
|
| 86 |
+
assign(target, 'alist.2', 3)
|
| 87 |
+
assert target['alist'][2] == 3
|
| 88 |
+
|
| 89 |
+
with pytest.raises(PathAssignError, match='could not assign') as exc_info:
|
| 90 |
+
assign(target, 'alist.3', 4)
|
| 91 |
+
|
| 92 |
+
# the following test is because pypy's IndexError is different than CPython's:
|
| 93 |
+
# E - PathAssignError(IndexError('list index out of range',), Path('alist'), '3')
|
| 94 |
+
# E + PathAssignError(IndexError('list assignment index out of range',), Path('alist'), '3')
|
| 95 |
+
# E ? +++++++++++
|
| 96 |
+
|
| 97 |
+
exc_repr = repr(exc_info.value)
|
| 98 |
+
assert exc_repr.startswith('PathAssignError(')
|
| 99 |
+
assert exc_repr.endswith("'3')")
|
| 100 |
+
return
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_invalid_assign_op_target():
|
| 104 |
+
target = {'afunc': lambda x: 'hi %s' % x}
|
| 105 |
+
spec = T['afunc'](x=1)
|
| 106 |
+
|
| 107 |
+
with pytest.raises(ValueError):
|
| 108 |
+
assign(target, spec, None)
|
| 109 |
+
return
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def test_assign_missing_signature():
|
| 113 |
+
# test signature (non-callable missing hook)
|
| 114 |
+
with pytest.raises(TypeError, match='callable'):
|
| 115 |
+
assign({}, 'a.b.c', 'lol', missing='invalidbcnotcallable')
|
| 116 |
+
return
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_assign_missing_dict():
|
| 120 |
+
target = {}
|
| 121 |
+
val = object()
|
| 122 |
+
|
| 123 |
+
from itertools import count
|
| 124 |
+
counter = count()
|
| 125 |
+
def debugdict():
|
| 126 |
+
ret = dict()
|
| 127 |
+
#ret['id'] = id(ret)
|
| 128 |
+
#ret['inc'] = counter.next()
|
| 129 |
+
return ret
|
| 130 |
+
|
| 131 |
+
assign(target, 'a.b.c.d', val, missing=debugdict)
|
| 132 |
+
|
| 133 |
+
assert target == {'a': {'b': {'c': {'d': val}}}}
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_assign_missing_object():
|
| 137 |
+
val = object()
|
| 138 |
+
class Container:
|
| 139 |
+
pass
|
| 140 |
+
|
| 141 |
+
target = Container()
|
| 142 |
+
target.a = extant_a = Container()
|
| 143 |
+
assign(target, 'a.b.c.d', val, missing=Container)
|
| 144 |
+
|
| 145 |
+
assert target.a.b.c.d is val
|
| 146 |
+
assert target.a is extant_a # make sure we didn't overwrite anything on the path
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_assign_missing_with_extant_keys():
|
| 150 |
+
"""This test ensures that assign with missing doesn't overwrite
|
| 151 |
+
perfectly fine extant keys that are along the path it needs to
|
| 152 |
+
assign to. call count is also checked to make sure missing() isn't
|
| 153 |
+
invoked too many times.
|
| 154 |
+
|
| 155 |
+
"""
|
| 156 |
+
target = {}
|
| 157 |
+
value = object()
|
| 158 |
+
default_struct = {'b': {'c': {}}}
|
| 159 |
+
|
| 160 |
+
call_count = [0]
|
| 161 |
+
|
| 162 |
+
def _get_default_struct():
|
| 163 |
+
call_count[0] += 1 # make sure this is only called once
|
| 164 |
+
return default_struct
|
| 165 |
+
|
| 166 |
+
assign(target, 'a.b.c', value, missing=_get_default_struct)
|
| 167 |
+
|
| 168 |
+
assert target['a']['b']['c'] is value
|
| 169 |
+
assert target['a']['b'] is default_struct['b']
|
| 170 |
+
assert call_count == [1]
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def test_assign_missing_unassignable():
|
| 174 |
+
"""Check that the final assignment to the target object comes last,
|
| 175 |
+
ensuring that failed assignments don't leave targets in a bad
|
| 176 |
+
state.
|
| 177 |
+
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
class Tarjay:
|
| 181 |
+
init_count = 0
|
| 182 |
+
def __init__(self):
|
| 183 |
+
self.__class__.init_count += 1
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def unassignable(self):
|
| 187 |
+
return
|
| 188 |
+
|
| 189 |
+
value = object()
|
| 190 |
+
target = {"preexisting": "ok"}
|
| 191 |
+
|
| 192 |
+
with pytest.raises(PathAssignError):
|
| 193 |
+
assign(target, 'tarjay.unassignable.a.b.c', value, missing=Tarjay)
|
| 194 |
+
|
| 195 |
+
assert target == {'preexisting': 'ok'}
|
| 196 |
+
|
| 197 |
+
# why 3? "c" gets the value of "value", while "b", "a", and
|
| 198 |
+
# "tarjay" all succeed and are set to Tarjay instances. Then
|
| 199 |
+
# unassignable is already present, but not possible to assign to,
|
| 200 |
+
# raising the PathAssignError.
|
| 201 |
+
assert Tarjay.init_count == 3
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_s_assign():
|
| 205 |
+
'''
|
| 206 |
+
check that assign works when storing things into S
|
| 207 |
+
'''
|
| 208 |
+
assert glom({}, (Assign(S['foo'], 'bar'), S['foo'])) == 'bar'
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def test_delete():
|
| 212 |
+
class Foo:
|
| 213 |
+
def __init__(self, d=None):
|
| 214 |
+
for k, v in d.items():
|
| 215 |
+
setattr(self, k, v)
|
| 216 |
+
|
| 217 |
+
assert glom({'a': 1}, Delete(T['a'])) == {}
|
| 218 |
+
assert glom({'a': {'a': 1}}, Delete(T['a']['a'])) == {'a': {}}
|
| 219 |
+
assert glom({'a': {'a': 1}}, Delete('a.a')) == {'a': {}}
|
| 220 |
+
assert not hasattr(glom(Foo({'a': 1}), Delete(T.a)), 'a')
|
| 221 |
+
assert glom({'a': 1}, Delete('a')) == {}
|
| 222 |
+
assert not hasattr(glom(Foo({'a': 1}), Delete('a')), 'a')
|
| 223 |
+
assert not hasattr(glom({'a': Foo({'a': 1})}, Delete('a.a'))['a'], 'a')
|
| 224 |
+
|
| 225 |
+
def r():
|
| 226 |
+
r = {}
|
| 227 |
+
r['r'] = r
|
| 228 |
+
return r
|
| 229 |
+
|
| 230 |
+
assert glom(r(), Delete('r.r.r.r.r.r.r.r.r')) == {}
|
| 231 |
+
assert glom(r(), Delete(T['r']['r']['r']['r'])) == {}
|
| 232 |
+
assert glom(r(), Delete(Path('r', 'r', T['r']))) == {}
|
| 233 |
+
assert delete(r(), Path('r', 'r', T['r'])) == {}
|
| 234 |
+
with pytest.raises(TypeError, match='path argument must be'):
|
| 235 |
+
Delete(1, 'a')
|
| 236 |
+
with pytest.raises(ValueError, match='path must have at least one element'):
|
| 237 |
+
Delete(T, 1)
|
| 238 |
+
|
| 239 |
+
assert repr(Delete(T.a)) == 'Delete(T.a)'
|
| 240 |
+
|
| 241 |
+
# test delete from scope
|
| 242 |
+
assert glom(1, (S(x=T), S['x'])) == 1
|
| 243 |
+
with pytest.raises(PathAccessError):
|
| 244 |
+
glom(1, (S(x=T), Delete(S['x']), S['x']))
|
| 245 |
+
|
| 246 |
+
# test raising on missing parent
|
| 247 |
+
with pytest.raises(PathAccessError):
|
| 248 |
+
glom({}, Delete(T['a']['b']))
|
| 249 |
+
|
| 250 |
+
# test raising on missing index
|
| 251 |
+
with pytest.raises(PathDeleteError):
|
| 252 |
+
glom([], Delete(T[0]))
|
| 253 |
+
target = []
|
| 254 |
+
assert glom(target, Delete(T[0], ignore_missing=True)) is target
|
| 255 |
+
|
| 256 |
+
# test raising on missing attr
|
| 257 |
+
with pytest.raises(PathDeleteError):
|
| 258 |
+
glom(object(), Delete(T.does_not_exist))
|
| 259 |
+
target = object()
|
| 260 |
+
assert glom(target, Delete(T.does_not_exist, ignore_missing=True)) is target
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def test_unregistered_delete():
|
| 264 |
+
glommer = Glommer(register_default_types=False)
|
| 265 |
+
|
| 266 |
+
with pytest.raises(UnregisteredTarget, match='delete'):
|
| 267 |
+
glommer.glom({'a': 1}, Delete('a'))
|
| 268 |
+
|
| 269 |
+
with pytest.raises(UnregisteredTarget, match='delete'):
|
| 270 |
+
glom({'a': (1,)}, Delete('a.0'))
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def test_bad_delete_target():
|
| 274 |
+
class BadTarget:
|
| 275 |
+
def __delattr__(self, name):
|
| 276 |
+
raise Exception("and you trusted me?")
|
| 277 |
+
|
| 278 |
+
spec = Delete('a')
|
| 279 |
+
ok_target = lambda: None
|
| 280 |
+
ok_target.a = 1
|
| 281 |
+
glom(ok_target, spec)
|
| 282 |
+
assert not hasattr(ok_target, 'a')
|
| 283 |
+
|
| 284 |
+
with pytest.raises(PathDeleteError, match='could not delete'):
|
| 285 |
+
glom(BadTarget(), spec)
|
| 286 |
+
|
| 287 |
+
with pytest.raises(PathDeleteError, match='could not delete'):
|
| 288 |
+
delete({}, 'a')
|
| 289 |
+
return
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def test_sequence_delete():
|
| 293 |
+
target = {'alist': [0, 1, 2]}
|
| 294 |
+
delete(target, 'alist.1')
|
| 295 |
+
assert target['alist'] == [0, 2]
|
| 296 |
+
|
| 297 |
+
with pytest.raises(PathDeleteError, match='could not delete') as exc_info:
|
| 298 |
+
delete(target, 'alist.2')
|
| 299 |
+
|
| 300 |
+
exc_repr = repr(exc_info.value)
|
| 301 |
+
assert exc_repr.startswith('PathDeleteError(')
|
| 302 |
+
assert exc_repr.endswith("'2')")
|
| 303 |
+
return
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def test_invalid_delete_op_target():
|
| 307 |
+
target = {'afunc': lambda x: 'hi %s' % x}
|
| 308 |
+
spec = T['afunc'](x=1)
|
| 309 |
+
|
| 310 |
+
with pytest.raises(ValueError):
|
| 311 |
+
delete(target, spec, None)
|
| 312 |
+
return
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def test_delete_ignore_missing():
|
| 316 |
+
assert delete({}, 'a', ignore_missing=True) == {}
|
| 317 |
+
assert delete({}, 'a.b', ignore_missing=True) == {}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def test_star_broadcast():
|
| 321 |
+
val = {'a': [{'b': [{'c': 1}, {'c': 2}, {'c': 3}]}]}
|
| 322 |
+
assert glom(val, (Assign('a.*.b.*.d', 'a'), 'a.*.b.*.d')) == [['a', 'a', 'a']]
|
| 323 |
+
glom(val, Delete('a.*.b.*.d'))
|
| 324 |
+
assert 'c' in val['a'][0]['b'][0]
|
| 325 |
+
assert 'd' not in val['a'][0]['b'][0]
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_path_and_t.py
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
|
| 3 |
+
from glom import glom, Path, S, T, A, PathAccessError, GlomError, BadSpec, Or, Assign, Delete
|
| 4 |
+
from glom import core
|
| 5 |
+
|
| 6 |
+
def test_list_path_access():
|
| 7 |
+
assert glom(list(range(10)), Path(1)) == 1
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_path():
|
| 11 |
+
_obj = object()
|
| 12 |
+
target = {'a': {'b.b': [None, {_obj: [None, None, 'd']}]}}
|
| 13 |
+
|
| 14 |
+
assert glom(target, Path('a', 'b.b', 1, _obj, -1)) == 'd'
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_empty_path_access():
|
| 18 |
+
target = {}
|
| 19 |
+
|
| 20 |
+
assert glom(target, Path()) is target
|
| 21 |
+
assert glom(target, (Path(), Path(), Path())) is target
|
| 22 |
+
|
| 23 |
+
dup_dict = glom(target, {'target': Path(),
|
| 24 |
+
'target2': Path()})
|
| 25 |
+
dup_dict['target'] is target
|
| 26 |
+
dup_dict['target2'] is target
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_path_t_roundtrip():
|
| 30 |
+
# check that T repr roundrips
|
| 31 |
+
assert repr(T['a'].b.c()) == "T['a'].b.c()"
|
| 32 |
+
assert repr(T[1:]) == "T[1:]"
|
| 33 |
+
assert repr(T[::3, 1:, 1:2, :2:3]) == "T[::3, 1:, 1:2, :2:3]"
|
| 34 |
+
|
| 35 |
+
# check that Path repr roundtrips
|
| 36 |
+
assert repr(Path('a', 1, 'b.b', -1.0)) == "Path('a', 1, 'b.b', -1.0)"
|
| 37 |
+
|
| 38 |
+
# check that Path repr roundtrips when it contains Ts
|
| 39 |
+
assert repr(Path(T['a'].b, 'c', T['d'].e)) == "Path(T['a'].b, 'c', T['d'].e)"
|
| 40 |
+
|
| 41 |
+
# check that T instances containing Path access revert to repring with Path
|
| 42 |
+
assert repr(Path(T['a'].b, 'c', T['d'].e).path_t) == "Path(T['a'].b, 'c', T['d'].e)"
|
| 43 |
+
|
| 44 |
+
# check that Paths containing only T objects reduce to a T (joining the T objects)
|
| 45 |
+
assert repr(Path(T['a'].b, T.c())) == "T['a'].b.c()"
|
| 46 |
+
|
| 47 |
+
# check that multiple nested paths reduce
|
| 48 |
+
assert repr(Path(Path(Path('a')))) == "Path('a')"
|
| 49 |
+
|
| 50 |
+
# check builtin repr
|
| 51 |
+
assert repr(T[len]) == 'T[len]'
|
| 52 |
+
assert repr(T.func(len, sum)) == 'T.func(len, sum)'
|
| 53 |
+
|
| 54 |
+
# check * and **
|
| 55 |
+
assert repr(T.__star__().__starstar__()) == 'T.__star__().__starstar__()'
|
| 56 |
+
assert repr(Path('a', T.__star__().__starstar__())) == "Path('a', T.__star__().__starstar__())"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def test_path_access_error_message():
|
| 60 |
+
|
| 61 |
+
# test fuzzy access
|
| 62 |
+
with raises(GlomError) as exc_info:
|
| 63 |
+
glom({}, 'a.b')
|
| 64 |
+
assert ("PathAccessError: could not access 'a', part 0 of Path('a', 'b'), got error: KeyError"
|
| 65 |
+
in exc_info.exconly())
|
| 66 |
+
ke = repr(KeyError('a')) # py3.7+ changed the keyerror repr
|
| 67 |
+
assert repr(exc_info.value) == "PathAccessError(" + ke + ", Path('a', 'b'), 0)"
|
| 68 |
+
|
| 69 |
+
# test multi-part Path with T, catchable as a KeyError
|
| 70 |
+
with raises(KeyError) as exc_info:
|
| 71 |
+
# don't actually use glom to copy your data structures please
|
| 72 |
+
glom({'a': {'b': 'c'}}, Path('a', T.copy(), 'd'))
|
| 73 |
+
assert ("PathAccessError: could not access 'd', part 3 of Path('a', T.copy(), 'd'), got error: KeyError"
|
| 74 |
+
in exc_info.exconly())
|
| 75 |
+
ke = repr(KeyError('d')) # py3.7+ changed the keyerror repr
|
| 76 |
+
assert repr(exc_info.value) == "PathAccessError(" + ke + ", Path('a', T.copy(), 'd'), 3)"
|
| 77 |
+
|
| 78 |
+
# test AttributeError
|
| 79 |
+
with raises(GlomError) as exc_info:
|
| 80 |
+
glom({'a': {'b': 'c'}}, Path('a', T.b))
|
| 81 |
+
assert ("PathAccessError: could not access 'b', part 1 of Path('a', T.b), got error: AttributeError"
|
| 82 |
+
in exc_info.exconly())
|
| 83 |
+
ae = repr(AttributeError("'dict' object has no attribute 'b'"))
|
| 84 |
+
assert repr(exc_info.value) == "PathAccessError(" + ae + ", Path(\'a\', T.b), 1)"
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def test_t_picklability():
|
| 88 |
+
import pickle
|
| 89 |
+
|
| 90 |
+
class TargetType:
|
| 91 |
+
def __init__(self):
|
| 92 |
+
self.attribute = lambda: None
|
| 93 |
+
self.attribute.method = lambda: {'key': lambda x: x * 2}
|
| 94 |
+
|
| 95 |
+
spec = T.attribute.method()['key'](x=5)
|
| 96 |
+
|
| 97 |
+
rt_spec = pickle.loads(pickle.dumps(spec))
|
| 98 |
+
assert repr(spec) == repr(rt_spec)
|
| 99 |
+
|
| 100 |
+
assert glom(TargetType(), spec) == 10
|
| 101 |
+
|
| 102 |
+
s_spec = S.attribute
|
| 103 |
+
assert repr(s_spec) == repr(pickle.loads(pickle.dumps(s_spec)))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_t_subspec():
|
| 107 |
+
# tests that arg-mode is a min-mode, allowing for
|
| 108 |
+
# other specs to be embedded inside T calls
|
| 109 |
+
data = [
|
| 110 |
+
{'id': 1},
|
| 111 |
+
{'pk': 1}]
|
| 112 |
+
|
| 113 |
+
get_ids = (
|
| 114 |
+
S(id_type=int),
|
| 115 |
+
[S.id_type(Or('id', 'pk'))])
|
| 116 |
+
|
| 117 |
+
assert glom(data, get_ids) == [1, 1]
|
| 118 |
+
|
| 119 |
+
data = {'a': 1, 'b': 2, 'c': 3}
|
| 120 |
+
|
| 121 |
+
# test that "shallow" data structures translate as-is
|
| 122 |
+
get_vals = (
|
| 123 |
+
S(seq_type=tuple),
|
| 124 |
+
S.seq_type([T['a'], T['b'], Or('c', 'd')])
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
assert glom(data, get_vals) == (1, 2, 3)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def test_a_forbidden():
|
| 131 |
+
with raises(BadSpec):
|
| 132 |
+
A() # cannot assign to function call
|
| 133 |
+
with raises(BadSpec):
|
| 134 |
+
glom(1, A) # cannot assign without destination
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def test_s_magic():
|
| 138 |
+
assert glom(None, S.test, scope={'test': 'value'}) == 'value'
|
| 139 |
+
|
| 140 |
+
with raises(PathAccessError):
|
| 141 |
+
glom(1, S.a) # ref to 'a' which doesn't exist in scope
|
| 142 |
+
|
| 143 |
+
with raises(PathAccessError):
|
| 144 |
+
glom(1, A.b.c)
|
| 145 |
+
|
| 146 |
+
return
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_path_len():
|
| 150 |
+
|
| 151 |
+
assert len(Path()) == 0
|
| 152 |
+
assert len(Path('a', 'b', 'c')) == 3
|
| 153 |
+
assert len(Path.from_text('1.2.3.4')) == 4
|
| 154 |
+
|
| 155 |
+
assert len(Path(T)) == 0
|
| 156 |
+
assert len(Path(T.a.b.c)) == 3
|
| 157 |
+
assert len(Path(T.a()['b'].c.d)) == 5
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def test_path_getitem():
|
| 161 |
+
path = Path(T.a.b.c)
|
| 162 |
+
|
| 163 |
+
assert path[0] == Path(T.a)
|
| 164 |
+
assert path[1] == Path(T.b)
|
| 165 |
+
assert path[2] == Path(T.c)
|
| 166 |
+
assert path[-1] == Path(T.c)
|
| 167 |
+
assert path[-2] == Path(T.b)
|
| 168 |
+
|
| 169 |
+
with raises(IndexError, match='Path index out of range'):
|
| 170 |
+
path[4]
|
| 171 |
+
|
| 172 |
+
with raises(IndexError, match='Path index out of range'):
|
| 173 |
+
path[-14]
|
| 174 |
+
return
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def test_path_slices():
|
| 178 |
+
path = Path(T.a.b, 1, 2, T(test='yes'))
|
| 179 |
+
|
| 180 |
+
assert path[::] == path
|
| 181 |
+
|
| 182 |
+
# positive indices
|
| 183 |
+
assert path[3:] == Path(2, T(test='yes'))
|
| 184 |
+
assert path[1:3] == Path(T.b, 1)
|
| 185 |
+
assert path[:3] == Path(T.a.b, 1)
|
| 186 |
+
|
| 187 |
+
# positive indices backwards
|
| 188 |
+
assert path[2:1] == Path()
|
| 189 |
+
|
| 190 |
+
# negative indices forward
|
| 191 |
+
assert path[-1:] == Path(T(test='yes'))
|
| 192 |
+
assert path[:-2] == Path(T.a.b, 1)
|
| 193 |
+
assert path[-3:-1] == Path(1, 2)
|
| 194 |
+
|
| 195 |
+
# negative indices backwards
|
| 196 |
+
assert path[-1:-3] == Path()
|
| 197 |
+
|
| 198 |
+
# slicing and stepping
|
| 199 |
+
assert path[1::2] == Path(T.b, 2)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def test_path_values():
|
| 203 |
+
path = Path(T.a.b, 1, 2, T(test='yes'))
|
| 204 |
+
|
| 205 |
+
assert path.values() == ('a', 'b', 1, 2, ((), {'test': 'yes'}))
|
| 206 |
+
|
| 207 |
+
assert Path().values() == ()
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_path_items():
|
| 211 |
+
path = Path(T.a, 1, 2, T(test='yes'))
|
| 212 |
+
|
| 213 |
+
assert path.items() == (('.', 'a'),
|
| 214 |
+
('P', 1), ('P', 2),
|
| 215 |
+
('(', ((), {'test': 'yes'})))
|
| 216 |
+
|
| 217 |
+
assert Path().items() == ()
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def test_path_star():
|
| 221 |
+
val = {'a': [1, 2, 3]}
|
| 222 |
+
assert glom(val, 'a.*') == [1, 2, 3]
|
| 223 |
+
val['a'] = [{'b': v} for v in val['a']]
|
| 224 |
+
assert glom(val, 'a.*.b') == [1, 2, 3]
|
| 225 |
+
assert glom(val, T['a'].__star__()['b']) == [1, 2, 3]
|
| 226 |
+
assert glom(val, Path('a', T.__star__(), 'b')) == [1, 2, 3]
|
| 227 |
+
# multi-paths eat errors
|
| 228 |
+
assert glom(val, Path('a', T.__star__(), T.b)) == []
|
| 229 |
+
val = [[[1]]]
|
| 230 |
+
assert glom(val, '**') == [val, [[1]], [1], 1]
|
| 231 |
+
val = {'a': [{'b': [{'c': 1}, {'c': 2}, {'d': {'c': 3}}]}], 'c': 4}
|
| 232 |
+
assert glom(val, '**.c') == [4, 1, 2, 3]
|
| 233 |
+
assert glom(val, 'a.**.c') == [1, 2, 3]
|
| 234 |
+
assert glom(val, T['a'].__starstar__()['c']) == [1, 2, 3]
|
| 235 |
+
assert glom(val, 'a.*.b.*.c') == [[1, 2]]
|
| 236 |
+
# errors
|
| 237 |
+
class ErrDict(dict):
|
| 238 |
+
def __getitem__(key): 1/0
|
| 239 |
+
assert ErrDict(val).keys() # it will try to iterate
|
| 240 |
+
assert glom(ErrDict(val), '**') == [val]
|
| 241 |
+
assert glom(ErrDict(val), '*') == []
|
| 242 |
+
# object access
|
| 243 |
+
class A:
|
| 244 |
+
def __init__(self):
|
| 245 |
+
self.a = 1
|
| 246 |
+
self.b = {'c': 2}
|
| 247 |
+
val = A()
|
| 248 |
+
|
| 249 |
+
assert glom(val, '*') == [1, {'c': 2}]
|
| 250 |
+
assert glom(val, '**') == [val, 1, {'c': 2}, 2]
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def test_star_broadcast():
|
| 254 |
+
val = {'a': [1, 2, 3]}
|
| 255 |
+
assert glom(val, Path.from_text('a.*').path_t + 1) == [2, 3, 4]
|
| 256 |
+
val = {'a': [{'b': [{'c': 1}, {'c': 2}, {'c': 3}]}]}
|
| 257 |
+
assert glom(val, Path.from_text('**.c').path_t + 1) == [2, 3, 4]
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def test_star_warning():
|
| 261 |
+
'''check that the default behavior is as expected; this will change when * is default on'''
|
| 262 |
+
assert core.PATH_STAR is True
|
| 263 |
+
try:
|
| 264 |
+
core.PATH_STAR = False
|
| 265 |
+
assert glom({'*': 1}, '*') == 1
|
| 266 |
+
assert Path._STAR_WARNED
|
| 267 |
+
finally:
|
| 268 |
+
core.PATH_STAR = True
|
| 269 |
+
|
| 270 |
+
def test_path_eq():
|
| 271 |
+
assert Path('a', 'b') == Path('a', 'b')
|
| 272 |
+
assert Path('a') != Path('b')
|
| 273 |
+
|
| 274 |
+
assert Path() != object()
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def test_path_eq_t():
|
| 278 |
+
assert Path(T.a.b) == T.a.b
|
| 279 |
+
assert Path(T.a.b.c) != T.a.b
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def test_startswith():
|
| 283 |
+
ref = T.a.b[1]
|
| 284 |
+
|
| 285 |
+
assert Path(ref).startswith(T)
|
| 286 |
+
assert Path(ref).startswith(T.a.b)
|
| 287 |
+
assert Path(ref).startswith(ref)
|
| 288 |
+
assert Path(ref).startswith(ref.c) is False
|
| 289 |
+
|
| 290 |
+
assert Path('a.b.c').startswith(Path())
|
| 291 |
+
assert Path('a.b.c').startswith('a.b.c')
|
| 292 |
+
|
| 293 |
+
with raises(TypeError):
|
| 294 |
+
assert Path('a.b.c').startswith(None)
|
| 295 |
+
|
| 296 |
+
return
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def test_from_t_identity():
|
| 300 |
+
ref = Path(T.a.b)
|
| 301 |
+
assert ref.from_t() == ref
|
| 302 |
+
assert ref.from_t() is ref
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def test_t_dict_key():
|
| 306 |
+
target = {'a': 'A'}
|
| 307 |
+
assert glom(target, {T['a']: 'a'}) == {'A': 'A'}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def test_t_arithmetic():
|
| 311 |
+
t = 2
|
| 312 |
+
assert glom(t, T + T) == 4
|
| 313 |
+
assert glom(t, T * T) == 4
|
| 314 |
+
assert glom(t, T ** T) == 4
|
| 315 |
+
assert glom(t, T / 1) == 2
|
| 316 |
+
assert glom(t, T % 1) == 0
|
| 317 |
+
assert glom(t, T - 1) == 1
|
| 318 |
+
assert glom(t, T & T) == 2
|
| 319 |
+
assert glom(t, T | 1) == 3
|
| 320 |
+
assert glom(t, T ^ T) == 0
|
| 321 |
+
assert glom(2, ~T) == -3
|
| 322 |
+
assert glom(t, -T) == -2
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def test_t_arithmetic_reprs():
|
| 326 |
+
assert repr(T + T) == "T + T"
|
| 327 |
+
assert repr(T + (T / 2 * (T - 5) % 4)) == "T + (T / 2 * (T - 5) % 4)"
|
| 328 |
+
assert repr(T & 7 | (T ^ 6)) == "T & 7 | (T ^ 6)"
|
| 329 |
+
assert repr(-(~T)) == "-(~T)"
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def test_t_arithmetic_errors():
|
| 333 |
+
with raises(PathAccessError, match='zero'):
|
| 334 |
+
glom(0, T / 0)
|
| 335 |
+
|
| 336 |
+
with raises(PathAccessError, match='unsupported operand type'):
|
| 337 |
+
glom(None, T / 2)
|
| 338 |
+
|
| 339 |
+
return
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_t_dunders():
|
| 343 |
+
with raises(AttributeError) as exc_info:
|
| 344 |
+
T.__name__
|
| 345 |
+
|
| 346 |
+
assert 'use T.__("name__")' in str(exc_info.value)
|
| 347 |
+
|
| 348 |
+
assert glom(1, T.__('class__')) is int
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def test_path_cache():
|
| 352 |
+
assert Path.from_text('a.b.c') is Path.from_text('a.b.c')
|
| 353 |
+
pre = Path._MAX_CACHE
|
| 354 |
+
Path._MAX_CACHE = 0
|
| 355 |
+
assert Path.from_text('d.e.f') is not Path.from_text('d.e.f')
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_reduction.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import operator
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
from boltons.dictutils import OMD
|
| 5 |
+
|
| 6 |
+
from glom import glom, T, Sum, Fold, Flatten, Coalesce, flatten, FoldError, Glommer, Merge, merge
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_sum_integers():
|
| 10 |
+
target = list(range(5))
|
| 11 |
+
|
| 12 |
+
assert glom(target, Sum()) == 10
|
| 13 |
+
|
| 14 |
+
assert glom(target, Sum(init=lambda: 2)) == 12
|
| 15 |
+
|
| 16 |
+
target = []
|
| 17 |
+
assert glom(target, Sum()) == 0
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
target = [{"num": 3}, {"num": 2}, {"num": -1}]
|
| 21 |
+
assert glom(target, Sum(['num'])) == 4
|
| 22 |
+
|
| 23 |
+
target = target + [{}] # add a non-compliant dict
|
| 24 |
+
assert glom(target, Sum([Coalesce('num', default=0)])) ==4
|
| 25 |
+
|
| 26 |
+
assert repr(Sum()) == 'Sum()'
|
| 27 |
+
assert repr(Sum(len, init=float)) == 'Sum(len, init=float)'
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_sum_seqs():
|
| 31 |
+
target = [(x,) for x in range(4)]
|
| 32 |
+
assert glom(target, Sum(init=tuple)) == (0, 1, 2, 3)
|
| 33 |
+
|
| 34 |
+
# would not work with builtin sum(), gets:
|
| 35 |
+
# "TypeError: sum() can't sum strings [use ''.join(seq) instead]"
|
| 36 |
+
# Works here for now. If we're ok with that error, then we can
|
| 37 |
+
# switch to sum().
|
| 38 |
+
target = ['a', 'b', 'cd']
|
| 39 |
+
assert glom(target, Sum(init=str)) == 'abcd'
|
| 40 |
+
|
| 41 |
+
target = [['a'], ['b'], ['cde'], ['']]
|
| 42 |
+
|
| 43 |
+
assert glom(target, Sum(Sum(init=list), init=str)) == 'abcde'
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_fold():
|
| 47 |
+
target = range(1, 5)
|
| 48 |
+
assert glom(target, Fold(T, int)) == 10
|
| 49 |
+
assert glom(target, Fold(T, init=lambda: 2)) == 12
|
| 50 |
+
|
| 51 |
+
assert glom(target, Fold(T, lambda: 1, op=lambda l, r: l * r)) == 24
|
| 52 |
+
|
| 53 |
+
assert repr(Fold(T, int)) == 'Fold(T, init=int)'
|
| 54 |
+
assert repr(Fold(T, int, op=operator.imul)).startswith('Fold(T, init=int, op=<')
|
| 55 |
+
|
| 56 |
+
# signature coverage
|
| 57 |
+
with pytest.raises(TypeError):
|
| 58 |
+
Fold(T, list, op=None) # noncallable op
|
| 59 |
+
|
| 60 |
+
with pytest.raises(TypeError):
|
| 61 |
+
Fold(T, init=None) # noncallable init
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_fold_bad_iter():
|
| 65 |
+
glommer = Glommer(register_default_types=False)
|
| 66 |
+
|
| 67 |
+
def bad_iter(obj):
|
| 68 |
+
raise RuntimeError('oops')
|
| 69 |
+
|
| 70 |
+
glommer.register(list, iterate=bad_iter)
|
| 71 |
+
|
| 72 |
+
with pytest.raises(TypeError):
|
| 73 |
+
target = []
|
| 74 |
+
glommer.glom(target, Flatten())
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_flatten():
|
| 78 |
+
target = [[1], [2], [3, 4]]
|
| 79 |
+
assert glom(target, Flatten()) == [1, 2, 3, 4]
|
| 80 |
+
|
| 81 |
+
target = [(1, 2), [3]]
|
| 82 |
+
assert glom(target, Flatten()) == [1, 2, 3]
|
| 83 |
+
|
| 84 |
+
gen = glom(target, Flatten(init='lazy'))
|
| 85 |
+
assert next(gen) == 1
|
| 86 |
+
assert list(gen) == [2, 3]
|
| 87 |
+
|
| 88 |
+
assert repr(Flatten()) == 'Flatten()'
|
| 89 |
+
assert repr(Flatten(init='lazy')) == "Flatten(init='lazy')"
|
| 90 |
+
assert repr(Flatten(init=tuple)) == "Flatten(init=tuple)"
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_flatten_func():
|
| 94 |
+
target = [[1], [2], [3, 4]]
|
| 95 |
+
assert flatten(target) == [1, 2, 3, 4]
|
| 96 |
+
|
| 97 |
+
two_level_target = [[x] for x in target]
|
| 98 |
+
assert flatten(two_level_target, levels=2) == [1, 2, 3, 4]
|
| 99 |
+
assert flatten(two_level_target, levels=0) == two_level_target
|
| 100 |
+
|
| 101 |
+
unflattenable = 2
|
| 102 |
+
|
| 103 |
+
with pytest.raises(FoldError):
|
| 104 |
+
assert flatten(unflattenable)
|
| 105 |
+
|
| 106 |
+
# kind of an odd use, but it works for now
|
| 107 |
+
assert flatten(['a', 'b', 'cd'], init=str) == 'abcd'
|
| 108 |
+
|
| 109 |
+
# another odd case
|
| 110 |
+
subspec_target = {'items': {'numbers': [1, 2, 3]}}
|
| 111 |
+
assert (flatten(subspec_target, spec='items.numbers', init=int) == 6)
|
| 112 |
+
|
| 113 |
+
# basic signature tests
|
| 114 |
+
with pytest.raises(ValueError):
|
| 115 |
+
flatten([], levels=-1)
|
| 116 |
+
|
| 117 |
+
with pytest.raises(TypeError):
|
| 118 |
+
flatten([], nonexistentkwarg=False)
|
| 119 |
+
|
| 120 |
+
return
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_merge():
|
| 124 |
+
|
| 125 |
+
target = [{'a': 'A'}, {'b': 'B'}]
|
| 126 |
+
|
| 127 |
+
assert glom(target, Merge()) == {'a': 'A', 'b': 'B'}
|
| 128 |
+
|
| 129 |
+
assert glom(target, Merge(op=dict.update)) == {'a': 'A', 'b': 'B'}
|
| 130 |
+
|
| 131 |
+
with pytest.raises(ValueError):
|
| 132 |
+
Merge(init=list) # has no .update()
|
| 133 |
+
|
| 134 |
+
with pytest.raises(ValueError):
|
| 135 |
+
Merge(op='update_extend') # doesn't work on base dict, the default init
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def test_merge_omd():
|
| 139 |
+
target = [{'a': 'A'}, {'a': 'aleph'}]
|
| 140 |
+
|
| 141 |
+
assert glom(target, Merge(init=OMD)) == OMD({'a': 'aleph'})
|
| 142 |
+
assert glom(target, Merge(init=OMD, op='update_extend')) == OMD([('a', 'A'), ('a', 'aleph')])
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def test_merge_func():
|
| 146 |
+
|
| 147 |
+
target = [{'a': 'A'}, {'b': 'B'}]
|
| 148 |
+
assert merge(target) == {'a': 'A', 'b': 'B'}
|
| 149 |
+
assert merge([]) == {}
|
| 150 |
+
|
| 151 |
+
# basic signature test
|
| 152 |
+
with pytest.raises(TypeError):
|
| 153 |
+
merge([], nonexistentkwarg=False)
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_scope_vars.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from glom import glom, Path, S, A, T, Vars, Val, GlomError, M, SKIP, Let
|
| 4 |
+
|
| 5 |
+
from glom.core import ROOT
|
| 6 |
+
from glom.mutation import PathAssignError
|
| 7 |
+
|
| 8 |
+
def test_s_scope_assign():
|
| 9 |
+
data = {'a': 1, 'b': [{'c': 2}, {'c': 3}]}
|
| 10 |
+
output = [{'a': 1, 'c': 2}, {'a': 1, 'c': 3}]
|
| 11 |
+
assert glom(data, (S(a=T['a']), ('b', [{'a': S['a'], 'c': 'c'}]))) == output
|
| 12 |
+
assert glom(data, ('b', [{'a': S[ROOT][Val(T)]['a'], 'c': 'c'}])) == output
|
| 13 |
+
|
| 14 |
+
with pytest.raises(TypeError):
|
| 15 |
+
S('posarg')
|
| 16 |
+
with pytest.raises(TypeError):
|
| 17 |
+
S()
|
| 18 |
+
|
| 19 |
+
assert glom([[1]], (S(v=Vars()), [[A.v.a]], S.v.a)) == 1
|
| 20 |
+
assert glom(1, (S(v={}), A.v['a'], S.v['a'])) == 1
|
| 21 |
+
with pytest.raises(GlomError):
|
| 22 |
+
glom(1, (S(v=1), A.v.a))
|
| 23 |
+
|
| 24 |
+
class FailAssign:
|
| 25 |
+
def __setattr__(self, name, val):
|
| 26 |
+
raise Exception('nope')
|
| 27 |
+
|
| 28 |
+
with pytest.raises(PathAssignError):
|
| 29 |
+
glom(1, (S(v=FailAssign()), Path(A.v, 'a')))
|
| 30 |
+
|
| 31 |
+
assert repr(S(a=T.a.b)) == 'S(a=T.a.b)'
|
| 32 |
+
|
| 33 |
+
spec = (S(a=T['x']), S.a)
|
| 34 |
+
assert glom({'x': 'y'}, spec) == 'y'
|
| 35 |
+
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_globals():
|
| 40 |
+
assert glom([[1]], ([[A.globals.a]], S.globals.a)) == 1
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_vars():
|
| 44 |
+
assert glom(1, A.a) == 1 # A should not change the target
|
| 45 |
+
assert glom(1, (A.a, S.a)) == 1
|
| 46 |
+
# check that tuple vars don't "leak" into parent tuple
|
| 47 |
+
assert glom(1, (A.t, Val(2), A.t, S.t)) == 2
|
| 48 |
+
assert glom(1, (A.t, (Val(2), A.t), S.t)) == 1
|
| 49 |
+
let = S(v=Vars({'b': 2}, c=3))
|
| 50 |
+
assert glom(1, (let, A.v.a, S.v.a)) == 1
|
| 51 |
+
with pytest.raises(AttributeError):
|
| 52 |
+
glom(1, (let, S.v.a)) # check that Vars() inside a spec doesn't hold state
|
| 53 |
+
assert glom(1, (let, Path(A, 'v', 'a'), S.v.a)) == 1
|
| 54 |
+
assert glom(1, (let, S.v.b)) == 2
|
| 55 |
+
assert glom(1, (let, S.v.c)) == 3
|
| 56 |
+
assert repr(let) == "S(v=Vars({'b': 2}, c=3))"
|
| 57 |
+
assert repr(Vars(a=1, b=2)) in (
|
| 58 |
+
"Vars(a=1, b=2)", "Vars(b=2, a=1)")
|
| 59 |
+
assert repr(Vars(a=1, b=2).glomit(None, None)) in (
|
| 60 |
+
"ScopeVars({'a': 1, 'b': 2})", "Vars({'b': 2, 'a': 1})")
|
| 61 |
+
|
| 62 |
+
assert repr(A.b["c"]) == "A.b['c']"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_scoped_vars():
|
| 66 |
+
target = list(range(10)) + list(range(5))
|
| 67 |
+
|
| 68 |
+
scope_globals = glom(target, ([A.globals.last], S.globals))
|
| 69 |
+
assert scope_globals.last == 4
|
| 70 |
+
assert dict(scope_globals) == {'last': 4}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_max_skip():
|
| 74 |
+
target = list(range(10)) + list(range(5))
|
| 75 |
+
|
| 76 |
+
max_spec = (S(max=Vars(max=0)),
|
| 77 |
+
[((M > M(S.max.max)) & A.max.max) | Val(SKIP)],
|
| 78 |
+
S.max)
|
| 79 |
+
result = glom(target, max_spec)
|
| 80 |
+
assert result.max == 9
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_let(): # backwards compat 2020-07
|
| 84 |
+
data = {'a': 1, 'b': [{'c': 2}, {'c': 3}]}
|
| 85 |
+
output = [{'a': 1, 'c': 2}, {'a': 1, 'c': 3}]
|
| 86 |
+
assert glom(data, (Let(a='a'), ('b', [{'a': S['a'], 'c': 'c'}]))) == output
|
| 87 |
+
assert glom(data, ('b', [{'a': S[ROOT][Val(T)]['a'], 'c': 'c'}])) == output
|
| 88 |
+
|
| 89 |
+
with pytest.raises(TypeError):
|
| 90 |
+
Let('posarg')
|
| 91 |
+
with pytest.raises(TypeError):
|
| 92 |
+
Let()
|
| 93 |
+
|
| 94 |
+
assert glom([[1]], (Let(v=Vars()), [[A.v.a]], S.v.a)) == 1
|
| 95 |
+
assert glom(1, (Let(v=lambda t: {}), A.v['a'], S.v['a'])) == 1
|
| 96 |
+
with pytest.raises(GlomError):
|
| 97 |
+
glom(1, (Let(v=lambda t: 1), A.v.a))
|
| 98 |
+
|
| 99 |
+
class FailAssign:
|
| 100 |
+
def __setattr__(self, name, val):
|
| 101 |
+
raise Exception('nope')
|
| 102 |
+
|
| 103 |
+
with pytest.raises(PathAssignError):
|
| 104 |
+
glom(1, (Let(v=lambda t: FailAssign()), Path(A.v, 'a')))
|
| 105 |
+
|
| 106 |
+
assert repr(Let(a=T.a.b)) == 'Let(a=T.a.b)'
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_snippets.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
from collections import deque
|
| 3 |
+
from decimal import Decimal
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import textwrap
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
import glom
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _get_codeblock(lines, offset):
|
| 14 |
+
if lines[offset:offset + 2] != [".. code-block:: python\n", "\n"]:
|
| 15 |
+
return None
|
| 16 |
+
start = offset + 2
|
| 17 |
+
try:
|
| 18 |
+
finish = lines.index('\n', start)
|
| 19 |
+
except ValueError:
|
| 20 |
+
return None
|
| 21 |
+
return textwrap.dedent("".join(lines[start:finish]))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _find_snippets():
|
| 25 |
+
path = os.path.dirname(os.path.abspath(__file__)) + '/../../docs/snippets.rst'
|
| 26 |
+
with open(path) as snippet_file:
|
| 27 |
+
lines = list(snippet_file)
|
| 28 |
+
snippets = []
|
| 29 |
+
for line_no in range(len(lines)):
|
| 30 |
+
source = _get_codeblock(lines, line_no)
|
| 31 |
+
if source:
|
| 32 |
+
snippets.append((line_no, source))
|
| 33 |
+
return snippets
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
SNIPPETS = _find_snippets()
|
| 38 |
+
except:
|
| 39 |
+
SNIPPETS = [] # in case running in an environment without docs
|
| 40 |
+
|
| 41 |
+
SNIPPETS_GLOBALS = copy.copy(glom.__dict__)
|
| 42 |
+
SNIPPETS_GLOBALS.update(dict(
|
| 43 |
+
json=json,
|
| 44 |
+
deque=deque,
|
| 45 |
+
Decimal=Decimal,
|
| 46 |
+
data=json.dumps({'a': ['b']}),
|
| 47 |
+
contacts=[{'primary_email': {'email': 'a@example.com'}}, {}],
|
| 48 |
+
glom=glom.glom))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@pytest.mark.parametrize("line,source", SNIPPETS)
|
| 52 |
+
def test_snippet(line, source):
|
| 53 |
+
if '>>>' in source:
|
| 54 |
+
return # maybe doctest output checking
|
| 55 |
+
code = compile(source, 'snippets.rst', 'exec')
|
| 56 |
+
if 'django' in source:
|
| 57 |
+
return # maybe in the future
|
| 58 |
+
eval(code, SNIPPETS_GLOBALS)
|
| 59 |
+
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_spec.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from glom import glom, Spec, T, S
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_spec():
|
| 7 |
+
assert glom(5, T) == 5 # check assumption about echo behavior
|
| 8 |
+
echo = Spec(T)
|
| 9 |
+
assert echo.glom(5) == 5
|
| 10 |
+
assert glom(5, echo) == 5
|
| 11 |
+
echo2 = Spec(echo)
|
| 12 |
+
assert echo2.glom(5) == 5
|
| 13 |
+
|
| 14 |
+
with pytest.raises(TypeError, match='expected spec to be'):
|
| 15 |
+
glom({}, object())
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
+
def test_scope_spec():
|
| 19 |
+
scope_spec = Spec(S)
|
| 20 |
+
assert scope_spec.glom(5, scope={'cat': 1})['cat'] == 1
|
| 21 |
+
cat_scope_spec = Spec(scope_spec, scope={'cat': 1})
|
| 22 |
+
assert 'cat' in repr(cat_scope_spec)
|
| 23 |
+
assert cat_scope_spec.glom(5)['cat'] == 1
|
| 24 |
+
|
| 25 |
+
# test that Spec overrides the scope for its sub-tree
|
| 26 |
+
assert glom(5, cat_scope_spec, scope={'cat': 2})['cat'] == 1
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_streaming.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from itertools import count, dropwhile, chain
|
| 4 |
+
|
| 5 |
+
from glom import Iter
|
| 6 |
+
from glom import glom, SKIP, STOP, T, Call, Spec, Glommer, Check, SKIP
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
RANGE_5 = list(range(5))
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_iter():
|
| 13 |
+
assert list(glom(['1', '2', '3'], Iter(int))) == [1, 2, 3]
|
| 14 |
+
cnt = count()
|
| 15 |
+
cnt_1 = glom(cnt, Iter(lambda t: t + 1))
|
| 16 |
+
assert (next(cnt_1), next(cnt_1)) == (1, 2)
|
| 17 |
+
assert next(cnt) == 2
|
| 18 |
+
|
| 19 |
+
assert list(glom(['1', '2', '3'], (Iter(int), enumerate))) == [(0, 1), (1, 2), (2, 3)]
|
| 20 |
+
|
| 21 |
+
assert list(glom([1, SKIP, 2], Iter())) == [1, 2]
|
| 22 |
+
assert list(glom([1, STOP, 2], Iter())) == [1]
|
| 23 |
+
|
| 24 |
+
with pytest.raises(TypeError):
|
| 25 |
+
Iter(nonexistent_kwarg=True)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_filter():
|
| 29 |
+
is_odd = lambda x: x % 2
|
| 30 |
+
odd_spec = Iter().filter(is_odd)
|
| 31 |
+
out = glom(RANGE_5, odd_spec)
|
| 32 |
+
assert list(out) == [1, 3]
|
| 33 |
+
|
| 34 |
+
# let's just make sure we're actually streaming just in case
|
| 35 |
+
counter = count()
|
| 36 |
+
out = glom(counter, odd_spec)
|
| 37 |
+
assert next(out) == 1
|
| 38 |
+
assert next(out) == 3
|
| 39 |
+
assert next(counter) == 4
|
| 40 |
+
assert next(counter) == 5
|
| 41 |
+
assert next(out) == 7
|
| 42 |
+
|
| 43 |
+
bools = [True, False, False, True, False]
|
| 44 |
+
spec = Iter().filter().all()
|
| 45 |
+
out = glom(bools, spec)
|
| 46 |
+
assert out == [True, True]
|
| 47 |
+
|
| 48 |
+
imags = [0j, 1j, 2, 2j, 3j]
|
| 49 |
+
spec = Iter().filter(Check(T.imag.real, type=float, one_of=(0, 2), default=SKIP)).all()
|
| 50 |
+
out = glom(imags, spec)
|
| 51 |
+
assert out == [0j, 2j]
|
| 52 |
+
|
| 53 |
+
assert repr(Iter().filter(T.a.b)) == 'Iter().filter(T.a.b)'
|
| 54 |
+
assert repr(Iter(list).filter(sum)) == 'Iter(list).filter(sum)'
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_map():
|
| 58 |
+
spec = Iter().map(lambda x: x * 2)
|
| 59 |
+
out = glom(RANGE_5, spec)
|
| 60 |
+
assert list(out) == [0, 2, 4, 6, 8]
|
| 61 |
+
assert repr(Iter().map(T.a.b)) == 'Iter().map(T.a.b)'
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_split_flatten():
|
| 65 |
+
falsey_stream = [1, None, None, 2, 3, None, 4]
|
| 66 |
+
spec = Iter().split()
|
| 67 |
+
out = glom(falsey_stream, spec)
|
| 68 |
+
assert list(out) == [[1], [2, 3], [4]]
|
| 69 |
+
|
| 70 |
+
spec = Iter().split().flatten()
|
| 71 |
+
out = glom(falsey_stream, spec)
|
| 72 |
+
assert list(out) == [1, 2, 3, 4]
|
| 73 |
+
|
| 74 |
+
assert repr(Iter().split(sep=None, maxsplit=2)) == 'Iter().split(sep=None, maxsplit=2)'
|
| 75 |
+
assert repr(Iter(T.a.b[1]).flatten()) == 'Iter(T.a.b[1]).flatten()'
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_chunked():
|
| 79 |
+
int_list = list(range(9))
|
| 80 |
+
|
| 81 |
+
spec = Iter().chunked(3)
|
| 82 |
+
out = glom(int_list, spec)
|
| 83 |
+
assert list(out) == [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
|
| 84 |
+
|
| 85 |
+
spec = Iter().chunked(3).map(sum)
|
| 86 |
+
out = glom(int_list, spec)
|
| 87 |
+
assert list(out) == [3, 12, 21]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_windowed():
|
| 91 |
+
int_list = list(range(5))
|
| 92 |
+
|
| 93 |
+
spec = Iter().windowed(3)
|
| 94 |
+
out = glom(int_list, spec)
|
| 95 |
+
assert list(out) == [(0, 1, 2), (1, 2, 3), (2, 3, 4)]
|
| 96 |
+
assert repr(spec) == 'Iter().windowed(3)'
|
| 97 |
+
|
| 98 |
+
spec = spec.filter(lambda x: bool(x[0] % 2)).map(sum)
|
| 99 |
+
out = glom(int_list, spec)
|
| 100 |
+
assert next(out) == 6
|
| 101 |
+
|
| 102 |
+
out = glom(range(10), spec)
|
| 103 |
+
assert list(out) == [6, 12, 18, 24]
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_unique():
|
| 107 |
+
int_list = list(range(10))
|
| 108 |
+
|
| 109 |
+
spec = Iter().unique()
|
| 110 |
+
out = glom(int_list, spec)
|
| 111 |
+
assert list(out) == int_list
|
| 112 |
+
|
| 113 |
+
spec = Iter(lambda x: x % 4).unique()
|
| 114 |
+
out = glom(int_list, spec)
|
| 115 |
+
assert list(out) == int_list[:4]
|
| 116 |
+
assert repr(Iter().unique(T.a)) == 'Iter().unique(T.a)'
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_slice():
|
| 120 |
+
cnt = count()
|
| 121 |
+
|
| 122 |
+
spec = Iter().slice(3)
|
| 123 |
+
out = glom(cnt, spec)
|
| 124 |
+
|
| 125 |
+
assert list(out) == [0, 1, 2]
|
| 126 |
+
assert next(cnt) == 3
|
| 127 |
+
|
| 128 |
+
out = glom(range(10), Iter().slice(1, 5))
|
| 129 |
+
assert list(out) == [1, 2, 3, 4]
|
| 130 |
+
|
| 131 |
+
out = glom(range(10), Iter().slice(1, 6, 2))
|
| 132 |
+
assert list(out) == [1, 3, 5]
|
| 133 |
+
assert repr(Iter().slice(1, 6, 2)) == 'Iter().slice(1, 6, 2)'
|
| 134 |
+
|
| 135 |
+
out = glom(range(10), Iter().limit(3))
|
| 136 |
+
assert list(out) == [0, 1, 2]
|
| 137 |
+
assert repr(Iter().limit(3)) == 'Iter().limit(3)'
|
| 138 |
+
|
| 139 |
+
out = glom(range(5), Iter().limit(10))
|
| 140 |
+
assert list(out) == [0, 1, 2, 3, 4]
|
| 141 |
+
|
| 142 |
+
# test broken args
|
| 143 |
+
with pytest.raises(TypeError):
|
| 144 |
+
Iter().slice(1, 2, 3, 4)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def test_while():
|
| 148 |
+
cnt = count()
|
| 149 |
+
out = glom(cnt, Iter().takewhile(lambda x: x < 3))
|
| 150 |
+
assert list(out) == [0, 1, 2]
|
| 151 |
+
assert next(cnt) == 4
|
| 152 |
+
assert repr(Iter().takewhile(T.a) == 'Iter().takewhile(T.a)')
|
| 153 |
+
|
| 154 |
+
range_iter = iter(range(7))
|
| 155 |
+
out = glom(range_iter, Iter().dropwhile(lambda x: x < 3 or x > 5))
|
| 156 |
+
assert list(out) == [3, 4, 5, 6] # 6 still here despite the x>5 above
|
| 157 |
+
|
| 158 |
+
out = glom(range(10), Iter().dropwhile(lambda x: x >= 0).limit(10))
|
| 159 |
+
assert list(out) == []
|
| 160 |
+
|
| 161 |
+
out = glom(range(8), Iter().dropwhile((T.bit_length(), lambda x: x < 3)))
|
| 162 |
+
assert list(out) == [4, 5, 6, 7]
|
| 163 |
+
assert repr(Iter().dropwhile(T.a) == 'Iter().dropwhile(T.a)')
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def test_iter_composition():
|
| 167 |
+
int_list = list(range(10))
|
| 168 |
+
out = glom(int_list, (Iter(), Iter(), list))
|
| 169 |
+
assert out == int_list
|
| 170 |
+
|
| 171 |
+
out = glom([int_list] * 3, Iter(Iter(lambda x: x % 4)).flatten().unique())
|
| 172 |
+
assert list(out) == [0, 1, 2, 3]
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_faulty_iterate():
|
| 176 |
+
glommer = Glommer()
|
| 177 |
+
|
| 178 |
+
def bad_iter(obj):
|
| 179 |
+
raise RuntimeError('oops')
|
| 180 |
+
|
| 181 |
+
glommer.register(str, iterate=bad_iter)
|
| 182 |
+
|
| 183 |
+
with pytest.raises(TypeError):
|
| 184 |
+
glommer.glom('abc', (Iter(), list))
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_first():
|
| 188 |
+
spec = Iter().first(T.imag)
|
| 189 |
+
|
| 190 |
+
target = iter([1, 2, 3j, 4])
|
| 191 |
+
out = glom(target, spec)
|
| 192 |
+
assert out == 3j
|
| 193 |
+
assert next(target) == 4
|
| 194 |
+
assert repr(spec) == '(Iter(), First(T.imag))'
|
| 195 |
+
|
| 196 |
+
spec = Iter().first(T.imag, default=0)
|
| 197 |
+
target = iter([1, 2, 4])
|
| 198 |
+
out = glom(target, spec)
|
| 199 |
+
assert out == 0
|
| 200 |
+
assert repr(spec) == '(Iter(), First(T.imag, default=0))'
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_all():
|
| 204 |
+
int_iter = iter(range(10))
|
| 205 |
+
|
| 206 |
+
out = glom(int_iter, Iter().all())
|
| 207 |
+
assert out == list(range(10))
|
| 208 |
+
assert next(int_iter, None) is None
|
| 209 |
+
assert repr(Iter().all()) == 'Pipe(Iter(), list)'
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_target_types.py
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import glom
|
| 4 |
+
from glom import Glommer, PathAccessError, UnregisteredTarget
|
| 5 |
+
from glom.core import TargetRegistry
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class A:
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
class B:
|
| 12 |
+
pass
|
| 13 |
+
|
| 14 |
+
class C(A):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
class D(B):
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
class E(C, D, A):
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
class F(E):
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_types_leave_one_out():
|
| 28 |
+
ALL_TYPES = [A, B, C, D, E, F]
|
| 29 |
+
for cur_t in ALL_TYPES:
|
| 30 |
+
|
| 31 |
+
treg = TargetRegistry(register_default_types=False)
|
| 32 |
+
|
| 33 |
+
treg.register(object, get=lambda: object)
|
| 34 |
+
for t in ALL_TYPES:
|
| 35 |
+
if t is cur_t:
|
| 36 |
+
continue
|
| 37 |
+
treg.register(t, get=(lambda t: lambda: t)(t))
|
| 38 |
+
|
| 39 |
+
obj = cur_t()
|
| 40 |
+
assert treg.get_handler('get', obj)() == obj.__class__.mro()[1]
|
| 41 |
+
|
| 42 |
+
if cur_t is E:
|
| 43 |
+
assert treg.get_handler('get', obj)() is C # sanity check
|
| 44 |
+
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def test_types_bare():
|
| 49 |
+
glommer = Glommer(register_default_types=False)
|
| 50 |
+
|
| 51 |
+
treg = glommer.scope[TargetRegistry]
|
| 52 |
+
assert treg._get_closest_type(object(), treg._op_type_tree.get('get', {})) is None
|
| 53 |
+
|
| 54 |
+
# test that bare glommers can't glom anything
|
| 55 |
+
with pytest.raises(UnregisteredTarget) as exc_info:
|
| 56 |
+
glommer.glom(object(), {'object_repr': '__class__.__name__'})
|
| 57 |
+
assert repr(exc_info.value) == "UnregisteredTarget('get', <type 'object'>, OrderedDict(), ('__class__',))"
|
| 58 |
+
assert str(exc_info.value).find(
|
| 59 |
+
"glom() called without registering any types for operation 'get'."
|
| 60 |
+
" see glom.register() or Glommer's constructor for details.") != -1
|
| 61 |
+
|
| 62 |
+
with pytest.raises(UnregisteredTarget, match='without registering') as exc_info:
|
| 63 |
+
glommer.glom([{'hi': 'hi'}], ['hi'])
|
| 64 |
+
assert not exc_info.value.type_map
|
| 65 |
+
|
| 66 |
+
glommer.register(object, get=getattr)
|
| 67 |
+
glommer.register(dict, get=dict.__getitem__, exact=True)
|
| 68 |
+
|
| 69 |
+
# check again that registering object for 'get' doesn't change the
|
| 70 |
+
# fact that we don't have iterate support yet
|
| 71 |
+
with pytest.raises(UnregisteredTarget) as exc_info:
|
| 72 |
+
glommer.glom({'test': [{'hi': 'hi'}]}, ('test', ['hi']))
|
| 73 |
+
# feel free to update the "(at ['test'])" part to improve path display
|
| 74 |
+
assert (
|
| 75 |
+
"target type 'list' not registered for 'iterate', "
|
| 76 |
+
"expected one of registered types: (dict)" in str(exc_info.value))
|
| 77 |
+
return
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_invalid_register():
|
| 81 |
+
glommer = Glommer()
|
| 82 |
+
with pytest.raises(TypeError):
|
| 83 |
+
glommer.register(1)
|
| 84 |
+
return
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def test_exact_register():
|
| 88 |
+
glommer = Glommer(register_default_types=False)
|
| 89 |
+
|
| 90 |
+
class BetterList(list):
|
| 91 |
+
pass
|
| 92 |
+
|
| 93 |
+
glommer.register(BetterList, iterate=iter, exact=True)
|
| 94 |
+
|
| 95 |
+
expected = [0, 2, 4]
|
| 96 |
+
value = glommer.glom(BetterList(range(3)), [lambda x: x * 2])
|
| 97 |
+
assert value == expected
|
| 98 |
+
|
| 99 |
+
with pytest.raises(UnregisteredTarget):
|
| 100 |
+
glommer.glom(list(range(3)), ['unused'])
|
| 101 |
+
|
| 102 |
+
return
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_duck_register():
|
| 106 |
+
class LilRanger:
|
| 107 |
+
def __init__(self):
|
| 108 |
+
self.lil_list = list(range(5))
|
| 109 |
+
|
| 110 |
+
def __iter__(self):
|
| 111 |
+
return iter(self.lil_list)
|
| 112 |
+
|
| 113 |
+
glommer = Glommer(register_default_types=False)
|
| 114 |
+
|
| 115 |
+
target = LilRanger()
|
| 116 |
+
|
| 117 |
+
with pytest.raises(UnregisteredTarget):
|
| 118 |
+
float_range = glommer.glom(target, [float])
|
| 119 |
+
|
| 120 |
+
glommer.register(LilRanger)
|
| 121 |
+
|
| 122 |
+
float_range = glommer.glom(target, [float])
|
| 123 |
+
|
| 124 |
+
assert float_range == [0.0, 1.0, 2.0, 3.0, 4.0]
|
| 125 |
+
|
| 126 |
+
glommer = Glommer() # now with just defaults
|
| 127 |
+
float_range = glommer.glom(target, [float])
|
| 128 |
+
assert float_range == [0.0, 1.0, 2.0, 3.0, 4.0]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_bypass_getitem():
|
| 132 |
+
target = list(range(3)) * 3
|
| 133 |
+
|
| 134 |
+
with pytest.raises(PathAccessError):
|
| 135 |
+
glom.glom(target, 'count')
|
| 136 |
+
|
| 137 |
+
res = glom.glom(target, lambda list_obj: list_obj.count(1))
|
| 138 |
+
|
| 139 |
+
assert res == 3
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def test_iter_set():
|
| 143 |
+
some_ints = set(range(5))
|
| 144 |
+
some_floats = glom.glom(some_ints, [float])
|
| 145 |
+
|
| 146 |
+
assert sorted(some_floats) == [0.0, 1.0, 2.0, 3.0, 4.0]
|
| 147 |
+
|
| 148 |
+
# now without defaults
|
| 149 |
+
glommer = Glommer(register_default_types=False)
|
| 150 |
+
glommer.register(set, iterate=iter)
|
| 151 |
+
some_floats = glom.glom(some_ints, [float])
|
| 152 |
+
|
| 153 |
+
assert sorted(some_floats) == [0.0, 1.0, 2.0, 3.0, 4.0]
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def test_iter_str():
|
| 157 |
+
# check that strings are not iterable by default, one of the most
|
| 158 |
+
# common sources of bugs
|
| 159 |
+
glom_buddy = 'kurt'
|
| 160 |
+
|
| 161 |
+
with pytest.raises(UnregisteredTarget):
|
| 162 |
+
glom.glom(glom_buddy, {'name': [glom_buddy]})
|
| 163 |
+
|
| 164 |
+
# also check that someone can override this
|
| 165 |
+
|
| 166 |
+
glommer = Glommer()
|
| 167 |
+
glommer.register(str, iterate=iter)
|
| 168 |
+
res = glommer.glom(glom_buddy, {'name_chars_for_some_reason': [str]})
|
| 169 |
+
assert len(res['name_chars_for_some_reason']) == 4
|
| 170 |
+
|
| 171 |
+
# the better way, for any dissenter reading this
|
| 172 |
+
|
| 173 |
+
assert glom.glom(glom_buddy, {'name_chars': list}) == {'name_chars': ['k', 'u', 'r', 't']}
|
| 174 |
+
|
| 175 |
+
# and for the really passionate: how about making strings
|
| 176 |
+
# non-iterable and just giving them a .chars() method that returns
|
| 177 |
+
# a list of single-character strings.
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_default_scope_register():
|
| 181 |
+
# just hit it to make sure it exists, it behaves exactly like Glommer.register
|
| 182 |
+
glom.register(type, exact=False)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def test_faulty_iterate():
|
| 186 |
+
glommer = Glommer()
|
| 187 |
+
|
| 188 |
+
def bad_iter(obj):
|
| 189 |
+
raise RuntimeError('oops')
|
| 190 |
+
|
| 191 |
+
glommer.register(str, iterate=bad_iter)
|
| 192 |
+
|
| 193 |
+
with pytest.raises(TypeError):
|
| 194 |
+
glommer.glom({'a': 'fail'}, ('a', {'chars': [str]}))
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def test_faulty_op_registration():
|
| 198 |
+
treg = TargetRegistry()
|
| 199 |
+
|
| 200 |
+
with pytest.raises(TypeError, match="text name, not:"):
|
| 201 |
+
treg.register_op(None, len)
|
| 202 |
+
with pytest.raises(TypeError, match="callable, not:"):
|
| 203 |
+
treg.register_op('fake_op', object())
|
| 204 |
+
|
| 205 |
+
class NewType:
|
| 206 |
+
pass
|
| 207 |
+
|
| 208 |
+
def _autodiscover_raise(type_obj):
|
| 209 |
+
raise Exception('noperino')
|
| 210 |
+
|
| 211 |
+
with pytest.raises(TypeError, match="noperino"):
|
| 212 |
+
treg.register_op('fake_op', _autodiscover_raise)
|
| 213 |
+
|
| 214 |
+
assert 'fake_op' not in treg._op_auto_map
|
| 215 |
+
|
| 216 |
+
# check op with no autodiscovery
|
| 217 |
+
treg.register_op('lol', exact=True)
|
| 218 |
+
lol_type_map = treg.get_type_map('lol')
|
| 219 |
+
assert all([v is False for v in lol_type_map.values()])
|
| 220 |
+
|
| 221 |
+
# check op reregistration, this time not exact
|
| 222 |
+
assert not treg._op_type_tree.get('lol')
|
| 223 |
+
treg.register_op('lol', exact=False)
|
| 224 |
+
assert treg._op_type_tree.get('lol')
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def _autodiscover_faulty_return(type_obj):
|
| 228 |
+
return 'hideeho'
|
| 229 |
+
|
| 230 |
+
with pytest.raises(TypeError, match="hideeho"):
|
| 231 |
+
treg.register_op('fake_op', _autodiscover_faulty_return)
|
| 232 |
+
|
| 233 |
+
def _autodiscover_sneaky(type_obj):
|
| 234 |
+
# works with default registrations, but fails later on sets and frozensets
|
| 235 |
+
if type_obj is set:
|
| 236 |
+
return 'this should have been False or a callable, but was intentionally a string'
|
| 237 |
+
if type_obj is frozenset:
|
| 238 |
+
raise ValueError('this should have been False or a callable, but was intentionally a ValueError')
|
| 239 |
+
return False
|
| 240 |
+
|
| 241 |
+
treg.register_op('sneak', _autodiscover_sneaky)
|
| 242 |
+
|
| 243 |
+
with pytest.raises(TypeError, match="intentionally a string"):
|
| 244 |
+
treg.register(set)
|
| 245 |
+
with pytest.raises(TypeError, match="intentionally a ValueError"):
|
| 246 |
+
treg.register(frozenset)
|
| 247 |
+
|
| 248 |
+
return
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def test_reregister_type():
|
| 252 |
+
treg = TargetRegistry()
|
| 253 |
+
|
| 254 |
+
class NewType:
|
| 255 |
+
pass
|
| 256 |
+
|
| 257 |
+
treg.register(NewType, op=lambda obj: obj)
|
| 258 |
+
|
| 259 |
+
obj = NewType()
|
| 260 |
+
handler = treg.get_handler('op', obj)
|
| 261 |
+
|
| 262 |
+
assert handler(obj) == obj
|
| 263 |
+
|
| 264 |
+
# assert no change in reregistering same
|
| 265 |
+
treg.register(NewType, op=lambda obj: obj)
|
| 266 |
+
handler = treg.get_handler('op', obj)
|
| 267 |
+
assert handler(obj) == obj
|
| 268 |
+
|
| 269 |
+
# assert change in reregistering new
|
| 270 |
+
treg.register(NewType, op=lambda obj: obj.__class__.__name__)
|
| 271 |
+
handler = treg.get_handler('op', obj)
|
| 272 |
+
assert handler(obj) == 'NewType'
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/glom/test/test_tutorial.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from glom import glom, tutorial
|
| 2 |
+
from glom.tutorial import Contact, Email
|
| 3 |
+
|
| 4 |
+
def test_tutorial_data():
|
| 5 |
+
assert 4 <= len(tutorial.CONTACTS) < 10
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_tutorial():
|
| 9 |
+
target = {'a': {'b': {'c': 'd'}}}
|
| 10 |
+
|
| 11 |
+
val = target['a']['b']['c']
|
| 12 |
+
|
| 13 |
+
res = glom(target, 'a.b.c')
|
| 14 |
+
|
| 15 |
+
assert res == val
|
| 16 |
+
|
| 17 |
+
contact = Contact('Julian', emails=[Email('julian@sunnyvaletrailerpark.info')])
|
| 18 |
+
contact.save()
|
| 19 |
+
assert Contact.objects.get(contact_id=contact.id) is contact
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/pytest.ini
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest]
|
| 2 |
+
doctest_optionflags=NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ELLIPSIS
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/setup.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.util
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from setuptools import setup
|
| 5 |
+
|
| 6 |
+
__author__ = 'Mahmoud Hashemi and Kurt Rose'
|
| 7 |
+
__contact__ = 'mahmoud@hatnote.com'
|
| 8 |
+
__url__ = 'https://github.com/mahmoud/glom'
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def import_path(module_name, path):
|
| 12 |
+
spec = importlib.util.spec_from_file_location(module_name, path)
|
| 13 |
+
module = importlib.util.module_from_spec(spec)
|
| 14 |
+
spec.loader.exec_module(module)
|
| 15 |
+
return module
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
CUR_PATH = os.path.abspath(os.path.dirname(__file__))
|
| 19 |
+
_version_mod_path = os.path.join(CUR_PATH, 'glom', '_version.py')
|
| 20 |
+
_version_mod = import_path('_version', _version_mod_path)
|
| 21 |
+
__version__ = _version_mod.__version__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
open_kwarg = {}
|
| 25 |
+
|
| 26 |
+
with open('README.md', encoding='utf8') as read_me:
|
| 27 |
+
long_description = read_me.read()
|
| 28 |
+
|
| 29 |
+
setup(name='glom',
|
| 30 |
+
version=__version__,
|
| 31 |
+
description="A declarative object transformer and formatter, for conglomerating nested data.",
|
| 32 |
+
long_description=long_description,
|
| 33 |
+
long_description_content_type='text/markdown',
|
| 34 |
+
author=__author__,
|
| 35 |
+
author_email=__contact__,
|
| 36 |
+
url=__url__,
|
| 37 |
+
project_urls={
|
| 38 |
+
'Documentation': 'https://glom.readthedocs.io/en/latest/',
|
| 39 |
+
},
|
| 40 |
+
packages=['glom', 'glom.test'],
|
| 41 |
+
install_requires=['boltons>=19.3.0', 'attrs', 'face>=20.1.1'],
|
| 42 |
+
extras_require={
|
| 43 |
+
'toml': ['tomli; python_version<"3.11"'],
|
| 44 |
+
'yaml': ['PyYAML'],
|
| 45 |
+
},
|
| 46 |
+
entry_points={'console_scripts': ['glom = glom.cli:console_main']},
|
| 47 |
+
include_package_data=True,
|
| 48 |
+
zip_safe=False,
|
| 49 |
+
platforms='any',
|
| 50 |
+
license_files=['LICENSE'],
|
| 51 |
+
classifiers=[
|
| 52 |
+
'Topic :: Utilities',
|
| 53 |
+
'Intended Audience :: Developers',
|
| 54 |
+
'Topic :: Software Development :: Libraries',
|
| 55 |
+
'Development Status :: 5 - Production/Stable',
|
| 56 |
+
'Programming Language :: Python :: 3.7',
|
| 57 |
+
'Programming Language :: Python :: 3.8',
|
| 58 |
+
'Programming Language :: Python :: 3.9',
|
| 59 |
+
'Programming Language :: Python :: 3.10',
|
| 60 |
+
'Programming Language :: Python :: 3.11',
|
| 61 |
+
'Programming Language :: Python :: 3.12',
|
| 62 |
+
'Programming Language :: Python :: Implementation :: CPython',
|
| 63 |
+
'Programming Language :: Python :: Implementation :: PyPy',
|
| 64 |
+
'License :: OSI Approved :: BSD License',
|
| 65 |
+
]
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
"""
|
| 69 |
+
A brief checklist for release:
|
| 70 |
+
|
| 71 |
+
* tox
|
| 72 |
+
* git commit (if applicable)
|
| 73 |
+
* Bump glom/_version.py off of -dev
|
| 74 |
+
* git commit -a -m "bump version for vx.y.z release"
|
| 75 |
+
* write CHANGELOG
|
| 76 |
+
* bump docs/conf.py version
|
| 77 |
+
* git commit
|
| 78 |
+
* rm -rf dist/*
|
| 79 |
+
* python setup.py sdist bdist_wheel
|
| 80 |
+
* twine upload dist/*
|
| 81 |
+
* git tag -a vx.y.z -m "brief summary"
|
| 82 |
+
* bump glom/_version.py onto n+1 dev
|
| 83 |
+
* git commit
|
| 84 |
+
* git push
|
| 85 |
+
|
| 86 |
+
NB: if dropping support for a python version, bump the pyupgrade argument in tox and run syntax-upgrade tox env.
|
| 87 |
+
|
| 88 |
+
"""
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/tests/trusted/tox.ini
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tox]
|
| 2 |
+
envlist = py37,py38,py39,py310,py311,py312,pypy3,coverage-report,packaging
|
| 3 |
+
|
| 4 |
+
[testenv]
|
| 5 |
+
changedir = .tox
|
| 6 |
+
deps = -rrequirements.txt
|
| 7 |
+
commands = coverage run --parallel --rcfile {toxinidir}/.tox-coveragerc -m pytest -vv --doctest-modules {envsitepackagesdir}/glom {posargs}
|
| 8 |
+
|
| 9 |
+
[testenv:coverage-report]
|
| 10 |
+
changedir = .tox
|
| 11 |
+
deps = coverage
|
| 12 |
+
commands = coverage combine --rcfile {toxinidir}/.tox-coveragerc
|
| 13 |
+
coverage xml --rcfile {toxinidir}/.tox-coveragerc
|
| 14 |
+
coverage report --rcfile {toxinidir}/.tox-coveragerc
|
| 15 |
+
coverage html --rcfile {toxinidir}/.tox-coveragerc -d {toxinidir}/htmlcov
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
[testenv:packaging]
|
| 19 |
+
changedir = {toxinidir}
|
| 20 |
+
deps =
|
| 21 |
+
check-manifest==0.50
|
| 22 |
+
commands =
|
| 23 |
+
check-manifest
|
| 24 |
+
|
| 25 |
+
[testenv:syntax-upgrade]
|
| 26 |
+
changedir = {toxinidir}
|
| 27 |
+
deps =
|
| 28 |
+
flynt
|
| 29 |
+
pyupgrade
|
| 30 |
+
commands =
|
| 31 |
+
flynt ./glom
|
| 32 |
+
python -c "import glob; import subprocess; [subprocess.run(['pyupgrade', '--py37-plus', f]) for f in glob.glob('./glom/**/*.py', recursive=True)]"
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/canaries/first-hunk-only.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_PARTIAL'
|
| 5 |
+
diff --git a/glom/grouping.py b/glom/grouping.py
|
| 6 |
+
index a2b07d664dd102c9b25f3942e1011becd7c0b582..122bd0863df47161b8eb663797705f4c3e00a4ab 100644
|
| 7 |
+
--- a/glom/grouping.py
|
| 8 |
+
+++ b/glom/grouping.py
|
| 9 |
+
@@ -209,8 +209,8 @@
|
| 10 |
+
__slots__ = ()
|
| 11 |
+
|
| 12 |
+
def agg(self, target, tree):
|
| 13 |
+
- if self not in tree or target < tree[self]:
|
| 14 |
+
- tree[self] = target - 1
|
| 15 |
+
+ if self not in tree or target > tree[self]:
|
| 16 |
+
+ tree[self] = target
|
| 17 |
+
return tree[self]
|
| 18 |
+
|
| 19 |
+
def __repr__(self):
|
| 20 |
+
OPENENV_PARTIAL
|
| 21 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/canaries/original-bug.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
:
|
tasks/mahmoud__glom.fb3c4e76.combine_file__g5ew8sro/validation/openenv.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canaries": "validation/canaries",
|
| 3 |
+
"profile": "harbor-semantic-v1",
|
| 4 |
+
"requires_credentials": false,
|
| 5 |
+
"resources": {
|
| 6 |
+
"cpu": 2,
|
| 7 |
+
"disk_mb": 16384,
|
| 8 |
+
"episode_timeout_s": 1800,
|
| 9 |
+
"memory_mb": 8192
|
| 10 |
+
},
|
| 11 |
+
"reward": {
|
| 12 |
+
"floor_margin": 0.1,
|
| 13 |
+
"oracle_tolerance": 0,
|
| 14 |
+
"range": [
|
| 15 |
+
0,
|
| 16 |
+
1
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
"reward_key": "reward",
|
| 20 |
+
"types": {
|
| 21 |
+
"tags": [
|
| 22 |
+
"swe",
|
| 23 |
+
"python",
|
| 24 |
+
"mutation-repair"
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
}
|
tasks/mahmoud__glom.fb3c4e76.combine_file__izanr69t/LICENSE.source
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018, Mahmoud Hashemi
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are
|
| 7 |
+
met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright
|
| 10 |
+
notice, this list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above
|
| 13 |
+
copyright notice, this list of conditions and the following
|
| 14 |
+
disclaimer in the documentation and/or other materials provided
|
| 15 |
+
with the distribution.
|
| 16 |
+
|
| 17 |
+
* The names of the contributors may not be used to endorse or
|
| 18 |
+
promote products derived from this software without specific
|
| 19 |
+
prior written permission.
|
| 20 |
+
|
| 21 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 22 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 23 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 24 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 25 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 26 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 27 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 28 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 29 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 30 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|