def setUp(self): types = formats.types instances = [] for t in types: instances.append(AudioFile.__new__(t)) self.PICKLE = pickle.dumps(instances, 1)
def test_save_ascii_keys_as_bytes_on_py3(self): i = AudioFile.__new__(list(formats.types)[0]) dict.__setitem__(i, u"foo", u"bar") data = dump_audio_files([i], process=True) items = load_audio_files(data, process=False) assert isinstance(list(items[0].keys())[0], bytes)
def test_sanitized_py3(self): i = AudioFile.__new__(list(formats.types)[0]) # this is something that old py2 versions could pickle dict.__init__( i, { b"bytes": b"bytes", u"unicode": u"unicode", b"~filename": b"somefile", u"~mountpoint": u"somemount", u"int": 42, b"float": 1.25, }) data = pickle_dumps([i], 1) items = load_audio_files(data, process=True) i = items[0] if not PY3: return assert i["bytes"] == "bytes" assert i["unicode"] == "unicode" assert isinstance(i["~filename"], fsnative) assert isinstance(i["~mountpoint"], fsnative) assert i["int"] == 42 assert i["float"] == 1.25
def test_save_ascii_keys_as_bytes_on_py3(self): i = AudioFile.__new__(list(formats.types)[0]) dict.__setitem__(i, u"foo", u"bar") data = dump_audio_files([i], process=True) if PY3: items = load_audio_files(data, process=False) assert isinstance(list(items[0].keys())[0], bytes)
def test_reaload_non_existing(self): for t in format_types: if not t.is_file: continue instance = AudioFile.__new__(t) instance.sanitize(self.filename) try: instance.reload() except AudioFileError: pass
def test_reload_non_existing(self): for t in format_types: if not t.is_file: continue instance = AudioFile.__new__(t) instance.sanitize(self.filename) try: instance.reload() except AudioFileError: pass
def test_dump_items(self): from quodlibet.library.libraries import dump_items, load_items types = formats.types instances = [] for t in types: instances.append(AudioFile.__new__(t)) with temp_filename() as filename: dump_items(filename, instances) self.assertEqual(len(load_items(filename)), len(formats.types))
def test_pickle(self): types = formats.types instances = [] for t in types: instances.append(AudioFile.__new__(t)) with temp_filename() as filename: with open(filename, "wb") as h: pickle.dump(instances, h, 1) with open(filename, "rb") as h: self.assertEqual(len(pickle.load(h)), len(formats.types))
def setUp(self): types = formats.types instances = [] for t in types: i = AudioFile.__new__(t) # we want to pickle/unpickle everything, since historically # these things ended up in the file dict.__init__( i, {b"foo": u"bar", u"quux": b"baz", "a": "b", u"b": 42, "c": 0.25}) instances.append(i) self.instances = instances
def test_tag_text_types(self): for t in format_types: i = AudioFile.__new__(t) i["~filename"] = fsnative(u"foo") for tag in TAGS.values(): name = tag.name # brute force variants = [ name, "~" + name, name + "sort", "~" + name + "sort", name + ":role", "~" + name + ":role", "~" + name + "sort:role", name + "sort:role", ] for name in variants: if name in FILESYSTEM_TAGS: assert isinstance(i(name, fsnative()), fsnative) else: assert isinstance(i(name), text_type)
def test_sanitized_py3(self): i = AudioFile.__new__(list(formats.types)[0]) # this is something that old py2 versions could pickle dict.__init__(i, { b"bytes": b"bytes", u"unicode": u"unicode", b"~filename": b"somefile", u"~mountpoint": u"somemount", u"int": 42, b"float": 1.25, }) data = pickle_dumps([i], 1) items = load_audio_files(data, process=True) i = items[0] if not PY3: return assert i["bytes"] == "bytes" assert i["unicode"] == "unicode" assert isinstance(i["~filename"], fsnative) assert isinstance(i["~mountpoint"], fsnative) assert i["int"] == 42 assert i["float"] == 1.25
def test_format_type(self): for t in format_types: i = AudioFile.__new__(t) assert isinstance(i("~format"), str)
def test_format_type(self): for t in format_types: i = AudioFile.__new__(t) assert isinstance(i("~format"), text_type)