本文整理汇总了Python中tests.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
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):
示例2: test_gtp_packed
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)
示例3: Tto_int_be
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(), "")
示例4: mkstemp
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)
示例5: test_almost_my_file
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):
示例6: test_invalid_not_first
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)
示例7: Tis_valid_apev2_key
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
示例8: setUp
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)
示例9: MP3
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)
示例10: int
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)
示例11: TExpression
# $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)
示例12: TaskController
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)
示例13: test_save_grown_split_setup_packet_reference
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)
示例14: mkstemp
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 = []
示例15: test_save_all
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)