当前位置: 首页>>代码示例>>Python>>正文


Python file_element.DataFileElement类代码示例

本文整理汇总了Python中smqtk.representation.data_element.file_element.DataFileElement的典型用法代码示例。如果您正苦于以下问题:Python DataFileElement类的具体用法?Python DataFileElement怎么用?Python DataFileElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataFileElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的smqtk.representation.data_element.file_element.DataFileElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。