本文整理汇总了Python中tests.mkstemp函数的典型用法代码示例。如果您正苦于以下问题:Python mkstemp函数的具体用法?Python mkstemp怎么用?Python mkstemp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mkstemp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
config.init()
self.main = mkdtemp()
self.dir1 = mkdtemp(dir=self.main)
self.dir2 = mkdtemp(dir=self.main)
h, self.cover1 = mkstemp(".png", dir=self.main)
os.close(h)
pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
pb.savev(self.cover1, "png", [], [])
h, self.cover2 = mkstemp(".png", dir=self.main)
os.close(h)
pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
pb.savev(self.cover2, "png", [], [])
fd, self.file1 = mkstemp(".mp3", dir=self.main)
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file1)
fd, self.file2 = mkstemp(".mp3", dir=self.main)
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file2)
self.manager = CoverManager()
示例2: setUp
def setUp(self):
config.init()
fd, self.filename = mkstemp(".mp3")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.filename)
fd, self.filename2 = mkstemp(".mp3")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'mutagen-bug.mp3'), self.filename2)
示例3: setUp
def setUp(self):
fd, self.f = mkstemp(".wma")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'test.wma'), self.f)
self.song = WMAFile(self.f)
fd, self.f2 = mkstemp(".wma")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.f2)
self.song2 = WMAFile(self.f2)
示例4: setUp
def setUp(self):
config.init()
fd, self.f = mkstemp(".ogg")
os.close(fd)
fd, self.f2 = mkstemp(".mp3")
os.close(fd)
fd, self.f3 = mkstemp(".mp3")
os.write(fd, "garbage")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.ogg'), self.f)
shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.f2)
self.s = MusicFile(self.f)
self.s2 = MusicFile(self.f2)
示例5: test_validate
def test_validate(self):
with open(self.PATH, "rb") as template:
desktop_data = template.read()
# copy to a temp file and strip "_ from translatable entries
fd, name = mkstemp(suffix=".desktop")
os.close(fd)
with open(name, "wb") as temp:
new_lines = []
for l in desktop_data.splitlines():
if l.startswith("_"):
l = l[1:]
new_lines.append(l)
temp.write("\n".join(new_lines))
# pass to desktop-file-validate
try:
output = subprocess.check_output(
["desktop-file-validate", name], stderr=subprocess.STDOUT)
except OSError:
# desktop-file-validate not available
return
except subprocess.CalledProcessError as e:
output = e.output
finally:
os.remove(name)
if output:
raise Exception(output)
示例6: create_plugin
def create_plugin(self, id="", name="", desc="", icon="", funcs=None, mod=False):
fd, fn = mkstemp(suffix=".py", text=True, dir=self.tempdir)
file = os.fdopen(fd, "w")
if mod:
indent = ""
else:
file.write("from quodlibet.plugins.playlist import PlaylistPlugin\n")
file.write("class %s(PlaylistPlugin):\n" % name)
indent = " "
file.write("%spass\n" % indent)
if name:
file.write("%sPLUGIN_ID = %r\n" % (indent, name))
if name:
file.write("%sPLUGIN_NAME = %r\n" % (indent, name))
if desc:
file.write("%sPLUGIN_DESC = %r\n" % (indent, desc))
if icon:
file.write("%sPLUGIN_ICON = %r\n" % (indent, icon))
for f in funcs or []:
if f in ["__init__"]:
file.write(
"%sdef %s(self, *args): super(%s, self).__init__("
'*args); raise Exception("as expected.")\n' % (indent, f, name)
)
else:
file.write("%sdef %s(*args): return args\n" % (indent, f))
file.flush()
file.close()
示例7: test_savedsearch
def test_savedsearch(self):
if 'include_saved' not in self.plugins:
return
plugin = self.plugins['include_saved'].cls()
self.failUnlessRaises(QueryPluginError, plugin.parse_body, None)
try:
fd, filename = mkstemp(text=True)
file = os.fdopen(fd, 'w')
file.write("artist=a\nQuery 1\ngenre=classical\nAnother query")
file.close()
self.failUnlessRaises(QueryPluginError, plugin.parse_body,
'missing query')
self.failUnlessRaises(QueryPluginError, plugin.parse_body,
'artist=a')
self.failUnless(plugin.parse_body(' quEry 1',
query_path_=filename))
query1 = plugin.parse_body('Query 1', query_path_=filename)
query2 = plugin.parse_body('another query', query_path_=filename)
song = AudioFile({'artist': u'a', 'genre': u'dance'})
self.failUnless(plugin.search(song, query1))
self.failIf(plugin.search(song, query2))
finally:
os.remove(filename)
示例8: test_trash_removes_file
def test_trash_removes_file(self):
filename = mkstemp()[1]
with open(filename, "w") as f:
f.write("\n")
self.failUnless(os.path.exists(filename))
trash(filename)
self.failIf(os.path.exists(filename))
示例9: setUp
def setUp(self):
quodlibet.config.init()
h, self.fname = mkstemp()
os.close(h)
with open(self.fname + ".saved", "w") as f:
f.write("%s\n%s\n" % (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
self.sae = StandaloneEditor(self.fname, "test", None, None)
示例10: setUp
def setUp(self):
config.init()
init_fake_app()
fd, self.fn = mkstemp()
os.close(fd)
pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
pb.savev(self.fn, "png", [], [])
示例11: setUp
def setUp(self):
TVCCover.setUp(self)
h, self.filename = mkstemp(".flac")
os.close(h)
shutil.copy(os.path.join(DATA_DIR, 'empty.flac'), self.filename)
self.MutagenType = FLAC
self.QLType = FLACFile
示例12: create_plugin
def create_plugin(self, id='', name='', desc='', icon='',
funcs=None, mod=False):
fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir)
file = os.fdopen(fd, 'w')
if mod:
indent = ''
else:
file.write(
"from quodlibet.plugins.songsmenu import SongsMenuPlugin\n")
file.write("class %s(SongsMenuPlugin):\n" % name)
indent = ' '
file.write("%spass\n" % indent)
if name:
file.write("%sPLUGIN_ID = %r\n" % (indent, name))
if name:
file.write("%sPLUGIN_NAME = %r\n" % (indent, name))
if desc:
file.write("%sPLUGIN_DESC = %r\n" % (indent, desc))
if icon:
file.write("%sPLUGIN_ICON = %r\n" % (indent, icon))
for f in (funcs or []):
if f in ["__init__"]:
file.write("%sdef %s(self, *args): super(%s, self).__init__("
"*args); raise Exception(\"as expected\")\n"
% (indent, f, name))
else:
file.write("%sdef %s(*args): return args\n" % (indent, f))
file.flush()
file.close()
示例13: setUp
def setUp(self):
from gi.repository import GdkPixbuf
h, self.filename = mkstemp()
os.close(h)
pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
pb.savev(self.filename, "png", [], [])
示例14: test_validate
def test_validate(self):
# strip translatable prefix from tags
from xml.etree import ElementTree
tree = ElementTree.parse(self.PATH)
for x in tree.iter():
if x.tag.startswith("_"):
x.tag = x.tag[1:]
fd, name = mkstemp(suffix=".appdata.xml")
os.close(fd)
with open(name, "wb") as temp:
header = open(self.PATH, "rb").read().splitlines()[0]
temp.write(header + "\n")
temp.write(ElementTree.tostring(tree.getroot(), encoding="utf-8"))
# pass to desktop-file-validate
try:
subprocess.check_output(
["appdata-validate", "--nonet", name],
stderr=subprocess.STDOUT)
except OSError:
# appdata-validate not available
return
except subprocess.CalledProcessError as e:
raise Exception(e.output)
finally:
os.remove(name)
示例15: test_load_noexist
def test_load_noexist(self):
fd, filename = mkstemp()
os.close(fd)
os.unlink(filename)
library = self.Library()
library.load(filename)
assert len(library) == 0