Ejemplo n.º 1
0
        def test_metadata_get(self):
            self.assertEqual("single1-value", self.metadata["single1"])
            self.assertEqual("single1-value", self.metadata.get("single1"))
            self.assertEqual(["single1-value"],
                             self.metadata.getall("single1"))
            self.assertEqual(["single1-value"],
                             self.metadata.getraw("single1"))

            self.assertEqual(MULTI_VALUED_JOINER.join(self.multi1),
                             self.metadata["multi1"])
            self.assertEqual(MULTI_VALUED_JOINER.join(self.multi1),
                             self.metadata.get("multi1"))
            self.assertEqual(self.multi1, self.metadata.getall("multi1"))
            self.assertEqual(self.multi1, self.metadata.getraw("multi1"))

            self.assertEqual("", self.metadata["nonexistent"])
            self.assertEqual(None, self.metadata.get("nonexistent"))
            self.assertEqual([], self.metadata.getall("nonexistent"))
            self.assertRaises(KeyError, self.metadata.getraw, "nonexistent")

            self.assertEqual(self.metadata._store.items(),
                             self.metadata.rawitems())
            metadata_items = [(x, z) for (x, y) in self.metadata.rawitems()
                              for z in y]
            self.assertEqual(metadata_items, list(self.metadata.items()))
Ejemplo n.º 2
0
    def test_metadata_applyfunc(self):
        def func(x):
            return x[1:]

        self.metadata.apply_func(func)

        self.assertEqual("ingle1-value", self.metadata["single1"])
        self.assertEqual("ingle1-value", self.metadata.get("single1"))
        self.assertEqual(["ingle1-value"], self.metadata.getall("single1"))

        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)),
                         self.metadata["multi1"])
        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)),
                         self.metadata.get("multi1"))
        self.assertEqual(list(map(func, self.multi1)),
                         self.metadata.getall("multi1"))

        self.assertEqual("", self.metadata["nonexistent"])
        self.assertEqual(None, self.metadata.get("nonexistent"))
        self.assertEqual([], self.metadata.getall("nonexistent"))

        self.assertEqual(dict.items(self.metadata), self.metadata.rawitems())
        metadata_items = [(x, z) for (x, y) in dict.items(self.metadata)
                          for z in y]
        self.assertEqual(metadata_items, list(self.metadata.items()))
Ejemplo n.º 3
0
    def test_metadata_applyfunc(self):
        def func(x): return x[1:]
        self.metadata.apply_func(func)

        self.assertEqual("ingle1-value", self.metadata["single1"])
        self.assertEqual("ingle1-value", self.metadata.get("single1"))
        self.assertEqual(["ingle1-value"], self.metadata.getall("single1"))

        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata["multi1"])
        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata.get("multi1"))
        self.assertEqual(list(map(func, self.multi1)), self.metadata.getall("multi1"))
Ejemplo n.º 4
0
    def test_metadata_applyfunc(self):
        def func(x): return x[1:]
        self.metadata.apply_func(func)

        self.assertEqual("ingle1-value", self.metadata["single1"])
        self.assertEqual("ingle1-value", self.metadata.get("single1"))
        self.assertEqual(["ingle1-value"], self.metadata.getall("single1"))

        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata["multi1"])
        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata.get("multi1"))
        self.assertEqual(list(map(func, self.multi1)), self.metadata.getall("multi1"))
Ejemplo n.º 5
0
    def test_metadata_get(self):
        self.assertEqual("single1-value", self.metadata["single1"])
        self.assertEqual("single1-value", self.metadata.get("single1"))
        self.assertEqual(["single1-value"], self.metadata.getall("single1"))

        self.assertEqual(MULTI_VALUED_JOINER.join(self.multi1), self.metadata["multi1"])
        self.assertEqual(MULTI_VALUED_JOINER.join(self.multi1), self.metadata.get("multi1"))
        self.assertEqual(self.multi1, self.metadata.getall("multi1"))

        self.assertEqual("", self.metadata["nonexistent"])
        self.assertEqual(None, self.metadata.get("nonexistent"))
        self.assertEqual([], self.metadata.getall("nonexistent"))

        self.assertEqual(dict.items(self.metadata), self.metadata.rawitems())
        metadata_items = [(x, z) for (x, y) in dict.items(self.metadata) for z in y]
        self.assertEqual(metadata_items, list(self.metadata.items()))
Ejemplo n.º 6
0
 def get(self, name, default=None):
     values = dict.get(self, name, None)
     if not values:
         return default
     vals = self.__id3v23_date(name, values)
     if config.setting["write_id3v23"]:
         return config.setting["id3v23_join_with"].join(vals)
     else:
         return MULTI_VALUED_JOINER.join(vals)
Ejemplo n.º 7
0
 def get(self, name, default=None):
     values = dict.get(self, name, None)
     if not values:
         return default
     vals = self.__id3v23_date(name, values)
     if config.setting["write_id3v23"]:
         return config.setting["id3v23_join_with"].join(vals)
     else:
         return MULTI_VALUED_JOINER.join(vals)
Ejemplo n.º 8
0
    def test_metadata_applyfunc(self):
        func = lambda x: x[1:]
        self.metadata.apply_func(func)

        self.assertEqual("ingle1-value", self.metadata["single1"])
        self.assertEqual("ingle1-value", self.metadata.get("single1"))
        self.assertEqual(["ingle1-value"], self.metadata.getall("single1"))

        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata["multi1"])
        self.assertEqual(MULTI_VALUED_JOINER.join(map(func, self.multi1)), self.metadata.get("multi1"))
        self.assertEqual(list(map(func, self.multi1)), self.metadata.getall("multi1"))

        self.assertEqual("", self.metadata["nonexistent"])
        self.assertEqual(None, self.metadata.get("nonexistent"))
        self.assertEqual([], self.metadata.getall("nonexistent"))

        self.assertEqual(dict.items(self.metadata), self.metadata.rawitems())
        metadata_items = [(x, z) for (x, y) in dict.items(self.metadata) for z in y]
        self.assertEqual(metadata_items, list(self.metadata.items()))
Ejemplo n.º 9
0
 def test_metadata_mapping_init(self):
     d = {'a': 'b', 'c': 2, 'd': ['x', 'y'], 'x': '', 'z': {'u', 'w'}}
     deleted_tags = set('c')
     m = Metadata(d, deleted_tags=deleted_tags, length=1234)
     self.assertTrue('a' in m)
     self.assertEqual(m.getraw('a'), ['b'])
     self.assertEqual(m['d'], MULTI_VALUED_JOINER.join(d['d']))
     self.assertNotIn('c', m)
     self.assertNotIn('length', m)
     self.assertIn('c', m.deleted_tags)
     self.assertEqual(m.length, 1234)
Ejemplo n.º 10
0
 def test_metadata_mapping_init(self):
     d = {'a': 'b', 'c': 2, 'd': ['x', 'y'], 'x': '', 'z': {'u', 'w'}}
     deleted_tags = set('c')
     m = Metadata(d, deleted_tags=deleted_tags, length=1234)
     self.assertTrue('a' in m)
     self.assertEqual(m.getraw('a'), ['b'])
     self.assertEqual(m['d'], MULTI_VALUED_JOINER.join(d['d']))
     self.assertNotIn('c', m)
     self.assertNotIn('length', m)
     self.assertIn('c', m.deleted_tags)
     self.assertEqual(m.length, 1234)
Ejemplo n.º 11
0
 def copy_value(self):
     item = self.currentItem()
     if item:
         column = item.column()
         tag = self.tag_diff.tag_names[item.row()]
         value = None
         if column == self.COLUMN_ORIG:
             value = self.tag_diff.orig[tag]
         elif column == self.COLUMN_NEW:
             value = self.tag_diff.new[tag]
         if tag == '~length':
             value = [format_time(value or 0), ]
         if value is not None:
             self.tagger.clipboard().setText(MULTI_VALUED_JOINER.join(value))
             self.clipboard = value
Ejemplo n.º 12
0
    def display_value(self, tag):
        count = self.counts[tag]
        missing = self.parent.objects - count

        if tag in self.different:
            return (ungettext("(different across %d item)", "(different across %d items)", count) % count, True)
        else:
            if tag == "~length":
                msg = format_time(self.get(tag, 0))
            else:
                msg = MULTI_VALUED_JOINER.join(self[tag])

            if count > 0 and missing > 0:
                return (msg + " " + (ungettext("(missing from %d item)", "(missing from %d items)", missing) % missing), True)
            else:
                return (msg, False)
Ejemplo n.º 13
0
    def display_value(self, tag):
        count = self.counts[tag]
        missing = self.parent.objects - count

        if tag in self.different:
            return (ungettext("(different across %d item)", "(different across %d items)", count) % count, True)
        else:
            if tag == "~length":
                msg = format_time(self.get(tag, 0))
            else:
                msg = MULTI_VALUED_JOINER.join(self[tag])

            if count > 0 and missing > 0:
                return (msg + " " + (ungettext("(missing from %d item)", "(missing from %d items)", missing) % missing), True)
            else:
                return (msg, False)
Ejemplo n.º 14
0
 def edit(self, index, trigger, event):
     if index.column() != 2:
         return False
     item = self.itemFromIndex(index)
     if item.flags() & QtCore.Qt.ItemIsEditable and \
        trigger in (QtGui.QAbstractItemView.DoubleClicked,
                    QtGui.QAbstractItemView.EditKeyPressed,
                    QtGui.QAbstractItemView.AnyKeyPressed):
         tag = self.tag_names[item.row()]
         values = self.tag_diff.new[tag]
         if len(values) > 1:
             self.edit_tag(tag)
             return False
         else:
             self.editing = True
             self.itemChanged.disconnect(self.item_changed)
             item.setText(MULTI_VALUED_JOINER.join(values))
             self.itemChanged.connect(self.item_changed)
             return QtGui.QTableWidget.edit(self, index, trigger, event)
     return False
Ejemplo n.º 15
0
    def display_value(self, tag):
        count = self.counts[tag]
        missing = self.parent.objects - count

        if tag in self.different:
            return (ngettext("(different across %d item)",
                             "(different across %d items)", count) % count,
                    True)
        else:
            if tag == "~length":
                msg = format_time(self.get(tag, 0))
            else:
                # ensure values are strings, e.g. 'ISRC' tag can be a dict
                msg = MULTI_VALUED_JOINER.join([str(x) for x in self[tag]])

            if count > 0 and missing > 0:
                return (
                    msg + " " +
                    (ngettext("(missing from %d item)",
                              "(missing from %d items)", missing) % missing),
                    True)
            else:
                return (msg, False)