當前位置: 首頁>>代碼示例>>Python>>正文


Python DataFileElement.write_temp方法代碼示例

本文整理匯總了Python中smqtk.representation.data_element.file_element.DataFileElement.write_temp方法的典型用法代碼示例。如果您正苦於以下問題:Python DataFileElement.write_temp方法的具體用法?Python DataFileElement.write_temp怎麽用?Python DataFileElement.write_temp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在smqtk.representation.data_element.file_element.DataFileElement的用法示例。


在下文中一共展示了DataFileElement.write_temp方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_writeTempOverride_diffDir

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:28,代碼來源:test_DataFileElement.py

示例2: test_cleanTemp

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
 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,代碼行數:11,代碼來源:test_DataFileElement.py

示例3: test_writeTempOverride

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:10,代碼來源:test_DataFileElement.py

示例4: test_writeTempOverride_sameDir

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:11,代碼來源:test_DataFileElement.py

示例5: test_writeTempOverride_sameDir

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:11,代碼來源:test_DataFileElement.py

示例6: test_writeTempOverride_diffDir

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:41,代碼來源:test_DataFileElement.py

示例7: test_writeTempOverride_diffDir

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import write_temp [as 別名]
    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,代碼行數:17,代碼來源:test_DataFileElement.py


注:本文中的smqtk.representation.data_element.file_element.DataFileElement.write_temp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。