Skip to content

Commit 038b34c

Browse files
fix: clarify func name, fix typo
1 parent 6c401c5 commit 038b34c

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

pyxform/survey.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,33 @@ def register_nsmap():
7777
register_nsmap()
7878

7979

80-
def share_same_repeat_parent(
80+
def get_path_relative_to_lcar(
8181
target: SurveyElement,
8282
source: SurveyElement,
8383
lcar_steps_source: int,
8484
lcar: SurveyElement,
8585
reference_parent: bool = False,
86-
):
86+
) -> tuple[int, str]:
8787
"""
88-
Returns a tuple of the number of steps from the source xpath to the lowest common
89-
ancestor repeat, and the xpath to the target xpath from the LCAR.
88+
Get the number of steps from the source to the LCAR, and the path to the target.
9089
91-
Function only called if target and source share a ancestor repeat.
90+
Implementation assumes that it is only called if target and source have an LCAR.
9291
93-
For example,
94-
xpath = /data/repeat_a/group_a/name
95-
context_xpath = /data/repeat_a/group_b/age
92+
Example:
93+
target = /data/repeat_a/group_a/name
94+
source = /data/repeat_a/group_b/age
95+
return = (2, "/group_a/name")
9696
97-
returns (2, '/group_a/name')'
97+
:param target: The reference target, like "/data/repeat/q1" for "${q1}"
98+
:param source: The reference source, where the reference is located.
99+
:param lcar_steps_source: The number of path segments from the source to the LCAR.
100+
:param lcar: The lowest common ancestor repeat.
101+
:param reference_parent: If True, calculate to the LCAR parent rather than the LCAR.
102+
This may not be actually honoured depending on the topography.
98103
"""
99104

100-
def is_repeat(i: SurveyElement) -> bool:
101-
return isinstance(i, Section) and i.type == constants.REPEAT
105+
def is_repeat(e: SurveyElement) -> bool:
106+
return isinstance(e, Section) and e.type == constants.REPEAT
102107

103108
# Currently reference_parent only used for itemsets containing a pyxform variable,
104109
# i.e. `select_one ${ref}`. In that case, an extra step up the reference path may be
@@ -1092,7 +1097,7 @@ def _relative_path(ref_name: str, _use_current: bool) -> str | None:
10921097
other=target, group_type=constants.REPEAT
10931098
)
10941099
if relation[0] == "Common Ancestor":
1095-
steps, ref_path = share_same_repeat_parent(
1100+
steps, ref_path = get_path_relative_to_lcar(
10961101
target=target,
10971102
source=context,
10981103
lcar_steps_source=relation[1],
File renamed without changes.

tests/pyxform_test_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def assertPyxformXform(
165165
odk_validate_error__contains = coalesce(odk_validate_error__contains, [])
166166
survey_valid = True
167167
result = None
168-
# Some tests explicitly turn off ODK Validate because they not valid forms, so
168+
# Some tests explicitly turn off ODK Validate because they are not valid forms, so
169169
# use the setting if any before applying the environment variable default.
170170
run_odk_validate = coalesce(run_odk_validate, PYXFORM_TESTS_RUN_ODK_VALIDATE)
171171

tests/test_survey.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pyxform import constants as const
66
from pyxform.question import InputQuestion
77
from pyxform.section import GroupedSection, RepeatingSection
8-
from pyxform.survey import Survey, share_same_repeat_parent
8+
from pyxform.survey import Survey, get_path_relative_to_lcar
99

1010
from tests.pyxform_test_case import PYXFORM_TESTS_RUN_ODK_VALIDATE, PyxformTestCase
1111

@@ -181,9 +181,9 @@ def build_survey_from_path_spec(
181181
return survey, target, source
182182

183183

184-
class TestShareSameRepeatParent(TestCase):
184+
class TestGetPathRelativeToLCAR(TestCase):
185185
"""
186-
Tests of pyxform.survey.share_same_repeat_parent
186+
Tests of pyxform.survey.get_path_relative_to_lcar
187187
"""
188188

189189
def assert_relative_path(
@@ -217,7 +217,7 @@ def assert_relative_path(
217217
relation = source.lowest_common_ancestor(
218218
other=target, group_type=const.REPEAT
219219
)
220-
observed = share_same_repeat_parent(
220+
observed = get_path_relative_to_lcar(
221221
target=target,
222222
source=source,
223223
lcar_steps_source=relation[1],
@@ -232,7 +232,7 @@ def assert_relative_path(
232232

233233
def test_relative_paths__combinations_max_inner_depth_of_2(self):
234234
"""Should find relative XPath and steps are calculated accurately."""
235-
path = Path(__file__).parent / "fixtures" / "share_same_repeat_parent_cases.csv"
235+
path = Path(__file__).parent / "fixtures" / "get_path_relative_to_lcar_cases.csv"
236236
with open(path) as f:
237237
for case in DictReader(f):
238238
self.assert_relative_path(

0 commit comments

Comments
 (0)