修复:输出前缀绑定替换保留原引号,避免 Python -c 字符串字面量变裸标识符(zh01 NameError)
This commit is contained in:
@@ -1528,3 +1528,31 @@ def test_replay_isolates_symlink_input_before_source_overwrite(
|
||||
}
|
||||
]
|
||||
assert result["execution_work_tree"]["Ft.input.txt"]["type"] == "regular"
|
||||
|
||||
|
||||
def test_shell_word_replacement_preserves_python_string_literal_quotes() -> None:
|
||||
"""zh01 回归:python -c 里带引号的输出路径被前缀替换后必须保留引号。
|
||||
|
||||
替换前:SeqIO.write(...,'combined.pep.fasta','fasta')
|
||||
若用 shlex.quote 替换会变成 SeqIO.write(...,output.fasta,'fasta')
|
||||
→ Python 报 NameError: name 'output' is not defined。
|
||||
"""
|
||||
pattern = runtime_module._shell_word_pattern("combined.pep.fasta")
|
||||
replace = runtime_module._shell_word_replacement("output.fasta")
|
||||
source = (
|
||||
"python -c \"from Bio import SeqIO; "
|
||||
"SeqIO.write(list(SeqIO.parse('Ft.SPL.pep.fasta','fasta')),"
|
||||
"'combined.pep.fasta','fasta')\" && "
|
||||
"muscle -in combined.pep.fasta -out combined.pep.mfa"
|
||||
)
|
||||
updated, count = pattern.subn(replace, source)
|
||||
assert count == 2
|
||||
assert "'output.fasta'" in updated
|
||||
assert "'combined.pep.fasta'" not in updated
|
||||
# 无引号的 shell 单词路径不受影响(不引入引号)
|
||||
shell_text = "muscle -in combined.pep.mfa -out combined.pep.mfa2"
|
||||
updated_shell, shell_count = runtime_module._shell_word_pattern(
|
||||
"combined.pep.mfa"
|
||||
).subn(runtime_module._shell_word_replacement("output.mfa"), shell_text)
|
||||
assert shell_count == 1
|
||||
assert "-in output.mfa" in updated_shell
|
||||
|
||||
Reference in New Issue
Block a user