当前位置: 首页>>代码示例>>Python>>正文


Python ScriptParser.eval方法代码示例

本文整理汇总了Python中picard.script.ScriptParser.eval方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptParser.eval方法的具体用法?Python ScriptParser.eval怎么用?Python ScriptParser.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在picard.script.ScriptParser的用法示例。


在下文中一共展示了ScriptParser.eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _example_to_filename

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def _example_to_filename(self, file):
     settings = {
         'windows_compatibility': self.ui.windows_compatibility.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.ui.move_files.isChecked(),
         'use_va_format': False,  # TODO remove
         'file_naming_format': self.ui.file_naming_format.toPlainText(),
         'move_files_to': os.path.normpath(self.ui.move_files_to.text())
     }
     try:
         if config.setting["enable_tagger_scripts"]:
             for s_pos, s_name, s_enabled, s_text in config.setting["list_of_scripts"]:
                 if s_enabled and s_text:
                     parser = ScriptParser()
                     parser.eval(s_text, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         if not settings["move_files"]:
             return os.path.basename(filename)
         return filename
     except SyntaxError:
         return ""
     except ScriptError:
         return ""
     except TypeError:
         return ""
开发者ID:JDLH,项目名称:picard,代码行数:28,代码来源:renaming.py

示例2: _example_to_filename

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def _example_to_filename(self, file):
     settings = {
         'windows_compatibility': self.ui.windows_compatibility.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.ui.move_files.isChecked(),
         'use_va_format': False,  # TODO remove
         'file_naming_format': unicode(self.ui.file_naming_format.toPlainText()),
         'move_files_to': os.path.normpath(unicode(self.ui.move_files_to.text()))
     }
     try:
         if config.setting["enable_tagger_script"]:
             script = config.setting["tagger_script"]
             parser = ScriptParser()
             parser.eval(script, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         if not settings["move_files"]:
             return os.path.basename(filename)
         return filename
     except SyntaxError:
         return ""
     except ScriptError:
         return ""
     except TypeError:
         return ""
     except UnknownFunction:
         return ""
开发者ID:KLuken,项目名称:picard,代码行数:29,代码来源:renaming.py

示例3: _finalize_loading

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _finalize_loading(self, error):
        if error:
            self.metadata.clear()
            self.metadata['album'] = _("[could not load album %s]") % self.id
            del self._new_metadata
            del self._new_tracks
            self.update()
            return

        # Run metadata plugins
        while self._metadata_plugins:
            try:
                self._metadata_plugins.popleft()()
            except:
                self.log.error(traceback.format_exc())

        if not self._requests:
            # Prepare parser for user's script
            script = None
            if self.config.setting["enable_tagger_script"]:
                script = self.config.setting["tagger_script"]
                parser = ScriptParser()

            for track in self._new_tracks:
                # Update the track with new album metadata, in case it
                # was modified by plugins.
                for key, values in self._new_metadata.rawitems():
                    track.metadata[key] = values[:]
                # Run tagger script for each track
                if script:
                    try:
                        parser.eval(script, track.metadata)
                    except:
                        self.log.error(traceback.format_exc())
                    # Strip leading/trailing whitespace
                    track.metadata.strip_whitespace()

            # Run tagger script for the album itself
            if script:
                try:
                    parser.eval(script, self._new_metadata)
                except:
                    self.log.error(traceback.format_exc())
                self._new_metadata.strip_whitespace()

            for track in self.tracks:
                for file in list(track.linked_files):
                    file.move(self.unmatched_files)
            self.metadata = self._new_metadata
            self.tracks = self._new_tracks
            del self._new_metadata
            del self._new_tracks
            self.loaded = True
            self.match_files(self.unmatched_files.files)
            self.update()
            self.tagger.window.set_statusbar_message('Album %s loaded', self.id, timeout=3000)
            while self._after_load_callbacks.qsize() > 0:
                func = self._after_load_callbacks.get()
                func()
开发者ID:lalinsky,项目名称:picard-debian,代码行数:61,代码来源:album.py

示例4: check_format

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def check_format(self):
     parser = ScriptParser()
     try:
         parser.eval(unicode(self.ui.file_naming_format.toPlainText()))
     except Exception as e:
         raise OptionsCheckError("", str(e))
     if self.ui.rename_files.isChecked():
         if not unicode(self.ui.file_naming_format.toPlainText()).strip():
             raise OptionsCheckError("", _("The file naming format must not be empty."))
开发者ID:KLuken,项目名称:picard,代码行数:11,代码来源:renaming.py

示例5: process

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def process(self, script):
        files = self.files

        for file in files:
            m = file.metadata
            parser = ScriptParser()
            try:
                parser.eval(script, m)
            except:
                log.error(traceback.format_exc())
            m.strip_whitespace()
开发者ID:rupa108,项目名称:picard_plugins,代码行数:13,代码来源:__init__.py

示例6: _run_script

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _run_script(self, script):
        s_name = script[1]
        s_text = script[3]
        parser = ScriptParser()

        for obj in self._get_unique_metadata_objects():
            try:
                parser.eval(s_text, obj.metadata)
                obj.update()
            except ScriptError as e:
                log.exception('Error running tagger script "%s" on object %r', s_name, obj)
                msg = N_('Script error in "%(script)s": %(message)s')
                mparms = {
                    'script': s_name,
                    'message': str(e),
                }
                self.tagger.window.set_statusbar_message(msg, mparms)
开发者ID:Jormangeud,项目名称:picard,代码行数:19,代码来源:scriptsmenu.py

示例7: _parse_recording

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def _parse_recording(self, recording):
     recording_to_metadata(recording, self, self.config)
     self._customize_metadata()
     m = self.metadata
     run_track_metadata_processors(self.album, m, None, recording)
     if self.config.setting["enable_tagger_script"]:
         script = self.config.setting["tagger_script"]
         if script:
             parser = ScriptParser()
             try:
                 parser.eval(script, m)
             except:
                 self.log.error(traceback.format_exc())
             m.strip_whitespace()
     self.loaded = True
     if self.callback:
         self.callback()
     self.tagger.nats.update(True)
开发者ID:betoth2001,项目名称:picard,代码行数:20,代码来源:track.py

示例8: _parse_recording

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _parse_recording(self, recording):
        m = self.metadata
        recording_to_metadata(recording, m, self)
        self._customize_metadata()
        run_track_metadata_processors(self.album, m, None, recording)
        if config.setting["enable_tagger_scripts"]:
            for s_pos, s_name, s_enabled, s_text in config.setting["list_of_scripts"]:
                if s_enabled and s_text:
                    parser = ScriptParser()
                    try:
                        parser.eval(s_text, m)
                    except:
                        log.error(traceback.format_exc())
                    m.strip_whitespace()

        self.loaded = True
        if self.callback:
            self.callback()
            self.callback = None
        self.tagger.nats.update(True)
开发者ID:Sophist-UK,项目名称:Sophist_picard,代码行数:22,代码来源:track.py

示例9: _parse_recording

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _parse_recording(self, recording):
        m = self.metadata
        recording_to_metadata(recording, m, self)
        self.orig_metadata.copy(m)
        self._customize_metadata()
        run_track_metadata_processors(self.album, m, None, recording)
        for s_name, s_text in enabled_tagger_scripts_texts():
            parser = ScriptParser()
            try:
                parser.eval(s_text, m)
            except ScriptError:
                log.exception("Failed to run tagger script %s on track", s_name)
            m.strip_whitespace()

        self.loaded = True
        self.status = None
        if self.callback:
            self.callback()
            self.callback = None
        self.album.update(True)
开发者ID:Jormangeud,项目名称:picard,代码行数:22,代码来源:track.py

示例10: _example_to_filename

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def _example_to_filename(self, file):
     settings = {
         'windows_compatible_filenames': self.ui.windows_compatible_filenames.isChecked(),
         'ascii_filenames': self.ui.ascii_filenames.isChecked(),
         'rename_files': self.ui.rename_files.isChecked(),
         'move_files': self.config.setting["move_files"],
         'use_va_format': self.ui.use_va_format.isChecked(),
         'file_naming_format': unicode(self.ui.file_naming_format.toPlainText()),
         'va_file_naming_format': unicode(self.ui.va_file_naming_format.toPlainText()),
         'move_files_to': os.path.normpath(unicode(self.config.setting["move_files_to"])),
     }
     try:
         if self.config.setting["enable_tagger_script"]:
             script = self.config.setting["tagger_script"]
             parser = ScriptParser()
             parser.eval(script, file.metadata)
         filename = file._make_filename(file.filename, file.metadata, settings)
         return filename
     except SyntaxError, e: return ""
     except TypeError, e: return ""
     except UnknownFunction, e: return ""
开发者ID:lalinsky,项目名称:picard-debian,代码行数:23,代码来源:renaming.py

示例11: _finalize_loading

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _finalize_loading(self, error):
        if error:
            self.metadata.clear()
            self.metadata['album'] = _("[could not load album %s]") % self.id
            del self._new_metadata
            del self._new_tracks
            self.update()
            return

        if self._requests > 0:
            return

        if not self._tracks_loaded:
            artists = set()
            totalalbumtracks = 0

            djmix_ars = {}
            if hasattr(self._new_metadata, "_djmix_ars"):
                djmix_ars = self._new_metadata._djmix_ars

            for medium_node in self._release_node.medium_list[0].medium:
                mm = Metadata()
                mm.copy(self._new_metadata)
                medium_to_metadata(medium_node, mm)
                totalalbumtracks += int(mm["totaltracks"])

                for dj in djmix_ars.get(mm["discnumber"], []):
                    mm.add("djmixer", dj)

                for track_node in medium_node.track_list[0].track:
                    track = Track(track_node.recording[0].id, self)
                    self._new_tracks.append(track)

                    # Get track metadata
                    tm = track.metadata
                    tm.copy(mm)
                    track_to_metadata(track_node, track, self.config)
                    track._customize_metadata()

                    self._new_metadata.length += tm.length
                    artists.add(tm["musicbrainz_artistid"])

                    # Run track metadata plugins
                    try:
                        run_track_metadata_processors(self, tm, self._release_node, track_node)
                    except:
                        self.log.error(traceback.format_exc())

            totalalbumtracks = str(totalalbumtracks)

            for track in self._new_tracks:
                track.metadata["~totalalbumtracks"] = totalalbumtracks
                if len(artists) > 1:
                    track.metadata["compilation"] = "1"

            del self._release_node
            self._tracks_loaded = True

        if not self._requests:
            # Prepare parser for user's script
            if self.config.setting["enable_tagger_script"]:
                script = self.config.setting["tagger_script"]
                if script:
                    parser = ScriptParser()
                    for track in self._new_tracks:
                        # Run tagger script for each track
                        try:
                            parser.eval(script, track.metadata)
                        except:
                            self.log.error(traceback.format_exc())
                        # Strip leading/trailing whitespace
                        track.metadata.strip_whitespace()
                    # Run tagger script for the album itself
                    try:
                        parser.eval(script, self._new_metadata)
                    except:
                        self.log.error(traceback.format_exc())
                    self._new_metadata.strip_whitespace()

            for track in self.tracks:
                for file in list(track.linked_files):
                    file.move(self.unmatched_files)
            self.metadata = self._new_metadata
            self.tracks = self._new_tracks
            del self._new_metadata
            del self._new_tracks
            self.loaded = True
            self.match_files(self.unmatched_files.files)
            self.update()
            self.tagger.window.set_statusbar_message(_('Album %s loaded'), self.id, timeout=3000)
            while self._after_load_callbacks.qsize() > 0:
                func = self._after_load_callbacks.get()
                func()
开发者ID:rossabaker,项目名称:picard,代码行数:95,代码来源:album.py

示例12: check

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
 def check(self):
     parser = ScriptParser()
     try:
         parser.eval(unicode(self.ui.tagger_script.toPlainText()))
     except Exception as e:
         raise OptionsCheckError(_("Script Error"), str(e))
开发者ID:noupiii,项目名称:picard,代码行数:8,代码来源:scripting.py

示例13: _finalize_loading

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
    def _finalize_loading(self, error):
        if error:
            self.metadata.clear()
            self.status = _("[could not load album %s]") % self.id
            del self._new_metadata
            del self._new_tracks
            self.update()
            return

        if self._requests > 0:
            return

        if not self._tracks_loaded:
            artists = set()
            totalalbumtracks = 0
            absolutetracknumber = 0
            va = self._new_metadata['musicbrainz_albumartistid'] == VARIOUS_ARTISTS_ID

            djmix_ars = {}
            if hasattr(self._new_metadata, "_djmix_ars"):
                djmix_ars = self._new_metadata._djmix_ars

            for medium_node in self._release_node['media']:
                mm = Metadata()
                mm.copy(self._new_metadata)
                medium_to_metadata(medium_node, mm)
                discpregap = False

                for dj in djmix_ars.get(mm["discnumber"], []):
                    mm.add("djmixer", dj)

                if 'discs' in medium_node:
                    discids = [disc.get('id') for disc in medium_node['discs']]
                    mm['~musicbrainz_discids'] = discids
                    mm['musicbrainz_discid'] = list(self._discids.intersection(discids))

                if "pregap" in medium_node:
                    discpregap = True
                    absolutetracknumber += 1
                    track = self._finalize_loading_track(medium_node['pregap'], mm, artists, va, absolutetracknumber, discpregap)
                    track.metadata['~pregap'] = "1"

                track_count = medium_node['track-count']
                if track_count:
                    tracklist_node = medium_node['tracks']
                    for track_node in tracklist_node:
                        absolutetracknumber += 1
                        track = self._finalize_loading_track(track_node, mm, artists, va, absolutetracknumber, discpregap)

                if "data-tracks" in medium_node:
                    for track_node in medium_node['data-tracks']:
                        absolutetracknumber += 1
                        track = self._finalize_loading_track(track_node, mm, artists, va, absolutetracknumber, discpregap)
                        track.metadata['~datatrack'] = "1"

            totalalbumtracks = str(absolutetracknumber)

            for track in self._new_tracks:
                track.metadata["~totalalbumtracks"] = totalalbumtracks
                if len(artists) > 1:
                    track.metadata["~multiartist"] = "1"
            del self._release_node
            del self._release_artist_nodes
            self._tracks_loaded = True

        if not self._requests:
            self.enable_update_metadata_images(False)
            # Prepare parser for user's script
            for s_name, s_text in enabled_tagger_scripts_texts():
                parser = ScriptParser()
                for track in self._new_tracks:
                    # Run tagger script for each track
                    try:
                        parser.eval(s_text, track.metadata)
                    except ScriptError:
                        log.exception("Failed to run tagger script %s on track", s_name)
                    track.metadata.strip_whitespace()
                # Run tagger script for the album itself
                try:
                    parser.eval(s_text, self._new_metadata)
                except ScriptError:
                    log.exception("Failed to run tagger script %s on album", s_name)
                self._new_metadata.strip_whitespace()

            for track in self.tracks:
                track.metadata_images_changed.connect(self.update_metadata_images)
                for file in list(track.linked_files):
                    file.move(self.unmatched_files)
            self.metadata = self._new_metadata
            self.tracks = self._new_tracks
            del self._new_metadata
            del self._new_tracks
            self.loaded = True
            self.status = None
            self.match_files(self.unmatched_files.files)
            self.enable_update_metadata_images(True)
            self.update()
            self.tagger.window.set_statusbar_message(
                N_('Album %(id)s loaded: %(artist)s - %(album)s'),
                {
#.........这里部分代码省略.........
开发者ID:Jormangeud,项目名称:picard,代码行数:103,代码来源:album.py

示例14: ScriptParserTest

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
class ScriptParserTest(unittest.TestCase):

    def setUp(self):
        config.setting = {
            'enabled_plugins': '',
        }

        self.parser = ScriptParser()

        def func_noargstest(parser):
            return ""

        register_script_function(func_noargstest, "noargstest")

    def assertScriptResultEquals(self, script, expected, context=None):
        """Asserts that evaluating `script` returns `expected`.


        Args:
            script: The tagger script
            expected: The expected result
            context: A Metadata object with pre-set tags or None
        """
        actual = self.parser.eval(script, context=context)
        self.assertEqual(actual,
                         expected,
                         "'%s' evaluated to '%s', expected '%s'"
                         % (script, actual, expected))

    def test_cmd_noop(self):
        self.assertScriptResultEquals("$noop()", "")
        self.assertScriptResultEquals("$noop(abcdefg)", "")

    def test_cmd_if(self):
        self.assertScriptResultEquals("$if(1,a,b)", "a")
        self.assertScriptResultEquals("$if(,a,b)", "b")

    def test_cmd_if2(self):
        self.assertScriptResultEquals("$if2(,a,b)", "a")
        self.assertScriptResultEquals("$if2($noop(),b)", "b")

    def test_cmd_left(self):
        self.assertScriptResultEquals("$left(abcd,2)", "ab")

    def test_cmd_right(self):
        self.assertScriptResultEquals("$right(abcd,2)", "cd")

    def test_cmd_set(self):
        self.assertScriptResultEquals("$set(test,aaa)%test%", "aaa")

    def test_cmd_set_empty(self):
        self.assertScriptResultEquals("$set(test,)%test%", "")

    def test_cmd_set_multi_valued(self):
        context = Metadata()
        context["source"] = ["multi", "valued"]
        self.parser.eval("$set(test,%source%)", context)
        self.assertEqual(context.getall("test"), ["multi; valued"])  # list has only a single value

    def test_cmd_setmulti_multi_valued(self):
        context = Metadata()
        context["source"] = ["multi", "valued"]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_multi_valued_wth_spaces(self):
        context = Metadata()
        context["source"] = ["multi, multi", "valued, multi"]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_not_multi_valued(self):
        context = Metadata()
        context["source"] = "multi, multi"
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_will_remove_empty_items(self):
        context = Metadata()
        context["source"] = ["", "multi", ""]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(["multi"], context.getall("test"))

    def test_cmd_setmulti_custom_splitter_string(self):
        context = Metadata()
        self.assertEqual("", self.parser.eval("$setmulti(test,multi##valued##test##,##)", context))  # no return value
        self.assertEqual(["multi", "valued", "test"], context.getall("test"))

    def test_cmd_setmulti_empty_splitter_does_nothing(self):
        context = Metadata()
        self.assertEqual("", self.parser.eval("$setmulti(test,multi; valued,)", context))  # no return value
        self.assertEqual(["multi; valued"], context.getall("test"))

    def test_cmd_get(self):
        context = Metadata()
        context["test"] = "aaa"
        self.assertScriptResultEquals("$get(test)", "aaa", context)
        context["test2"] = ["multi", "valued"]
        self.assertScriptResultEquals("$get(test2)", "multi; valued", context)

#.........这里部分代码省略.........
开发者ID:Sophist-UK,项目名称:Sophist_picard,代码行数:103,代码来源:test_script.py

示例15: ScriptParserTest

# 需要导入模块: from picard.script import ScriptParser [as 别名]
# 或者: from picard.script.ScriptParser import eval [as 别名]
class ScriptParserTest(unittest.TestCase):

    def setUp(self):
        config.setting = {
            'enabled_plugins': '',
        }
        self.parser = ScriptParser()
        def func_noargstest(parser):
            return ""
        register_script_function(func_noargstest, "noargstest")

    def test_cmd_noop(self):
        self.assertEqual(self.parser.eval("$noop()"), "")
        self.assertEqual(self.parser.eval("$noop(abcdefg)"), "")

    def test_cmd_if(self):
        self.assertEqual(self.parser.eval("$if(1,a,b)"), "a")
        self.assertEqual(self.parser.eval("$if(,a,b)"), "b")

    def test_cmd_if2(self):
        self.assertEqual(self.parser.eval("$if2(,a,b)"), "a")
        self.assertEqual(self.parser.eval("$if2($noop(),b)"), "b")

    def test_cmd_left(self):
        self.assertEqual(self.parser.eval("$left(abcd,2)"), "ab")

    def test_cmd_right(self):
        self.assertEqual(self.parser.eval("$right(abcd,2)"), "cd")

    def test_cmd_set(self):
        self.assertEqual(self.parser.eval("$set(test,aaa)%test%"), "aaa")

    def test_cmd_set_empty(self):
        self.assertEqual(self.parser.eval("$set(test,)%test%"), "")

    def test_cmd_set_multi_valued(self):
        context = Metadata()
        context["source"] = ["multi", "valued"]
        self.parser.eval("$set(test,%source%)", context)
        self.assertEqual(context.getall("test"), ["multi; valued"])  # list has only a single value

    def test_cmd_setmulti_multi_valued(self):
        context = Metadata()
        context["source"] = ["multi", "valued"]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_multi_valued_wth_spaces(self):
        context = Metadata()
        context["source"] = ["multi, multi", "valued, multi"]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_not_multi_valued(self):
        context = Metadata()
        context["source"] = "multi, multi"
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(context.getall("source"), context.getall("test"))

    def test_cmd_setmulti_will_remove_empty_items(self):
        context = Metadata()
        context["source"] = ["", "multi", ""]
        self.assertEqual("", self.parser.eval("$setmulti(test,%source%)", context))  # no return value
        self.assertEqual(["multi"], context.getall("test"))

    def test_cmd_setmulti_custom_splitter_string(self):
        context = Metadata()
        self.assertEqual("", self.parser.eval("$setmulti(test,multi##valued##test##,##)", context))  # no return value
        self.assertEqual(["multi", "valued", "test"], context.getall("test"))

    def test_cmd_setmulti_empty_splitter_does_nothing(self):
        context = Metadata()
        self.assertEqual("", self.parser.eval("$setmulti(test,multi; valued,)", context))  # no return value
        self.assertEqual(["multi; valued"], context.getall("test"))

    def test_cmd_get(self):
        context = Metadata()
        context["test"] = "aaa"
        self.assertEqual(self.parser.eval("$get(test)", context), "aaa")
        context["test2"] = ["multi", "valued"]
        self.assertEqual(self.parser.eval("$get(test2)", context), "multi; valued")

    def test_cmd_num(self):
        self.assertEqual(self.parser.eval("$num(3,3)"), "003")
        self.assertEqual(self.parser.eval("$num(03,3)"), "003")
        self.assertEqual(self.parser.eval("$num(123,2)"), "123")

    def test_cmd_or(self):
        self.assertEqual(self.parser.eval("$or(,)"), "")
        self.assertEqual(self.parser.eval("$or(,,)"), "")
        self.assertEqual(self.parser.eval("$or(,q)"), "1")
        self.assertEqual(self.parser.eval("$or(q,)"), "1")
        self.assertEqual(self.parser.eval("$or(q,q)"), "1")
        self.assertEqual(self.parser.eval("$or(q,,)"), "1")

    def test_cmd_and(self):
        self.assertEqual(self.parser.eval("$and(,)"), "")
        self.assertEqual(self.parser.eval("$and(,q)"), "")
        self.assertEqual(self.parser.eval("$and(q,)"), "")
        self.assertEqual(self.parser.eval("$and(q,q,)"), "")
#.........这里部分代码省略.........
开发者ID:Freso,项目名称:picard,代码行数:103,代码来源:test_script.py


注:本文中的picard.script.ScriptParser.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。