• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python system.file_exists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中Naked.toolshed.system.file_exists函数的典型用法代码示例。如果您正苦于以下问题:Python file_exists函数的具体用法?Python file_exists怎么用?Python file_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了file_exists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     self.cwd = os.getcwd()
     self.test_dir = "pull-tests/remotefiles"
     self.test_text_file_dict = {"testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile.txt"}
     self.test_text_file_two_dict = {"testfile": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile"}
     self.test_text_file_three_dict = {"existdir/testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile.txt"}
     self.test_text_file_four_dict = {"nonexistdir/testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile.txt"}
     
     self.test_multi_text_files_dict = {"testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile.txt", "testfile": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile"}
     self.test_multi_text_files_two_dict = {"existdir/testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile.txt", "nonexistdir/testfile": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/testfile"} 
     
     self.test_bad_text_file_dict = {"testfile.txt": "https://raw.githubusercontent.com/bit-store/testfiles/master/doxx/nonexistenttextfile.txt"}
     
     # remove test files and directories if they exist from last test
     if file_exists("pull-tests/remotefiles/testfile.txt"):
         os.remove("pull-tests/remotefiles/testfile.txt")
         self.assertFalse(file_exists("pull-tests/remotefiles/testfile.txt"))
         
     if file_exists("pull-tests/remotefiles/existdir/testfile.txt"):
         os.remove("pull-tests/remotefiles/existdir/testfile.txt")
         self.assertFalse(file_exists("pull-tests/remotefiles/existdir/testfile.txt"))
         
     if dir_exists("pull-tests/nonexistdir"):
         shutil.rmtree("pull-tests/nonexistdir")
         self.assertFalse(dir_exists("pull-tests/nonexistdir"))
开发者ID:tstyle,项目名称:doxx,代码行数:25,代码来源:test_doxx-remotefiles.py


示例2: test_escape_tar_encrypt

    def test_escape_tar_encrypt(self):
        try:
            # change to the sub test directory for tar tests
            os.chdir("testdir11")
            command = "crypto --tar testtar"
            child = self.submit_same_esc_passphrase(command)
            self.assertTrue(file_exists("testtar.tar.crypt"))  # test new encrypted archive exists
            child.close()

            shutil.move('testtar', 'testtar_temp')

            decrypt_command = "decrypto testtar.tar.crypt"
            child = self.submit_same_esc_passphrase(decrypt_command)
            self.assertTrue(dir_exists(make_path("testtar")))  # test decrypted tar archive exists
            self.assertTrue(file_exists(make_path("testtar", "esc_test.txt")))
            self.assertTrue(file_exists(make_path("testtar", "esc_test2.txt")))
            child.close()

            # cleanup
            os.remove(make_path("testtar.tar.crypt"))  # remove encrypted archive
            shutil.rmtree(make_path("testtar"))        # remove the decrypted, unpacked directory
            shutil.move('testtar_temp', 'testtar')  # move the original tar testing dir back to original path
        except Exception as e:
            # return to top level testing directory
            os.chdir(self.cwd)
            raise e
        finally:
            # return to top level testing directory
            os.chdir(self.cwd)
开发者ID:CamTosh,项目名称:crypto,代码行数:29,代码来源:test_escaping-passphrase.py


示例3: test_crypto_untar_subdirs_archive_cwd

    def test_crypto_untar_subdirs_archive_cwd(self):
        shutil.copyfile(self.subdirs_encrypted_archive_sourcepath, self.subdirs_encrypted_archive_destpath)
        # execute with testdir as the working directory
        try:
            os.chdir(self.testdir)
            command = "decrypto subdirs.tar.crypt"
            child = self.submit_same_passphrase(command)
            # directory write occurs in the proper spot
            self.assertTrue(dir_exists('subdirs'))
            # unpacked decrypted directory contains unpacked subdirectories
            self.assertTrue(dir_exists(os.path.join('subdirs', 'dir1')))
            self.assertTrue(dir_exists(os.path.join('subdirs', 'dir2')))
            # unpacked decrypted directory contains the correct path for unpacked file in subdirectory
            self.assertTrue(file_exists(os.path.join('subdirs', 'dir1', 'test.txt')))
            # the tar archive is deleted, encrypted file is not
            self.assertFalse(file_exists('subdirs.tar'))
            self.assertTrue(file_exists('subdirs.tar.crypt'))
            child.close()

            # cleanup
            shutil.rmtree('subdirs')
            os.remove('subdirs.tar.crypt')
            os.chdir(self.cwd)
        except Exception as e:
            os.chdir(self.cwd)
            raise e
开发者ID:CamTosh,项目名称:crypto,代码行数:26,代码来源:test_decrypt-untar.py


示例4: test_http_get_binary_file_absent

 def test_http_get_binary_file_absent(self):
     """Test HTTP GET request and write to binary file when it does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'test.tar.gz')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("https://github.com/chrissimpkins/six-four/tarball/master")
     http.get_bin_write_file(filepath)
     self.assertTrue(file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:8,代码来源:test_NETWORK_c.py


示例5: test_multifile_goodbad_filepath

    def test_multifile_goodbad_filepath(self):
        command = "crypto testdir1/test1.txt testdir1/bogusfile.txt"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir1", "test1.txt.crypt")))
        self.assertFalse(file_exists(make_path("testdir1", "bogusfile.txt.crypt"))) #should not be present when original does not exist
        child.close()

        # cleanup
        os.remove(make_path("testdir1", "test1.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:9,代码来源:test_multi-file.py


示例6: test_http_post_binary_file_absent

 def test_http_post_binary_file_absent(self):
     """Test HTTP POST request binary file write when the file does not exist"""
     filepath = os.path.join('testfiles', 'testdir', 'post.gz')
     if file_exists(filepath):
         os.remove(filepath)
     http = HTTP("http://httpbin.org/gzip")
     http_data_write = http.post_bin_write_file(filepath)
     self.assertEqual(True, http_data_write) #test boolean for confirmation of data write
     self.assertEqual(True, file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_NETWORK_c.py


示例7: test_multifile_encrypt_txt

    def test_multifile_encrypt_txt(self):
        command = "crypto testdir1/test1.txt testdir2/test1.txt"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir1", "test1.txt.crypt"))) #test that new encrypted file exists
        self.assertTrue(file_exists(make_path("testdir2", "test1.txt.crypt")))
        child.close()

        # cleanup
        os.remove(make_path("testdir1","test1.txt.crypt"))
        os.remove(make_path("testdir2","test1.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_multi-file.py


示例8: test_multifile_encrypt_image

    def test_multifile_encrypt_image(self):
        command = "crypto testdir1/star.png testdir1/tiger.jpg"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir1", "star.png.crypt")))
        self.assertTrue(file_exists(make_path("testdir1", "tiger.jpg.crypt")))
        child.close()

        # cleanup
        os.remove(make_path("testdir1", "star.png.crypt"))
        os.remove(make_path("testdir1", "tiger.jpg.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_multi-file.py


示例9: test_asciifile_encrypt_multiple_files

    def test_asciifile_encrypt_multiple_files(self):
        command = "crypto --armor testdir1/.testfile testdir1/test1.txt"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir1", ".testfile.crypt")))
        self.assertTrue(file_exists(make_path("testdir1", "test1.txt.crypt")))
        child.close()

        # cleanup
        os.remove(make_path("testdir1", ".testfile.crypt"))
        os.remove(make_path("testdir1", "test1.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_ascii-armored.py


示例10: test_multifile_encrypt_withdotfile

    def test_multifile_encrypt_withdotfile(self):
        command = "crypto testdir1/test1.txt testdir1/.testfile"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir1", "test1.txt.crypt")))
        self.assertTrue(file_exists(make_path("testdir1", ".testfile.crypt"))) #should encrypt an explicitly included dotfile
        child.close()

        # cleanup
        os.remove(make_path("testdir1", "test1.txt.crypt"))
        os.remove(make_path("testdir1", ".testfile.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_multi-file.py


示例11: test_unicode_directory_encrypt

    def test_unicode_directory_encrypt(self):
        command = "crypto testdir7"
        child = self.submit_same_uni_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir7", "uni_test.txt.crypt"))) #test that new encrypted file exists
        self.assertTrue(file_exists(make_path("testdir7", "uni_test2.txt.crypt"))) #test that new encrypted file exists
        child.close()

        # cleanup
        os.remove(make_path("testdir7","uni_test.txt.crypt"))
        os.remove(make_path("testdir7","uni_test2.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_unicode-passphrase.py


示例12: test_http_get_binary_file_exists_request_overwrite

 def test_http_get_binary_file_exists_request_overwrite(self):
     """Test HTTP GET request and write binary file executes the write when the file exists and overwrite requested"""
     filepath = os.path.join('testfiles', 'testdir', 'test.tar.gz')
     fw = FileWriter(filepath)
     fw.write("test")
     if not file_exists(filepath):
         raise RuntimeError("Missing test file for the unit test")
     http = HTTP("https://github.com/chrissimpkins/six-four/tarball/master")
     http.get_bin_write_file(filepath, overwrite_existing=True)
     self.assertTrue(file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_NETWORK_c.py


示例13: test_http_post_binary_file_present_request_overwrite

 def test_http_post_binary_file_present_request_overwrite(self):
     """Test HTTP POST request binary file write when file does exist and request for overwrite"""
     filepath = os.path.join('testfiles', 'testdir', 'post.gz')
     if not file_exists(filepath):
         fw = FileWriter(filepath)
         fw.write('test')
     http = HTTP('http://httpbin.org/gzip')
     response = http.post_bin_write_file(filepath, overwrite_existing=True)
     self.assertEqual(True, response)
     self.assertEqual(True, file_exists(filepath))
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_NETWORK_c.py


示例14: test_singledir_file_encrypt

    def test_singledir_file_encrypt(self):
        command = "crypto testdir2"
        child = self.submit_same_passphrase(command)
        child.close()
        self.assertTrue(file_exists(make_path("testdir2", "test1.txt.crypt")))
        self.assertTrue(file_exists(make_path("testdir2", "test2.txt.crypt")))
        self.assertFalse(file_exists(make_path("testdir2", "testcrypt.txt.crypt.crypt")))

        os.remove(make_path("testdir2","test1.txt.crypt"))
        os.remove(make_path("testdir2","test2.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:10,代码来源:test_single-directory.py


示例15: test_decrypt_singlegpgfile_overwrite_shortflag

 def test_decrypt_singlegpgfile_overwrite_shortflag(self):
     command = "decrypto -o testdir6/test2.txt.gpg"
     child = pexpect.spawn(command)
     child.expect("Please enter your passphrase: ")
     child.sendline("test")
     child.expect("Please enter your passphrase again: ")
     child.sendline("test")
     child.expect("'testdir6/test2.txt.gpg' decrypted to 'testdir6/test2.txt'")
     child.close()
     self.assertTrue(file_exists(make_path("testdir6", "test2.txt"))) # confirm decrypted file present
     self.assertFalse(file_exists(make_path("testdir6", "test2.txt.tmp"))) # confirm tmp file erased
开发者ID:CamTosh,项目名称:crypto,代码行数:11,代码来源:test_decrypt-single-file.py


示例16: test_multifile_encrypt_withencryptedfile

    def test_multifile_encrypt_withencryptedfile(self):
        command = "crypto testdir2/test1.txt testdir2/test2.txt testdir2/testcrypt.txt.crypt"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir2", "test1.txt.crypt")))
        self.assertTrue(file_exists(make_path("testdir2", "test2.txt.crypt")))
        self.assertFalse(file_exists(make_path("testdir2", "testcrypt.txt.crypt.crypt"))) # assert that did not encrypt previously encrypted file
        child.close()

        # cleanup
        os.remove(make_path("testdir2", "test1.txt.crypt"))
        os.remove(make_path("testdir2", "test2.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:11,代码来源:test_multi-file.py


示例17: test_doxx_pull_zip_archive

 def test_doxx_pull_zip_archive(self):
     try:
         os.chdir(self.zip_pull_dir)
         run_pull('https://github.com/bit-store/testfiles/raw/master/doxx/pull-tests/packed.zip')
         self.assertTrue(file_exists('key.yaml'))
         self.assertTrue(file_exists('test.doxt'))
         self.assertTrue(file_exists('test2.doxt'))
         os.chdir(self.cwd)
     except Exception as e:
         os.chdir(self.cwd)
         raise e
开发者ID:tstyle,项目名称:doxx,代码行数:11,代码来源:test_doxx-pull.py


示例18: test_multidir_bad_single_dir_path

    def test_multidir_bad_single_dir_path(self):
        command = "crypto bogusdir1 testdir2"
        child = self.submit_same_passphrase(command)

        self.assertTrue(file_exists(make_path("testdir2", "test1.txt.crypt")))
        self.assertTrue(file_exists(make_path("testdir2", "test2.txt.crypt")))

        self.assertFalse(file_exists(make_path("testdir2", "testcrypt.txt.crypt.crypt")))

        # cleanup
        os.remove(make_path("testdir2","test1.txt.crypt"))
        os.remove(make_path("testdir2","test2.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:12,代码来源:test_multi-directory.py


示例19: test_decrypt_multifile_same_directory

    def test_decrypt_multifile_same_directory(self):
        command = "decrypto testdir5/test1.txt.crypt testdir5/test2.txt.gpg testdir5/test3.txt.asc"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir5", "test1.txt")))
        self.assertTrue(file_exists(make_path("testdir5", "test2.txt")))
        self.assertTrue(file_exists(make_path("testdir5", "test3.txt")))

        child.close()

        #cleanup
        os.remove(make_path("testdir5", "test1.txt"))
        os.remove(make_path("testdir5", "test2.txt"))
        os.remove(make_path("testdir5", "test3.txt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:13,代码来源:test_decrypt-multi-file.py


示例20: test_asciifile_single_directory

    def test_asciifile_single_directory(self):
        command = "crypto --armor testdir2"
        child = self.submit_same_passphrase(command)
        self.assertTrue(file_exists(make_path("testdir2", "test1.txt.crypt")))
        self.assertTrue(file_exists(make_path("testdir2", "test2.txt.crypt")))
        self.assertFalse(
            file_exists(make_path("testdir2", "testcrypt.txt.crypt.crypt"))
        )  # test that did not encrypt previously encrypted file
        child.close()

        # cleanup
        os.remove(make_path("testdir2", "test1.txt.crypt"))
        os.remove(make_path("testdir2", "test2.txt.crypt"))
开发者ID:CamTosh,项目名称:crypto,代码行数:13,代码来源:test_ascii-armored.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python system.make_path函数代码示例发布时间:2022-05-24
下一篇:
Python network.HTTP类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap