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


Python system.file_exists函数代码示例

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


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


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