value = b"\xff\xff\x81" self.assertRaises(ValueError, value.decode, "utf-8") self.assertRaises(ValueError, value.decode, "cp1252") enc = locale.getpreferredencoding() # we need the decoding to fail for this test to work... try: value.decode(enc) except ValueError: pass else: return if not PY2: value = value.decode(enc, "surrogateescape") res, out = self.call("--TALB", value, self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) def test_invalid_escape(self): res, out = self.call("--TALB", '\\xaz', '-e', self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) res, out = self.call("--TALB", '\\', '-e', self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) add(TMid3v2)
self.failIf(value and value != NOTFOUND) def test_flac_reference_delete_readd(self): if not have_flac: return self.audio.delete() self.audio.tags.clear() self.audio["foobar"] = "foobar" * 1000 self.audio.save() self.scan_file() value = os.system("flac --ogg -t %s 2> %s" % (self.filename, devnull)) self.failIf(value and value != NOTFOUND) def test_not_my_ogg(self): fn = os.path.join('tests', 'data', 'empty.ogg') self.failUnlessRaises(IOError, type(self.audio), fn) self.failUnlessRaises(IOError, self.audio.save, fn) self.failUnlessRaises(IOError, self.audio.delete, fn) def test_mime(self): self.failUnless("audio/x-oggflac" in self.audio.mime) add(TOggFLAC) NOTFOUND = os.system("tools/notarealprogram 2> %s" % devnull) have_flac = True if os.system("flac 2> %s > %s" % (devnull, devnull)) == NOTFOUND: have_flac = False print("WARNING: Skipping Ogg FLAC reference tests.")
import os import glob from tests import add from tests.test_tools import _TTools class TMutagenInspect(_TTools): TOOL_NAME = 'mutagen-inspect' def test_basic(self): base = os.path.join('tests', 'data') self.paths = glob.glob(os.path.join(base, 'empty*')) self.paths += glob.glob(os.path.join(base, 'silence-*')) for path in self.paths: res, out = self.call(path) self.failIf(res) self.failUnless(out.strip()) self.failIf("Unknown file type" in out) self.failIf("Errno" in out) add(TMutagenInspect)
SAMPLE = os.path.join(DIR, "data", "click.mpc") OLD = os.path.join(DIR, "data", "oldtag.apev2") BROKEN = os.path.join(DIR, "data", "brokentag.apev2") LYRICS2 = os.path.join(DIR, "data", "apev2-lyricsv2.mp3") INVAL_ITEM_COUNT = os.path.join(DIR, "data", "145-invalid-item-count.apev2") class Tis_valid_apev2_key(TestCase): def test_yes(self): for key in ["foo", "Foo", " f ~~~"]: self.failUnless(is_valid_apev2_key(key)) def test_no(self): for key in ["\x11hi", "ffoo\xFF", u"\u1234", "a", "", "foo" * 100]: self.failIf(is_valid_apev2_key(key)) add(Tis_valid_apev2_key) class TAPEInvalidItemCount(TestCase): # http://code.google.com/p/mutagen/issues/detail?id=145 def test_load(self): x = mutagen.apev2.APEv2(INVAL_ITEM_COUNT) self.failUnlessEqual(len(x.keys()), 17) add(TAPEInvalidItemCount) class TAPEWriter(TestCase): offset = 0
MusepackHeaderError, Musepack, os.path.join("tests", "data", "emptyfile.mp3")) def test_almost_my_file(self): self.failUnlessRaises( MusepackHeaderError, MusepackInfo, StringIO("MP+" + "\x00" * 100)) def test_pprint(self): self.sv7.pprint() self.sv5.pprint() self.sv4.pprint() def test_mime(self): self.failUnless("audio/x-musepack" in self.sv7.mime) add(TMusepack) class TMusepackWithID3(TestCase): SAMPLE = os.path.join("tests", "data", "click.mpc") def setUp(self): fd, self.NEW = mkstemp(suffix='mpc') os.close(fd) shutil.copy(self.SAMPLE, self.NEW) self.failUnlessEqual(file(self.SAMPLE).read(), file(self.NEW).read()) def tearDown(self): os.unlink(self.NEW) def test_ignore_id3(self):
import os from tests import add from tests.test_tools import _TTools class TMutagenPony(_TTools): TOOL_NAME = "mutagen-pony" def test_basic(self): base = os.path.join('tests', 'data') res, out = self.call(base) self.failIf(res) self.failUnless("Report for tests/data" in out) add(TMutagenPony)
def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises(IOError, WavPack, os.path.join("tests", "data", "empty.ogg")) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime) add(TWavPack) class TWavPackNoLength(TestCase): def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "no_length.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x407) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100)
def test_call_with_add(): ast = asg(v("a"), call(v("t"), [add(v("b"), c(2)), add(c(1), v("c"))])) parser = Parser(Tokenizer("a = t(b+2, 1+c)")) assert parser.statement() == ast
self.failUnlessEqual(self.rdict.get("a", "b"), self.fdict.get("a", "b")) self.failUnlessEqual(self.rdict.get("foo"), self.fdict.get("foo")) def test_repr(self): self.failUnlessEqual(repr(self.rdict), repr(self.fdict)) def test_len(self): self.failUnlessEqual(len(self.rdict), len(self.fdict)) def tearDown(self): self.failUnlessEqual(self.fdict, self.rdict) self.failUnlessEqual(self.rdict, self.fdict) add(TDictMixin) class Tcdata(TestCase): ZERO = b"\x00\x00\x00\x00" LEONE = b"\x01\x00\x00\x00" BEONE = b"\x00\x00\x00\x01" NEGONE = b"\xff\xff\xff\xff" def test_int_le(self): self.failUnlessEqual(cdata.int_le(self.ZERO), 0) self.failUnlessEqual(cdata.int_le(self.LEONE), 1) self.failUnlessEqual(cdata.int_le(self.BEONE), 16777216) self.failUnlessEqual(cdata.int_le(self.NEGONE), -1)
try: len(data) except OverflowError: # Py_ssize_t is still only 32 bits on this system. self.failUnlessRaises(OverflowError, Atom.render, "data", data) else: data = Atom.render("data", data) self.failUnlessEqual(len(data), 4 + 4 + 8 + 4) def test_length_0(self): fileobj = StringIO("\x00\x00\x00\x00atom") Atom(fileobj) self.failUnlessEqual(fileobj.tell(), 8) add(TAtom) class TAtoms(TestCase): uses_mmap = False filename = os.path.join("tests", "data", "has-tags.m4a") def setUp(self): self.atoms = Atoms(open(self.filename, "rb")) def test___contains__(self): self.failUnless(self.atoms["moov"]) self.failUnless(self.atoms["moov.udta"]) self.failUnlessRaises(KeyError, self.atoms.__getitem__, "whee") def test_name(self):
# $Id: test_expr.py 1527 2006-05-07 16:41:16Z mu $ from tests import TestCase, add from yasm import Expression import operator class TExpression(TestCase): def test_create(self): e1 = Expression(operator.add, 1, 2) e2 = Expression('+', 1, 2) self.assertEquals(e1.get_intnum(), e1.get_intnum()) def test_extract(self): e1 = Expression('/', 15, 5) self.assertEquals(e1.get_intnum(), 3) self.assertRaises(ValueError, e1.extract_segoff) self.assertRaises(ValueError, e1.extract_wrt) add(TExpression)
# which we need to make a best guess for. # #def test_find_last_invalid_sync(self): # data = StringIO("if you think this is an OggS, you're crazy") # self.failUnlessRaises(OggError, OggPage.find_last, data, 0) def test_find_last_invalid_sync(self): data = StringIO("if you think this is an OggS, you're crazy") page = OggPage.find_last(data, 0) self.failIf(page) def tearDown(self): self.fileobj.close() add(TOggPage) class TOggFileType(TestCase): def scan_file(self): fileobj = open(self.filename, "rb") try: try: while True: page = OggPage(fileobj) except EOFError: pass finally: fileobj.close() def test_pprint_empty(self):
id3 = EasyID3(self.filename) self.failUnlessEqual(self.id3["date"], ["2004"]) self.id3["date"] = "2004" self.id3.save(self.filename) id3 = EasyID3(self.filename) self.failUnlessEqual(self.id3["date"], ["2004"]) def test_write_date_double(self): self.id3["date"] = ["2004", "2005"] self.id3.save(self.filename) id3 = EasyID3(self.filename) self.failUnlessEqual(self.id3["date"], ["2004", "2005"]) self.id3["date"] = ["2004", "2005"] self.id3.save(self.filename) id3 = EasyID3(self.filename) self.failUnlessEqual(self.id3["date"], ["2004", "2005"]) def test_write_invalid(self): self.failUnlessRaises(ValueError, self.id3.__getitem__, "notvalid") self.failUnlessRaises(ValueError, self.id3.__delitem__, "notvalid") self.failUnlessRaises(ValueError, self.id3.__setitem__, "notvalid", "tests") def tearDown(self): os.unlink(self.filename) add(TEasyID3)
self.failUnless(isinstance(value, bytes)) def test_low_unicode(self): value = utf8(u"1234") self.failUnlessEqual(value, b"1234") self.failUnless(isinstance(value, bytes)) def test_high_unicode(self): value = utf8(u"\u1234") self.failUnlessEqual(value, b'\xe1\x88\xb4') self.failUnless(isinstance(value, bytes)) def test_invalid(self): self.failUnlessRaises(TypeError, utf8, 1234) add(Tutf8) class Tcdata(TestCase): ZERO = b"\x00\x00\x00\x00" LEONE = b"\x01\x00\x00\x00" BEONE = b"\x00\x00\x00\x01" NEGONE = b"\xff\xff\xff\xff" def test_int_le(self): self.failUnlessEqual(cdata.int_le(self.ZERO), 0) self.failUnlessEqual(cdata.int_le(self.LEONE), 1) self.failUnlessEqual(cdata.int_le(self.BEONE), 16777216) self.failUnlessEqual(cdata.int_le(self.NEGONE), -1) def test_uint_le(self):
self.failUnlessEqual(self.audio.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises( IOError, WavPack, os.path.join("tests", "data", "empty.ogg")) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime) add(TWavPack) class TWavPackNoLength(TestCase): def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "no_length.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x407) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100)
def test_ixor(self): a = IntNum(-234) b = IntNum(432) a ^= b b ^= a a ^= b self.assertEquals(a, 432) self.assertEquals(b, -234) def test_cmp(self): a = IntNum(-1) b = IntNum(0) c = IntNum(1) self.assert_(a < b < c) self.assert_(a <= b <= c) self.assert_(c >= b >= a) self.assert_(c > b > a) self.assert_(a != b != c) def test_abs(self): a = IntNum(-1) b = IntNum(0) c = IntNum(1) self.assertEquals(abs(a), abs(c)) self.assertEquals(abs(a) - abs(c), abs(b)) add(TIntNum)
self.failUnless(isinstance(value, str)) def test_low_unicode(self): value = utf8(u"1234") self.failUnlessEqual(value, "1234") self.failUnless(isinstance(value, str)) def test_high_unicode(self): value = utf8(u"\u1234") self.failUnlessEqual(value, '\xe1\x88\xb4') self.failUnless(isinstance(value, str)) def test_invalid(self): self.failUnlessRaises(TypeError, utf8, 1234) add(Tutf8) class TDictMixin(TestCase): uses_mmap = False def setUp(self): self.fdict = FDict() self.rdict = {} self.fdict["foo"] = self.rdict["foo"] = "bar" def test_getsetitem(self): self.failUnlessEqual(self.fdict["foo"], "bar") self.failUnlessRaises(KeyError, self.fdict.__getitem__, "bar") def test_has_key_contains(self): self.failUnless("foo" in self.fdict)
except ImportError: pass else: def test_yaml(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) doc = yaml.load(yaml.dump(doc)) doc = yaml.load(yaml.dump(doc)) setattr(Texamples_yaml, "test_" + basename, test_yaml) def test_repr(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) repr(doc) setattr(Texamples_repr, "test_" + basename, test_repr) def test_run(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) bullets = [Bullet.FromDocument(doc)] for i in range(100): for bullet in bullets: bullets.extend(bullet.step()) setattr(Texamples_run, "test_" + basename, test_run) add(Texamples_xml) add(Texamples_yaml) add(Texamples_repr) add(Texamples_run)
def setUp(self): self.ofr = OptimFROG(os.path.join("tests", "data", "empty.ofr")) self.ofs = OptimFROG(os.path.join("tests", "data", "empty.ofs")) def test_channels(self): self.failUnlessEqual(self.ofr.info.channels, 2) self.failUnlessEqual(self.ofs.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.ofr.info.sample_rate, 44100) self.failUnlessEqual(self.ofs.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.ofr.info.length, 3.68, 2) self.failUnlessAlmostEqual(self.ofs.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises( OptimFROGHeaderError, OptimFROG, os.path.join("tests", "data", "empty.ogg")) self.failUnlessRaises( OptimFROGHeaderError, OptimFROG, os.path.join("tests", "data", "click.mpc")) def test_pprint(self): self.failUnless(self.ofr.pprint()) self.failUnless(self.ofs.pprint()) add(TOptimFROG)
fd, self.filename = mkstemp(suffix='.ogg') os.close(fd) shutil.copy(original, self.filename) # append the second file first = open(self.filename, "ab") to_append = os.path.join('tests', 'data', 'multipage-setup.ogg') second = open(to_append, "rb") first.write(second.read()) second.close() first.close() def tearDown(self): super(TMOggSPlit, self).tearDown() os.unlink(self.filename) def test_basic(self): d = os.path.dirname(self.filename) p = os.path.join(d, "%(stream)d.%(ext)s") res, out = self.call("--pattern", p, self.filename) self.failIf(res) self.failIf(out) for stream in [1002429366, 1806412655]: stream_path = os.path.join(d, str(stream) + ".ogg") self.failUnless(os.path.exists(stream_path)) os.unlink(stream_path) add(TMOggSPlit)
def test_invalid_not_first(self): page = OggPage(open(self.filename, "rb")) page.first = False self.failUnlessRaises(IOError, OggSpeexInfo, BytesIO(page.write())) def test_vendor(self): self.failUnless( self.audio.tags.vendor.startswith("Encoded with Speex 1.1.12")) self.failUnlessRaises(KeyError, self.audio.tags.__getitem__, "vendor") def test_not_my_ogg(self): fn = os.path.join('tests', 'data', 'empty.oggflac') self.failUnlessRaises(IOError, type(self.audio), fn) self.failUnlessRaises(IOError, self.audio.save, fn) self.failUnlessRaises(IOError, self.audio.delete, fn) def test_multiplexed_in_headers(self): shutil.copy( os.path.join("tests", "data", "multiplexed.spx"), self.filename) audio = self.Kind(self.filename) audio.tags["foo"] = ["bar"] audio.save() audio = self.Kind(self.filename) self.failUnlessEqual(audio.tags["foo"], ["bar"]) def test_mime(self): self.failUnless("audio/x-speex" in self.audio.mime) add(TOggSpeex)
from tests import TestCase, add class TWavPack(TestCase): uses_mmap = False def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "silence-44-s.wv")) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises(IOError, WavPack, os.path.join("tests", "data", "empty.ogg")) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime) add(TWavPack)
original = os.path.join('tests', 'data', 'multipagecomment.ogg') fd, self.filename = mkstemp(suffix='.ogg') os.close(fd) shutil.copy(original, self.filename) # append the second file first = open(self.filename, "ab") to_append = os.path.join('tests', 'data', 'multipage-setup.ogg') second = open(to_append, "rb") first.write(second.read()) second.close() first.close() def tearDown(self): super(TMOggSPlit, self).tearDown() os.unlink(self.filename) def test_basic(self): d = os.path.dirname(self.filename) p = os.path.join(d, "%(stream)d.%(ext)s") res, out = self.call("--pattern", p, self.filename) self.failIf(res) self.failIf(out) for stream in [1002429366, 1806412655]: stream_path = os.path.join(d, str(stream) + ".ogg") self.failUnless(os.path.exists(stream_path)) os.unlink(stream_path) add(TMOggSPlit)
def test_save_grown_split_setup_packet_reference(self): if ogg is None: return fn = os.path.join("tests", "data", "multipage-setup.ogg") shutil.copy(fn, self.filename) audio = OggVorbis(self.filename) audio["foobar"] = ["quux" * 50000] tags = audio.tags self.failUnless(tags) audio.save() self.audio = OggVorbis(self.filename) self.failUnlessEqual(self.audio.tags, tags) vfc = ogg.vorbis.VorbisFile(self.filename).comment() for key in self.audio: self.failUnlessEqual(vfc[key], self.audio[key]) self.ogg_reference(self.filename) def test_mime(self): self.failUnless("audio/vorbis" in self.audio.mime) # Don't think ogg.vorbis has been ported to Python3. # See http://ekyo.nerim.net/software/pyogg/index.html for news/porting. # I would do it, but I have no experience with C->Python wrappers. Maybe later. try: import ogg.vorbis except ImportError: print("WARNING: Skipping Ogg Vorbis reference tests.") ogg = None add(TOggVorbis)
self.failUnlessEqual(qltk.get_top_parent(w), w) self.failUnlessEqual(qltk.get_top_parent(l), None) w.destroy(); l.destroy() def test_gtp_packed(self): w = gtk.Window(); l = gtk.Label(); w.add(l) self.failUnlessEqual(qltk.get_top_parent(w), w) self.failUnlessEqual(qltk.get_top_parent(l), w) w.destroy(); l.destroy() def test_is_accel(self): e = gtk.gdk.Event(gtk.gdk.KEY_RELEASE) self.failIf(qltk.is_accel(e, "a")) e = gtk.gdk.Event(gtk.gdk.KEY_PRESS) e.keyval = 65293 e.state = gtk.gdk.CONTROL_MASK self.failUnless(qltk.is_accel(e, "<ctrl>Return")) def test_popup_menu_under_widget(self): w = gtk.Window() l = gtk.Label() w.add(l) m = gtk.Menu() l.realize() qltk.popup_menu_under_widget(m, l, 1, 0) w.destroy() m.destroy() add(TQltk)
def test_numeric_pairs(self): for tag in ["tracknumber", "discnumber"]: self.mp4[tag] = "3" self.failUnlessEqual(self.mp4[tag], ["3"]) self.mp4.save() mp4 = EasyMP4(self.filename) self.failUnlessEqual(mp4[tag], ["3"]) del (mp4[tag]) self.failIf(tag in mp4) self.failUnlessRaises(KeyError, mp4.__delitem__, tag) self.mp4[tag] = "3/10" self.failUnlessEqual(self.mp4[tag], ["3/10"]) self.mp4.save() mp4 = EasyMP4(self.filename) self.failUnlessEqual(mp4[tag], ["3/10"]) del (mp4[tag]) self.failIf(tag in mp4) self.failUnlessRaises(KeyError, mp4.__delitem__, tag) self.failUnlessRaises(ValueError, self.mp4.__setitem__, tag, "hello") def tearDown(self): os.unlink(self.filename) add(TEasyMP4)
from mutagen.flac import to_int_be, Padding, VCFLACDict, MetadataBlock, error from mutagen.flac import StreamInfo, SeekTable, CueSheet, FLAC, delete, Picture from tests.test__vorbis import TVCommentDict, VComment try: from os.path import devnull except ImportError: devnull = "/dev/null" class Tto_int_be(TestCase): uses_mmap = False def test_empty(self): self.failUnlessEqual(to_int_be(""), 0) def test_0(self): self.failUnlessEqual(to_int_be("\x00"), 0) def test_1(self): self.failUnlessEqual(to_int_be("\x01"), 1) def test_256(self): self.failUnlessEqual(to_int_be("\x01\x00"), 256) def test_long(self): self.failUnlessEqual(to_int_be("\x01\x00\x00\x00\x00"), 2**32) add(Tto_int_be) class TVCFLACDict(TVCommentDict): uses_mmap = False Kind = VCFLACDict def test_roundtrip_vc(self): self.failUnlessEqual(self.c, VComment(self.c.write() + "\x01")) add(TVCFLACDict) class TMetadataBlock(TestCase): uses_mmap = False def test_empty(self): self.failUnlessEqual(MetadataBlock("").write(), "")
class Tis_valid_apev2_key(TestCase): def test_yes(self): for key in ["foo", "Foo", " f ~~~"]: self.failUnless(is_valid_apev2_key(key)) def test_no(self): for key in ["\x11hi", "ffoo\xFF", u"\u1234", "a", "", "foo" * 100]: self.failIf(is_valid_apev2_key(key)) if PY3: def test_py3(self): self.assertRaises(TypeError, is_valid_apev2_key, b"abc") add(Tis_valid_apev2_key) class TAPEInvalidItemCount(TestCase): # http://code.google.com/p/mutagen/issues/detail?id=145 def test_load(self): x = mutagen.apev2.APEv2(INVAL_ITEM_COUNT) self.failUnlessEqual(len(x.keys()), 17) add(TAPEInvalidItemCount) class TAPEWriter(TestCase): offset = 0
mp3 = MP3(os.path.join("tests", "data", "silence-44-s.mp3")) self.failUnless(mp3.tags) self.failUnlessRaises(Exception, mp3.add_tags) def test_save_no_tags(self): self.mp3.tags = None self.failUnlessRaises(ValueError, self.mp3.save) def test_mime(self): self.failUnless("audio/mp3" in self.mp3.mime) def tearDown(self): os.unlink(self.filename) add(TMP3) class TMPEGInfo(TestCase): uses_mmap = False def test_not_real_file(self): filename = os.path.join("tests", "data", "silence-44-s-v1.mp3") fileobj = StringIO(file(filename, "rb").read(20)) MPEGInfo(fileobj) def test_empty(self): fileobj = StringIO("") self.failUnlessRaises(IOError, MPEGInfo, fileobj)
fileobj = cBytesIO(page.write()) self.failUnlessRaises(IOError, OggTheoraInfo, fileobj) def test_vendor(self): self.failUnless( self.audio.tags.vendor.startswith("Xiph.Org libTheora")) self.failUnlessRaises(KeyError, self.audio.tags.__getitem__, "vendor") def test_not_my_ogg(self): fn = os.path.join('tests', 'data', 'empty.ogg') self.failUnlessRaises(IOError, type(self.audio), fn) self.failUnlessRaises(IOError, self.audio.save, fn) self.failUnlessRaises(IOError, self.audio.delete, fn) def test_length(self): self.failUnlessAlmostEqual(5.5, self.audio.info.length, 1) self.failUnlessAlmostEqual(0.75, self.audio2.info.length, 2) def test_bitrate(self): self.failUnlessEqual(16777215, self.audio3.info.bitrate) def test_module_delete(self): delete(self.filename) self.scan_file() self.failIf(OggTheora(self.filename).tags) def test_mime(self): self.failUnless("video/x-theora" in self.audio.mime) add(TOggTheora)
class FakeMeta(Metadata): def __init__(self): pass def test_virtual_constructor(self): self.failUnlessRaises(NotImplementedError, Metadata, "filename") def test_virtual_save(self): self.failUnlessRaises(NotImplementedError, self.FakeMeta().save) self.failUnlessRaises( NotImplementedError, self.FakeMeta().save, "filename") def test_virtual_delete(self): self.failUnlessRaises(NotImplementedError, self.FakeMeta().delete) self.failUnlessRaises( NotImplementedError, self.FakeMeta().delete, "filename") add(TMetadata) class TFileType(TestCase): uses_mmap = False def setUp(self): self.vorbis = File(os.path.join("tests", "data", "empty.ogg")) def test_delitem_not_there(self): self.failUnlessRaises(KeyError, self.vorbis.__delitem__, "foobar") def test_delitem(self): self.vorbis["foobar"] = "quux" del(self.vorbis["foobar"]) self.failIf("quux" in self.vorbis) add(TFileType)
self.failUnlessEqual(self.audio.info.channels, 1) self.failUnless(self.audio.tags.vendor.startswith("libopus")) def test_module_delete(self): delete(self.filename) self.scan_file() self.failIf(self.Kind(self.filename).tags) def test_mime(self): self.failUnless("audio/ogg" in self.audio.mime) self.failUnless("audio/ogg; codecs=opus" in self.audio.mime) def test_invalid_not_first(self): page = OggPage(open(self.filename, "rb")) page.first = False self.failUnlessRaises(IOError, OggOpusInfo, BytesIO(page.write())) def test_unsupported_version(self): page = OggPage(open(self.filename, "rb")) data = bytearray(page.packets[0]) data[8] = 0x03 page.packets[0] = bytes(data) OggOpusInfo(BytesIO(page.write())) data[8] = 0x10 page.packets[0] = bytes(data) self.failUnlessRaises(IOError, OggOpusInfo, BytesIO(page.write())) add(TOggOpus)
'global') def test_iters(self): tab = self.symtab tab.declare("foo", None, 0) tab.declare("bar", None, 0) tab.declare("baz", None, 0) # while ordering is not known, it must be consistent self.assertEquals(list(tab.keys()), list(tab.iterkeys())) self.assertEquals(list(tab.values()), list(tab.itervalues())) self.assertEquals(list(tab.items()), list(tab.iteritems())) self.assertEquals(list(tab.iteritems()), zip(tab.keys(), tab.values())) add(TSymbolTable) class TSymbolAttr(TestCase): def setUp(self): self.symtab = SymbolTable() self.declsym = self.symtab.declare("foo", None, 0) def test_visibility(self): sym = self.symtab.declare("local1", None, 0) self.assertEquals(sym.visibility, set()) sym = self.symtab.declare("local2", '', 0) self.assertEquals(sym.visibility, set()) sym = self.symtab.declare("local3", 'local', 0) self.assertEquals(sym.visibility, set()) sym = self.symtab.declare("global", 'global', 0)
def test_sample_rate(self): self.failUnlessEqual(self.mac399.info.sample_rate, 44100) self.failUnlessEqual(self.mac396.info.sample_rate, 44100) self.failUnlessEqual(self.mac390.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.mac399.info.length, 3.68, 2) self.failUnlessAlmostEqual(self.mac396.info.length, 3.68, 2) self.failUnlessAlmostEqual(self.mac390.info.length, 15.63, 2) def test_version(self): self.failUnlessEqual(self.mac399.info.version, 3.99) self.failUnlessEqual(self.mac396.info.version, 3.96) self.failUnlessEqual(self.mac390.info.version, 3.90) def test_not_my_file(self): self.failUnlessRaises(MonkeysAudioHeaderError, MonkeysAudio, os.path.join("tests", "data", "empty.ogg")) self.failUnlessRaises(MonkeysAudioHeaderError, MonkeysAudio, os.path.join("tests", "data", "click.mpc")) def test_mime(self): self.failUnless("audio/x-ape" in self.mac399.mime) def test_pprint(self): self.failUnless(self.mac399.pprint()) self.failUnless(self.mac396.pprint()) add(TMonkeysAudio)
self.failUnlessRaises(NotImplementedError, Metadata, "filename") def test_load(self): m = Metadata() self.failUnlessRaises(NotImplementedError, m.load, "filename") def test_virtual_save(self): self.failUnlessRaises(NotImplementedError, self.FakeMeta().save) self.failUnlessRaises( NotImplementedError, self.FakeMeta().save, "filename") def test_virtual_delete(self): self.failUnlessRaises(NotImplementedError, self.FakeMeta().delete) self.failUnlessRaises( NotImplementedError, self.FakeMeta().delete, "filename") add(TMetadata) class TFileType(TestCase): def setUp(self): self.vorbis = File(os.path.join("tests", "data", "empty.ogg")) def test_delitem_not_there(self): self.failUnlessRaises(KeyError, self.vorbis.__delitem__, "foobar") def test_add_tags(self): self.failUnlessRaises(NotImplementedError, FileType().add_tags) def test_delitem(self): self.vorbis["foobar"] = "quux" del(self.vorbis["foobar"])
def test_length_0(self): fileobj = StringIO("\x00\x00\x00\x00atom" + 40 * "\x00") atom = Atom(fileobj) self.failUnlessEqual(fileobj.tell(), 48) self.failUnlessEqual(atom.length, 48) def test_length_0_container(self): data = StringIO(struct.pack(">I4s", 0, "moov") + Atom.render("data", "whee")) atom = Atom(data) self.failUnlessEqual(len(atom.children), 1) self.failUnlessEqual(atom.length, 20) self.failUnlessEqual(atom.children[-1].length, 12) add(TAtom) class TAtoms(TestCase): uses_mmap = False filename = os.path.join("tests", "data", "has-tags.m4a") def setUp(self): self.atoms = Atoms(open(self.filename, "rb")) def test___contains__(self): self.failUnless(self.atoms["moov"]) self.failUnless(self.atoms["moov.udta"]) self.failUnlessRaises(KeyError, self.atoms.__getitem__, "whee") def test_name(self): self.failUnlessEqual(self.atoms.atoms[0].name, "ftyp")
self.failUnlessRaises(IOError, TrueAudio, filename) def test_module_delete(self): delete(os.path.join("tests", "data", "empty.tta")) def test_delete(self): self.audio.delete() self.failIf(self.audio.tags) def test_pprint(self): self.failUnless(self.audio.pprint()) def test_save_reload(self): try: fd, filename = mkstemp(suffix='.tta') os.close(fd) shutil.copy(self.audio.filename, filename) audio = TrueAudio(filename) audio.add_tags() audio.tags.add(TIT1(encoding=0, text="A Title")) audio.save() audio = TrueAudio(filename) self.failUnlessEqual(audio["TIT1"], "A Title") finally: os.unlink(filename) def test_mime(self): self.failUnless("audio/x-tta" in self.audio.mime) add(TTrueAudio)
self.assertEquals( s.write(f, [(u"A", 100)]), b"\xff\xfeA\x00\x00\x00\x00\x00\x00d") # utf-16be f.encoding = 2 self.assertEqual(s.read(f, s.write(f, values)), (values, b"")) self.assertEquals( s.write(f, [(u"A", 100)]), b"\x00A\x00\x00\x00\x00\x00d") # utf-8 f.encoding = 3 self.assertEqual(s.read(f, s.write(f, values)), (values, b"")) self.assertEquals(s.write(f, [(u"A", 100)]), b"A\x00\x00\x00\x00d") add(SpecSanityChecks) class SpecValidateChecks(TestCase): def test_volumeadjustmentspec(self): from mutagen.id3 import VolumeAdjustmentSpec s = VolumeAdjustmentSpec('gain') self.assertRaises(ValueError, s.validate, None, 65) def test_volumepeakspec(self): from mutagen.id3 import VolumePeakSpec s = VolumePeakSpec('peak') self.assertRaises(ValueError, s.validate, None, 2) def test_bytespec(self):
self.__save_tags( {self.SINGLE: "1/2", self.FALLBACK: "3"}, {self.SINGLE: "1", self.MAIN: "2", self.FALLBACK: "3"}) def test_save_all(self): # not clear what to do here... self.__save_tags( {self.SINGLE: "1/2", self.MAIN: "4", self.FALLBACK: "3"}, {self.SINGLE: "1", self.MAIN: "4", self.FALLBACK: "3"}) class TTrackTotal(TTotalTagsBase): MAIN = "tracktotal" FALLBACK = "totaltracks" SINGLE = "tracknumber" add(TTrackTotal) class TDiscTotal(TTotalTagsBase): MAIN = "disctotal" FALLBACK = "totaldiscs" SINGLE = "discnumber" add(TDiscTotal) class TFLACFile(TVCFile): def setUp(self): TVCFile.setUp(self) self.filename = tempfile.mkstemp(".flac")[1] shutil.copy(os.path.join('tests', 'data', 'empty.flac'), self.filename) self.song = FLACFile(self.filename)
fd, filename = mkstemp() try: os.close(fd) self.library.add(self.Frange(30)) self.library.save(filename) library = self.Library() library.load(filename) self.failUnlessEqual( sorted(self.library.items()), sorted(library.items())) finally: os.unlink(filename) def tearDown(self): self.library.destroy() add(TLibrary) class TLibrarian(TestCase): Fake = Fake Frange = staticmethod(Frange) Librarian = Librarian Library = Library def setUp(self): self.librarian = self.Librarian() self.Library.librarian = self.librarian self.lib1 = self.Library("One") self.lib2 = self.Library("Two") self.added_1 = [] self.changed_1 = []
# it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation import sys from tests import TestCase, add from quodlibet import formats class TFormats(TestCase): def test_presence(self): self.failUnless(formats.midi) self.failUnless(formats.mod) self.failUnless(formats.monkeysaudio) self.failUnless(formats.mpc) self.failUnless(formats.mp3) self.failUnless(formats.mp4) self.failUnless(formats.spc) self.failUnless(formats.trueaudio) def test_infos(self): self.failUnless(formats._infos[".mp3"] is formats.mp3.MP3File) def test_migration(self): self.failUnless(formats.mp3 is sys.modules["quodlibet.formats.mp3"]) self.failUnless(formats.mp3 is sys.modules["quodlibet/formats/mp3"]) self.failUnless(formats.mp3 is sys.modules["formats.mp3"]) self.failUnless(formats.xiph is sys.modules["formats.flac"]) self.failUnless(formats.xiph is sys.modules["formats.oggvorbis"]) add(TFormats)
def test_invalid_not_first(self): page = OggPage(open(self.filename, "rb")) page.first = False self.failUnlessRaises(IOError, OggSpeexInfo, cBytesIO(page.write())) def test_vendor(self): self.failUnless( self.audio.tags.vendor.startswith("Encoded with Speex 1.1.12")) self.failUnlessRaises(KeyError, self.audio.tags.__getitem__, "vendor") def test_not_my_ogg(self): fn = os.path.join('tests', 'data', 'empty.oggflac') self.failUnlessRaises(IOError, type(self.audio), fn) self.failUnlessRaises(IOError, self.audio.save, fn) self.failUnlessRaises(IOError, self.audio.delete, fn) def test_multiplexed_in_headers(self): shutil.copy(os.path.join("tests", "data", "multiplexed.spx"), self.filename) audio = self.Kind(self.filename) audio.tags["foo"] = ["bar"] audio.save() audio = self.Kind(self.filename) self.failUnlessEqual(audio.tags["foo"], ["bar"]) def test_mime(self): self.failUnless("audio/x-speex" in self.audio.mime) add(TOggSpeex)
try: import yaml except ImportError: pass else: def test_yaml(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) doc = yaml.load(yaml.dump(doc)) doc = yaml.load(yaml.dump(doc)) setattr(Texamples_yaml, "test_" + basename, test_yaml) def test_repr(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) repr(doc) setattr(Texamples_repr, "test_" + basename, test_repr) def test_run(self, filename=filename): doc = BulletML.FromDocument(open(filename, "rU")) bullets = [Bullet.FromDocument(doc)] for i in range(100): for bullet in bullets: bullets.extend(bullet.step()) setattr(Texamples_run, "test_" + basename, test_run) add(Texamples_xml) add(Texamples_yaml) add(Texamples_repr) add(Texamples_run)
self.c = TaskController() self.f = FakeStatusBar() self.c.parent = self.f def test_reparent(self): def set_parent(p): self.c.parent = p set_parent(None) set_parent(FakeStatusBar()) self.assertRaises(ValueError, set_parent, FakeStatusBar()) def test_multiple_tasks(self): self.assertEquals(self.c.active_tasks, []) self.assertNotEqual(self.c.source, "") t1 = Task("src", "desc", controller = self.c) self.assertEquals(self.c.source, "src") self.assertEquals(self.c.active_tasks, [t1]) t1.update(0.5) self.assertEquals(self.c.frac, 0.5) t2 = Task("src2", "desc2", controller = self.c) self.assertEquals(self.c.source, _("Active tasks")) self.assertEquals(self.c.frac, 0.25) Task("src3", "desc3", controller = self.c, known_length=False) self.assertAlmostEqual(self.c.frac, 0.5/3) t1.finish() t2.finish() self.assertEquals(self.c.desc, "desc3") self.assertEquals(self.c.frac, None) add(TTaskController)
from tests import TestCase, add from quodlibet.qltk.sortdialog import SortDialog class TSortDialog(TestCase): def test(self): SortDialog(None).destroy() add(TSortDialog)
thumb = thumbnails.get_thumbnail(s.filename, (50, 60)) #check for right scaling s.failUnless(thumb) s.failUnlessEqual((thumb.get_width(), thumb.get_height()), (50, 3)) #test the thumbnail filename uri = "file://" + urllib.pathname2url(s.filename) name = hash.md5(uri).hexdigest() + ".png" path = os.path.expanduser("~/.thumbnails") # newer spec new_path = os.path.expanduser("~/.cache/thumbnails") if os.path.exists(new_path): path = new_path path = os.path.join(path, "normal", name) s.failUnless(os.path.isfile(path)) #check for metadata thumb_pb = gtk.gdk.pixbuf_new_from_file(path) meta_mtime = thumb_pb.get_option("tEXt::Thumb::MTime") meta_uri = thumb_pb.get_option("tEXt::Thumb::URI") s.failUnlessEqual(int(meta_mtime), int(mtime(s.filename))) s.failUnlessEqual(meta_uri, uri) #check rights s.failUnlessEqual(os.stat(path).st_mode, 33152) add(TThumb)
def __len__(self): return 1L << 32 data = TooBig("test") try: len(data) except OverflowError: # Py_ssize_t is still only 32 bits on this system. self.failUnlessRaises(OverflowError, Atom.render, "data", data) else: data = Atom.render("data", data) self.failUnlessEqual(len(data), 4 + 4 + 8 + 4) def test_length_0(self): fileobj = StringIO("\x00\x00\x00\x00atom") Atom(fileobj) self.failUnlessEqual(fileobj.tell(), 8) add(TAtom) class TAtoms(TestCase): uses_mmap = False filename = os.path.join("tests", "data", "has-tags.m4a") def setUp(self): self.atoms = Atoms(file(self.filename, "rb")) def test___contains__(self): self.failUnless(self.atoms["moov"]) self.failUnless(self.atoms["moov.udta"]) self.failUnlessRaises(KeyError, self.atoms.__getitem__, "whee") def test_name(self): self.failUnlessEqual(self.atoms.atoms[0].name, "ftyp")
# $Id: test_expr.py,v 1.1.1.1 2012/03/29 17:20:59 uid42307 Exp $ from tests import TestCase, add from yasm import Expression import operator class TExpression(TestCase): def test_create(self): e1 = Expression(operator.add, 1, 2) e2 = Expression('+', 1, 2) self.assertEquals(e1.get_intnum(), e1.get_intnum()) def test_extract(self): e1 = Expression('/', 15, 5) self.assertEquals(e1.get_intnum(), 3) self.assertRaises(ValueError, e1.extract_segoff) self.assertRaises(ValueError, e1.extract_wrt) add(TExpression)
def test_space(self): self.failUnless(istag("ti tle")) def test_ugly(self): self.failUnless(istag("!{}[]-_()*&")) def test_unicode(self): self.failUnless(istag(u"ti tle")) if PY3: def test_py3(self): self.failUnlessRaises(ValueError, istag, b"abc") add(Tistag) class TVComment(TestCase): Kind = VComment def setUp(self): self.c = VComment() self.c.append(("artist", u"piman")) self.c.append(("artist", u"mu")) self.c.append(("title", u"more fakes")) def test_invalid_init(self): self.failUnlessRaises(TypeError, VComment, []) def test_equal(self):
def setUp(self): quodlibet.config.init() self.library = SongLibrary() def test_none(self): Information(self.library, []).destroy() def test_one(self): f = AF({"~filename": "/dev/null"}) Information(self.library, [f]).destroy() def test_two(self): f = AF({"~filename": "/dev/null"}) f2 = AF({"~filename": "/dev/null2"}) Information(self.library, [f, f2]).destroy() def test_album(self): f = AF({"~filename": "/dev/null", "album": "woo"}) f2 = AF({"~filename": "/dev/null2", "album": "woo"}) Information(self.library, [f, f2]).destroy() def test_artist(self): f = AF({"~filename": "/dev/null", "artist": "woo"}) f2 = AF({"~filename": "/dev/null2", "artist": "woo"}) Information(self.library, [f, f2]).destroy() def tearDown(self): self.library.destroy() quodlibet.config.quit() add(TInformation)
def test_empty(self): self.failUnlessEqual(to_int_be(b""), 0) def test_0(self): self.failUnlessEqual(to_int_be(b"\x00"), 0) def test_1(self): self.failUnlessEqual(to_int_be(b"\x01"), 1) def test_256(self): self.failUnlessEqual(to_int_be(b"\x01\x00"), 256) def test_long(self): self.failUnlessEqual(to_int_be(b"\x01\x00\x00\x00\x00"), 2 ** 32) add(Tto_int_be) class TVCFLACDict(TVCommentDict): Kind = VCFLACDict def test_roundtrip_vc(self): self.failUnlessEqual(self.c, VComment(self.c.write() + b"\x01")) add(TVCFLACDict) class TMetadataBlock(TestCase): def test_empty(self): self.failUnlessEqual(MetadataBlock(b"").write(), b"")
def test_invalid_encoding(self): value = b"\xff\xff\x81" self.assertRaises(ValueError, value.decode, "utf-8") self.assertRaises(ValueError, value.decode, "cp1252") enc = locale.getpreferredencoding() # we need the decoding to fail for this test to work... try: value.decode(enc) except ValueError: pass else: return if not PY2: value = value.decode(enc, "surrogateescape") res, out = self.call("--TALB", value, self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) def test_invalid_escape(self): res, out = self.call("--TALB", '\\xaz', '-e', self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) res, out = self.call("--TALB", '\\', '-e', self.filename) self.failIfEqual(res, 0) self.failUnless("TALB" in out) add(TMid3v2)
def test_module_delete(self): delete(os.path.join("tests", "data", "empty.tta")) def test_delete(self): self.audio.delete() self.failIf(self.audio.tags) def test_pprint(self): self.failUnless(self.audio.pprint()) def test_save_reload(self): try: fd, filename = mkstemp(suffix='.tta') os.close(fd) shutil.copy(self.audio.filename, filename) audio = TrueAudio(filename) audio.add_tags() audio.tags.add(TIT1(encoding=0, text="A Title")) audio.save() audio = TrueAudio(filename) self.failUnlessEqual(audio["TIT1"], "A Title") finally: os.unlink(filename) def test_mime(self): self.failUnless("audio/x-tta" in self.audio.mime) add(TTrueAudio)