Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

641: Allow whitespace on either side of main header delimiter #718

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dealias_and_group_headers(
header = header.lower()

if use_double_colons:
tokens = header.split(group_delimiter)
tokens = [t.strip() for t in header.split(group_delimiter)]

# else:
# We do the initial parse using single colons
Expand All @@ -152,7 +152,7 @@ def dealias_and_group_headers(
# break if there is something like media:image:english
# so maybe a better backwards compatibility hack
# is to join any jr token with the next token
tokens = header.split(":")
tokens = [t.strip() for t in header.split(":")]
if "jr" in tokens:
jr_idx = tokens.index("jr")
tokens[jr_idx] = ":".join(tokens[jr_idx : jr_idx + 2])
Expand Down
23 changes: 23 additions & 0 deletions tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ def test_double_colon_translations(self):
warnings_count=0,
)

def test_spaces_adjacent_to_translation_delimiter(self):
"""Should trim whitespace either side of double-colon '::' delimiter."""
md = """
| survey |
| | type | name | label::French (fr) | constraint | constraint_message::French (fr) | constraint_message :: English (en) |
| | text | q1 | Q1 | string-length(.) > 5 | Trop court! | Too short! |
"""
self.assertPyxformXform(
md=md,
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:itext/x:translation[@lang='French (fr)']
/x:text[@id='/test_name/q1:jr:constraintMsg']
/x:value[not(@form) and text()='Trop court!']
""",
"""
/h:html/h:head/x:model/x:itext/x:translation[@lang='English (en)']
/x:text[@id='/test_name/q1:jr:constraintMsg']
/x:value[not(@form) and text()='Too short!']
""",
],
)

def test_missing_media_itext(self):
"""Test missing media itext translation

Expand Down
Loading