本文整理汇总了Python中smqtk.representation.data_element.file_element.DataFileElement类的典型用法代码示例。如果您正苦于以下问题:Python DataFileElement类的具体用法?Python DataFileElement怎么用?Python DataFileElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataFileElement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_writeTempOverride_diffDir
def test_writeTempOverride_diffDir(self, mock_open, mock_os_open,
mock_os_close, mock_fcntl, mock_scd):
source_filepath = '/path/to/file.png'
target_dir = '/some/other/dir'
d = DataFileElement(source_filepath)
fp = d.write_temp(temp_dir=target_dir)
ntools.assert_not_equal(fp, source_filepath)
ntools.assert_equal(os.path.dirname(fp), target_dir)
# subsequent call to write temp should not invoke creation of a new file
fp2 = d.write_temp()
ntools.assert_equal(fp2, source_filepath)
# request in same dir should return same path as first request with that
# directory
fp3 = d.write_temp(target_dir)
ntools.assert_equal(fp, fp3)
# request different target dir
target2 = '/even/different/path'
fp4 = d.write_temp(target2)
ntools.assert_equal(os.path.dirname(fp4), target2)
ntools.assert_not_equal(fp, fp4)
ntools.assert_equal(len(d._temp_filepath_stack), 2)
开发者ID:mrG7,项目名称:SMQTK,代码行数:26,代码来源:test_DataFileElement.py
示例2: test_writeTempOverride
def test_writeTempOverride(self, mock_DataElement_wt):
# no manual directory, should return the base filepath
expected_filepath = '/path/to/file.txt'
d = DataFileElement(expected_filepath)
fp = d.write_temp()
self.assertFalse(mock_DataElement_wt.called)
self.assertEqual(expected_filepath, fp)
开发者ID:Kitware,项目名称:SMQTK,代码行数:8,代码来源:test_DataFileElement.py
示例3: test_get_bytes_no_file
def test_get_bytes_no_file(self):
e = DataFileElement("/not/a/valid/path.txt", readonly=True)
# We currently expect, in the case where the filepath doesn't exist, to
# get the same bytes as if the file existed and were empty.
self.assertEqual(e.get_bytes(), six.b(""))
# read-only status should have no effect.
e = DataFileElement("/not/a/valid/path.txt", readonly=True)
self.assertEqual(e.get_bytes(), six.b(""))
开发者ID:Kitware,项目名称:SMQTK,代码行数:8,代码来源:test_DataFileElement.py
示例4: iter_valid_elements
def iter_valid_elements():
for fp in file_paths:
dfe = DataFileElement(fp)
ct = dfe.content_type()
if ct in generator.valid_content_types():
valid_file_paths[fp] = ct
yield dfe
else:
invalid_file_paths[fp] = ct
开发者ID:msarahan,项目名称:SMQTK,代码行数:9,代码来源:compute_many_descriptors.py
示例5: test_writeTempOverride_sameDir
def test_writeTempOverride_sameDir(self, mock_DataElement_wt):
expected_filepath = "/path/to/file.txt"
target_dir = "/path/to"
d = DataFileElement(expected_filepath)
fp = d.write_temp(temp_dir=target_dir)
ntools.assert_false(mock_DataElement_wt.called)
ntools.assert_equal(fp, expected_filepath)
开发者ID:msarahan,项目名称:SMQTK,代码行数:9,代码来源:test_DataFileElement.py
示例6: test_cleanTemp
def test_cleanTemp(self):
# a write temp and clean temp should not affect original file
source_file = os.path.join(TEST_DATA_DIR, 'test_file.dat')
self.assertTrue(os.path.isfile(source_file))
d = DataFileElement(source_file)
d.write_temp()
self.assertEqual(len(d._temp_filepath_stack), 0)
d.clean_temp()
self.assertTrue(os.path.isfile(source_file))
开发者ID:Kitware,项目名称:SMQTK,代码行数:9,代码来源:test_DataFileElement.py
示例7: test_writeTempOverride_sameDir
def test_writeTempOverride_sameDir(self, mock_DataElement_wt):
expected_filepath = '/path/to/file.txt'
target_dir = '/path/to'
d = DataFileElement(expected_filepath)
fp = d.write_temp(temp_dir=target_dir)
self.assertFalse(mock_DataElement_wt.called)
self.assertEqual(fp, expected_filepath)
开发者ID:Kitware,项目名称:SMQTK,代码行数:9,代码来源:test_DataFileElement.py
示例8: test_set_bytes_writable
def test_set_bytes_writable(self, m_sfw):
# Using a relative filepath
test_path = 'foo'
test_bytes = six.b('test string of bytes')
e = DataFileElement(test_path)
e.set_bytes(test_bytes)
# File write function should be called
m_sfw.assert_called_once_with(test_path, test_bytes)
开发者ID:Kitware,项目名称:SMQTK,代码行数:10,代码来源:test_DataFileElement.py
示例9: test_configuration
def test_configuration(self):
fp = os.path.join(TEST_DATA_DIR, "Lenna.png")
default_config = DataFileElement.get_default_config()
ntools.assert_equal(default_config, {"filepath": None})
default_config["filepath"] = fp
inst1 = DataFileElement.from_config(default_config)
ntools.assert_equal(default_config, inst1.get_config())
inst2 = DataFileElement.from_config(inst1.get_config())
ntools.assert_equal(inst1, inst2)
开发者ID:msarahan,项目名称:SMQTK,代码行数:11,代码来源:test_DataFileElement.py
示例10: test_configuration
def test_configuration(self):
fp = os.path.join(TEST_DATA_DIR, "Lenna.png")
default_config = DataFileElement.get_default_config()
self.assertEqual(default_config,
{'filepath': None, 'readonly': False,
'explicit_mimetype': None})
default_config['filepath'] = fp
inst1 = DataFileElement.from_config(default_config)
self.assertEqual(default_config, inst1.get_config())
inst2 = DataFileElement.from_config(inst1.get_config())
self.assertEqual(inst1, inst2)
开发者ID:Kitware,项目名称:SMQTK,代码行数:13,代码来源:test_DataFileElement.py
示例11: is_valid_element
def is_valid_element(fp):
dfe = DataFileElement(fp)
ct = dfe.content_type()
if ct in generator.valid_content_types():
if not check_image or test_image_load(dfe):
return dfe
else:
return None
else:
log.debug("Skipping file (invalid content) type for "
"descriptor generator (fp='%s', ct=%s)",
fp, ct)
return None
开发者ID:dhandeo,项目名称:SMQTK,代码行数:13,代码来源:compute_many_descriptors.py
示例12: test_from_uri
def test_from_uri(self):
# will be absolute path
test_file_path = os.path.join(TEST_DATA_DIR, "test_file.dat")
print("Test file path:", test_file_path)
e = DataFileElement.from_uri(test_file_path)
self.assertIsInstance(e, DataFileElement)
self.assertEqual(e._filepath, test_file_path)
self.assertEqual(e.get_bytes(), six.b(''))
e = DataFileElement.from_uri('file://' + test_file_path)
self.assertIsInstance(e, DataFileElement)
self.assertEqual(e._filepath, test_file_path)
self.assertEqual(e.get_bytes(), six.b(''))
开发者ID:Kitware,项目名称:SMQTK,代码行数:14,代码来源:test_DataFileElement.py
示例13: test_writeTempOverride_diffDir
def test_writeTempOverride_diffDir(self, mock_DataElement_wt):
"""
Test that adding ``temp_dir`` parameter triggers call to parent class
"""
source_filepath = '/path/to/file.png'
target_dir = '/some/other/dir'
d = DataFileElement(source_filepath)
# Should call parent class write_temp since target is not the same dir
# that the source file is in.
mock_DataElement_wt.return_value = 'expected'
v = d.write_temp(temp_dir=target_dir)
self.assertEqual(v, 'expected')
mock_DataElement_wt.assert_called_with(target_dir)
开发者ID:Kitware,项目名称:SMQTK,代码行数:15,代码来源:test_DataFileElement.py
示例14: test_fromConfig
def test_fromConfig(self):
fp = os.path.join(TEST_DATA_DIR, "Lenna.png")
c = {
"filepath": fp
}
df = DataFileElement.from_config(c)
ntools.assert_equal(df._filepath, fp)
开发者ID:mrG7,项目名称:SMQTK,代码行数:7,代码来源:test_DataFileElement.py
示例15: iqr_ingest_file
def iqr_ingest_file():
"""
Ingest the file with the given UID, getting the path from the
uploader.
:return: string of data/descriptor element's UUID
:rtype: str
"""
# TODO: Add status dict with a "GET" method branch for getting that
# status information.
# Start the ingest of a FID when POST
if flask.request.method == "POST":
with self.get_current_iqr_session() as iqrs:
fid = flask.request.form['fid']
self._log.debug("[%s::%s] Getting temporary filepath from "
"uploader module", iqrs.uuid, fid)
upload_filepath = self.mod_upload.get_path_for_id(fid)
self.mod_upload.clear_completed(fid)
self._log.debug("[%s::%s] Moving uploaded file",
iqrs.uuid, fid)
sess_upload = osp.join(self._iqr_work_dirs[iqrs.uuid],
osp.basename(upload_filepath))
os.rename(upload_filepath, sess_upload)
upload_data = DataFileElement(sess_upload)
uuid = upload_data.uuid()
self._iqr_example_data[iqrs.uuid][uuid] = upload_data
# Extend session ingest -- modifying
self._log.debug("[%s::%s] Adding new data to session "
"positives", iqrs.uuid, fid)
# iqrs.add_positive_data(upload_data)
try:
upload_descr = \
self._descriptor_generator.compute_descriptor(
upload_data, self._descr_elem_factory
)
except ValueError, ex:
return "Input Error: %s" % str(ex), 400
self._iqr_example_pos_descr[iqrs.uuid][uuid] = upload_descr
iqrs.adjudicate((upload_descr,))
return str(uuid)
开发者ID:dhandeo,项目名称:SMQTK,代码行数:47,代码来源:iqr_search.py
示例16: test_fromConfig
def test_fromConfig(self):
fp = os.path.join(TEST_DATA_DIR, "Lenna.png")
c = {
"filepath": fp
}
#: :type: DataFileElement
df = DataFileElement.from_config(c)
self.assertEqual(df._filepath, fp)
开发者ID:Kitware,项目名称:SMQTK,代码行数:8,代码来源:test_DataFileElement.py
示例17: iqr_ingest_file
def iqr_ingest_file():
"""
Ingest the file with the given UID, getting the path from the
uploader.
:return: string of data/descriptor element's UUID
:rtype: str
"""
# TODO: Add status dict with a "GET" method branch for getting that
# status information.
fid = flask.request.form['fid']
sid = self.get_current_iqr_session()
self._log.debug("[%s::%s] Getting temporary filepath from "
"uploader module", sid, fid)
upload_filepath = self.mod_upload.get_path_for_id(fid)
self.mod_upload.clear_completed(fid)
self._log.debug("[%s::%s] Moving uploaded file",
sid, fid)
sess_upload = osp.join(self._iqr_work_dirs[sid],
osp.basename(upload_filepath))
os.rename(upload_filepath, sess_upload)
# Record uploaded data as user example data for this session.
upload_data = DataFileElement(sess_upload)
uuid = upload_data.uuid()
self._iqr_example_data[sid][uuid] = upload_data
# Extend session ingest -- modifying
self._log.debug("[%s::%s] Adding new data to session "
"external positives", sid, fid)
data_b64 = base64.b64encode(upload_data.get_bytes())
data_ct = upload_data.content_type()
r = self._iqr_service.post('add_external_pos', sid=sid,
base64=data_b64, content_type=data_ct)
r.raise_for_status()
return str(uuid)
开发者ID:Kitware,项目名称:SMQTK,代码行数:42,代码来源:iqr_search.py
示例18: test_writeTempOverride_diffDir
def test_writeTempOverride_diffDir(self, mock_open, mock_os_open, mock_os_close, mock_fcntl, mock_scd, mock_isfile):
source_filepath = "/path/to/file.png"
target_dir = "/some/other/dir"
d = DataFileElement(source_filepath)
fp = d.write_temp(temp_dir=target_dir)
# Custom side-effect for os.path.isfile for simulated files
simulate = True
def osp_isfile_side_effect(path):
if simulate and path == fp:
return True
else:
return False
mock_isfile.side_effect = osp_isfile_side_effect
ntools.assert_not_equal(fp, source_filepath)
ntools.assert_equal(os.path.dirname(fp), target_dir)
# subsequent call to write temp should not invoke creation of a new file
fp2 = d.write_temp()
ntools.assert_equal(fp2, source_filepath)
# request in same dir should return same path as first request with that
# directory
fp3 = d.write_temp(target_dir)
ntools.assert_equal(fp, fp3)
# request different target dir
target2 = "/even/different/path"
fp4 = d.write_temp(target2)
ntools.assert_equal(os.path.dirname(fp4), target2)
ntools.assert_not_equal(fp, fp4)
ntools.assert_equal(len(d._temp_filepath_stack), 2)
# Restore normal os.path.isfile functionality
simulate = False
开发者ID:msarahan,项目名称:SMQTK,代码行数:39,代码来源:test_DataFileElement.py
示例19: test_writable_readonly_false
def test_writable_readonly_false(self):
e = DataFileElement('foo')
self.assertTrue(e.writable())
e = DataFileElement('foo', False)
self.assertTrue(e.writable())
e = DataFileElement('foo', readonly=False)
self.assertTrue(e.writable())
开发者ID:Kitware,项目名称:SMQTK,代码行数:9,代码来源:test_DataFileElement.py
示例20: iqr_ingest_file
def iqr_ingest_file():
"""
Ingest the file with the given UID, getting the path from the
uploader.
:return: string of data/descriptor element's UUID
:rtype: str
"""
# TODO: Add status dict with a "GET" method branch for getting that
# status information.
# Start the ingest of a FID when POST
if flask.request.method == "POST":
iqr_sess = self.get_current_iqr_session()
fid = flask.request.form['fid']
self.log.debug("[%s::%s] Getting temporary filepath from "
"uploader module", iqr_sess.uuid, fid)
upload_filepath = self.mod_upload.get_path_for_id(fid)
self.mod_upload.clear_completed(fid)
self.log.debug("[%s::%s] Moving uploaded file",
iqr_sess.uuid, fid)
sess_upload = osp.join(iqr_sess.work_dir,
osp.basename(upload_filepath))
os.rename(upload_filepath, sess_upload)
upload_data = DataFileElement(sess_upload)
upload_data.uuid()
# Extend session ingest -- modifying
self.log.debug("[%s::%s] Adding new data to session positives",
iqr_sess.uuid, fid)
iqr_sess.add_positive_data(upload_data)
return str(upload_data.uuid())
开发者ID:msarahan,项目名称:SMQTK,代码行数:36,代码来源:iqr_search.py
注:本文中的smqtk.representation.data_element.file_element.DataFileElement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论