Skip to content
Open
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
3 changes: 2 additions & 1 deletion liminal/base/base_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def __repr__(self) -> str:
if k.startswith("_"):
continue
if isinstance(v, str):
args.append(f"'{v}'")
# repr() quotes and escapes, so names like "5' UTR" stay valid Python
args.append(repr(str(v)))
else:
args.append(f"{v.__repr__()}")
return f"{self.__class__.__name__}({', '.join(args)})"
Expand Down
37 changes: 37 additions & 0 deletions liminal/tests/test_revision_file_quotes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pathlib import Path

import pytest

import liminal.external as b
from liminal.base.base_operation import BaseOperation
from liminal.migrate.revision import Revision


@pytest.mark.parametrize(
"operation",
[
b.CreateDropdownOption("Primer End", "5' UTR", 0),
b.UpdateDropdownName("Donor's Sex", "Donor Sex"),
b.CreateDropdown("Owner's Team", ["O'Brien Lab", 'Size 10"']),
],
)
def test_revision_file_string_round_trips_quotes(operation: BaseOperation) -> None:
back = eval(operation.revision_file_string(), {"b": b})
assert repr(back) == repr(operation)


def test_revision_file_with_apostrophes_parses_back(tmp_path: Path) -> None:
operations: list[BaseOperation] = [
b.CreateDropdown("Primer End", ["5' UTR", "3' UTR"]),
b.CreateDropdownOption("Primer End", "5' ITR", 2),
]
revision = Revision(
id=Revision.new_id(),
description="apostrophes in dropdown names",
down_revision_id=None,
upgrade_operations=operations,
downgrade_operations=[],
)
path = revision.write_revision_file(tmp_path)
parsed = Revision.parse_from_file(path)
assert [repr(o) for o in parsed.upgrade_operations] == [repr(o) for o in operations]