Skip to content

Commit df03eb1

Browse files
committed
script_variable_tag_names(): use TagVar.script_name(), add test
1 parent f5967ca commit df03eb1

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

picard/ui/widgets/scripttextedit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def __init__(self, parent=None):
182182
@property
183183
def choices(self):
184184
yield from (f'${name}' for name in script_function_names())
185-
yield from (f'%{name}%'.replace('~', '_', 1) for name in script_variable_tag_names())
185+
yield from (f'%{name}%' for name in script_variable_tag_names())
186186

187187
def set_highlighted(self, text):
188188
self.last_selected = text

picard/util/tags.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,11 @@ def file_info_tag_names():
841841

842842
def script_variable_tag_names():
843843
"""Tag names available to scripts (used by script editor completer)"""
844-
yield from ALL_TAGS.names(selector=lambda tv: tv.is_script_variable)
844+
yield from (
845+
tagvar.script_name()
846+
for tagvar in ALL_TAGS
847+
if tagvar.is_script_variable
848+
)
845849

846850

847851
def display_tag_name(name):

test/test_util_tags.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
display_tag_name,
3333
parse_comment_tag,
3434
parse_subtag,
35+
script_variable_tag_names,
3536
)
3637

3738

@@ -158,6 +159,22 @@ def test_tagvars_display_name(self):
158159
with mock.patch("picard.util.tags._", return_value='translated'):
159160
self.assertEqual(tagvars.display_name('only_sd'), 'translated')
160161

162+
def test_script_variable_tag_names(self):
163+
tagvars = TagVars(
164+
self.tagvar_nodesc,
165+
self.tagvar_hidden,
166+
self.tagvar_hidden_sd,
167+
self.tagvar_only_sd,
168+
self.tagvar_sd_ld,
169+
)
170+
self.tagvar_sd_ld.is_script_variable = False
171+
172+
with mock.patch('picard.util.tags.ALL_TAGS', tagvars):
173+
self.assertEqual(
174+
tuple(script_variable_tag_names()),
175+
('nodesc', '_hidden', '_hidden_sd', 'only_sd'),
176+
)
177+
161178

162179
class UtilTagsTest(PicardTestCase):
163180
def test_display_tag_name(self):

0 commit comments

Comments
 (0)