本文整理匯總了Python中tempfile.mktemp方法的典型用法代碼示例。如果您正苦於以下問題:Python tempfile.mktemp方法的具體用法?Python tempfile.mktemp怎麽用?Python tempfile.mktemp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tempfile
的用法示例。
在下文中一共展示了tempfile.mktemp方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: pooled_gold_standard_by_dir
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def pooled_gold_standard_by_dir(self, list_of_directory_bam, dict_id_to_file_path_fasta, file_path_output=None):
"""
Make a gold standard assembly merging bam files of several samples
@attention: bam files must have same name to be merged
@param list_of_directory_bam: list of directories containing bam files
@type list_of_directory_bam: list[str|unicode]
@param dict_id_to_file_path_fasta: path to reference files by key
@type dict_id_to_file_path_fasta: dict[str|unicode, str|unicode]
@return: output file path
@rtype: str | unicode
"""
if file_path_output is None:
file_path_output = tempfile.mktemp(dir=self._tmp_dir)
self._logger.info("Creating pooled gold standard")
self.merge_bam_files_by_list_of_dir(list_of_directory_bam, output_dir=self._temp_merges_bam_directory)
dict_id_to_file_path_bam = self.get_dict_id_to_file_path_bam_from_dir(self._temp_merges_bam_directory)
return self.gold_standard_assembly(dict_id_to_file_path_bam, dict_id_to_file_path_fasta, file_path_output)
示例2: test_recordio
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_recordio():
frec = tempfile.mktemp()
N = 255
writer = mx.recordio.MXRecordIO(frec, 'w')
for i in range(N):
if sys.version_info[0] < 3:
writer.write(str(chr(i)))
else:
writer.write(bytes(str(chr(i)), 'utf-8'))
del writer
reader = mx.recordio.MXRecordIO(frec, 'r')
for i in range(N):
res = reader.read()
if sys.version_info[0] < 3:
assert res == str(chr(i))
else:
assert res == bytes(str(chr(i)), 'utf-8')
示例3: test_indexed_recordio
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_indexed_recordio():
fidx = tempfile.mktemp()
frec = tempfile.mktemp()
N = 255
writer = mx.recordio.MXIndexedRecordIO(fidx, frec, 'w')
for i in range(N):
if sys.version_info[0] < 3:
writer.write_idx(i, str(chr(i)))
else:
writer.write_idx(i, bytes(str(chr(i)), 'utf-8'))
del writer
reader = mx.recordio.MXIndexedRecordIO(fidx, frec, 'r')
keys = reader.keys
assert sorted(keys) == [i for i in range(N)]
random.shuffle(keys)
for i in keys:
res = reader.read_idx(i)
if sys.version_info[0] < 3:
assert res == str(chr(i))
else:
assert res == bytes(str(chr(i)), 'utf-8')
示例4: SHCISCF
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def SHCISCF(mf, norb, nelec, maxM=1000, tol=1.0e-8, *args, **kwargs):
"""Shortcut function to setup CASSCF using the SHCI solver. The SHCI
solver is properly initialized in this function so that the 1-step
algorithm can applied with SHCI-CASSCF.
Examples:
>>> mol = gto.M(atom='C 0 0 0; C 0 0 1')
>>> mf = scf.RHF(mol).run()
>>> mc = SHCISCF(mf, 4, 4)
>>> mc.kernel()
-74.414908818611522
"""
mc = mcscf.CASSCF(mf, norb, nelec, *args, **kwargs)
mc.fcisolver = SHCI(mf.mol, maxM, tol=tol)
# mc.callback = mc.fcisolver.restart_scheduler_() #TODO
if mc.chkfile == mc._scf._chkfile.name:
# Do not delete chkfile after mcscf
mc.chkfile = tempfile.mktemp(dir=settings.SHCISCRATCHDIR)
if not os.path.exists(settings.SHCISCRATCHDIR):
os.makedirs(settings.SHCISCRATCHDIR)
return mc
示例5: DMRGSCF
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def DMRGSCF(mf, norb, nelec, maxM=1000, tol=1.e-8, *args, **kwargs):
'''Shortcut function to setup CASSCF using the DMRG solver. The DMRG
solver is properly initialized in this function so that the 1-step
algorithm can be applied with DMRG-CASSCF.
Examples:
>>> mol = gto.M(atom='C 0 0 0; C 0 0 1')
>>> mf = scf.RHF(mol).run()
>>> mc = DMRGSCF(mf, 4, 4)
>>> mc.kernel()
-74.414908818611522
'''
if getattr(mf, 'with_df', None):
mc = mcscf.DFCASSCF(mf, norb, nelec, *args, **kwargs)
else:
mc = mcscf.CASSCF(mf, norb, nelec, *args, **kwargs)
mc.fcisolver = DMRGCI(mf.mol, maxM, tol=tol)
mc.callback = mc.fcisolver.restart_scheduler_()
if mc.chkfile == mc._scf._chkfile.name:
# Do not delete chkfile after mcscf
mc.chkfile = tempfile.mktemp(dir=settings.BLOCKSCRATCHDIR)
if not os.path.exists(settings.BLOCKSCRATCHDIR):
os.makedirs(settings.BLOCKSCRATCHDIR)
return mc
示例6: test_Node_save
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_Node_save():
test_list = [1,2,3]
generic_node = mdp.Node()
generic_node.dummy_attr = test_list
# test string save
copy_node_pic = generic_node.save(None)
copy_node = cPickle.loads(copy_node_pic)
assert generic_node.dummy_attr == copy_node.dummy_attr,\
'Node save (string) method did not work'
copy_node.dummy_attr[0] = 10
assert generic_node.dummy_attr != copy_node.dummy_attr,\
'Node save (string) method did not work'
# test file save
dummy_file = tempfile.mktemp(prefix='MDP_', suffix=".pic",
dir=py.test.mdp_tempdirname)
generic_node.save(dummy_file, protocol=1)
dummy_file = open(dummy_file, 'rb')
copy_node = cPickle.load(dummy_file)
assert generic_node.dummy_attr == copy_node.dummy_attr,\
'Node save (file) method did not work'
copy_node.dummy_attr[0] = 10
assert generic_node.dummy_attr != copy_node.dummy_attr,\
'Node save (file) method did not work'
示例7: testFlow_save
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def testFlow_save():
dummy_list = [1,2,3]
flow = _get_default_flow()
flow[0].dummy_attr = dummy_list
# test string save
copy_flow_pic = flow.save(None)
copy_flow = cPickle.loads(copy_flow_pic)
assert flow[0].dummy_attr == copy_flow[0].dummy_attr, \
'Flow save (string) method did not work'
copy_flow[0].dummy_attr[0] = 10
assert flow[0].dummy_attr != copy_flow[0].dummy_attr, \
'Flow save (string) method did not work'
# test file save
dummy_file = tempfile.mktemp(prefix='MDP_', suffix=".pic",
dir=py.test.mdp_tempdirname)
flow.save(dummy_file, protocol=1)
dummy_file = open(dummy_file, 'rb')
copy_flow = cPickle.load(dummy_file)
assert flow[0].dummy_attr == copy_flow[0].dummy_attr, \
'Flow save (file) method did not work'
copy_flow[0].dummy_attr[0] = 10
assert flow[0].dummy_attr != copy_flow[0].dummy_attr, \
'Flow save (file) method did not work'
示例8: test_setmtime
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_setmtime(self):
import tempfile
import time
try:
fd, name = tempfile.mkstemp()
os.close(fd)
except AttributeError:
name = tempfile.mktemp()
open(name, 'w').close()
try:
mtime = int(time.time())-100
path = local(name)
assert path.mtime() != mtime
path.setmtime(mtime)
assert path.mtime() == mtime
path.setmtime()
assert path.mtime() != mtime
finally:
os.remove(name)
示例9: test_binary
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_binary(self, enable_randomness=True, times=1, timeout=15):
"""
Test the binary generated
"""
# dump the binary code
pov_binary_filename = tempfile.mktemp(dir='/tmp', prefix='rex-pov-')
self.dump_binary(filename=pov_binary_filename)
os.chmod(pov_binary_filename, 0o755)
pov_tester = CGCPovSimulator()
result = pov_tester.test_binary_pov(
pov_binary_filename,
self.crash.binary,
enable_randomness=enable_randomness,
timeout=timeout,
times=times)
# remove the generated pov
os.remove(pov_binary_filename)
return result
示例10: generate_report
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def generate_report(self, register_setters, leakers):
stat_name = tempfile.mktemp(dir=".", prefix='rex-results-')
l.info("exploitation report being written to '%s'", stat_name)
f = open(stat_name, 'w')
f.write("Binary %s:\n" % os.path.basename(self.crash.project.filename))
f.write("Register setting exploits:\n")
for register_setter in register_setters:
f.write("\t%s\n" % str(register_setter))
f.write("\n")
f.write("Leaker exploits:\n")
for leaker in leakers:
f.write("\t%s\n" % str(leaker))
f.close()
示例11: prepare_run
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def prepare_run(self, *args, **kwargs):
self._args = args
self._kwargs = kwargs
try:
# tempfile.mktemp is deprecated and discouraged, but we use it here
# to create a FIFO since the only other alternative would be to
# create a directory and place the FIFO there, which sucks. Since
# os.mkfifo will raise an exception anyways when the path doesn't
# exist, it shouldn't be a big issue.
self._filepath = tempfile.mktemp(prefix='qutebrowser-userscript-',
dir=standarddir.runtime())
# pylint: disable=no-member,useless-suppression
os.mkfifo(self._filepath, mode=0o600)
# pylint: enable=no-member,useless-suppression
except OSError as e:
self._filepath = None # Make sure it's not used
message.error("Error while creating FIFO: {}".format(e))
return
self._reader = _QtFIFOReader(self._filepath)
self._reader.got_line.connect(self.got_cmd) # type: ignore[arg-type]
示例12: test_custom_build
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_custom_build(clean_dir):
"""Test building with specific parameters."""
dunst_temp_path = shared.rel_to_cwd('templates', 'dunst')
base_output_dir = tempfile.mktemp()
builder.build(templates=[dunst_temp_path], schemes=['atelier-heath-light'],
base_output_dir=base_output_dir)
dunst_temps = builder.TemplateGroup(dunst_temp_path).get_templates()
# out_dirs = [dunst_temps[temp]['output'] for temp in dunst_temps.keys()]
for temp, sub in dunst_temps.items():
out_path = os.path.join(base_output_dir, 'dunst',
sub['output'])
theme_file = 'base16-atelier-heath-light{}'.format(sub['extension'])
out_file = os.path.join(out_path, theme_file)
assert os.path.exists(out_file)
assert len(os.listdir(out_path)) == 1
示例13: test_version_2_0_memmap
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_version_2_0_memmap():
# requires more than 2 byte for header
dt = [(("%d" % i) * 100, float) for i in range(500)]
d = np.ones(1000, dtype=dt)
tf = tempfile.mktemp('', 'mmap', dir=tempdir)
# 1.0 requested but data cannot be saved this way
assert_raises(ValueError, format.open_memmap, tf, mode='w+', dtype=d.dtype,
shape=d.shape, version=(1, 0))
ma = format.open_memmap(tf, mode='w+', dtype=d.dtype,
shape=d.shape, version=(2, 0))
ma[...] = d
del ma
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', UserWarning)
ma = format.open_memmap(tf, mode='w+', dtype=d.dtype,
shape=d.shape, version=None)
assert_(w[0].category is UserWarning)
ma[...] = d
del ma
ma = format.open_memmap(tf, mode='r')
assert_array_equal(ma, d)
示例14: test_exit_crash
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_exit_crash():
# For each Widget subclass, run a simple python script that creates an
# instance and then shuts down. The intent is to check for segmentation
# faults when each script exits.
tmp = tempfile.mktemp(".py")
path = os.path.dirname(pg.__file__)
initArgs = {
'CheckTable': "[]",
'ProgressDialog': '"msg"',
'VerticalLabel': '"msg"',
}
for name in dir(pg):
obj = getattr(pg, name)
if not isinstance(obj, type) or not issubclass(obj, pg.QtGui.QWidget):
continue
print(name)
argstr = initArgs.get(name, "")
open(tmp, 'w').write(code.format(path=path, classname=name, args=argstr))
proc = subprocess.Popen([sys.executable, tmp])
assert proc.wait() == 0
os.remove(tmp)
示例15: test_cli_writecoverage_source
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import mktemp [as 別名]
def test_cli_writecoverage_source(runner, devnull):
from covimerage.coveragepy import CoverageWrapper
fname = tempfile.mktemp()
result = runner.invoke(cli.main, [
'write_coverage', '--data-file', fname, '--source', '.',
'tests/fixtures/conditional_function.profile'])
assert result.output == '\n'.join([
'Writing coverage file %s.' % fname,
''])
assert result.exit_code == 0
cov = CoverageWrapper(data_file=fname)
assert cov.lines[
os.path.abspath('tests/test_plugin/conditional_function.vim')] == [
3, 8, 9, 11, 13, 14, 15, 17, 23]
assert cov.lines[
os.path.abspath('tests/test_plugin/autoload/test_plugin.vim')] == []