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


Python ssh.RemoteTarget類代碼示例

本文整理匯總了Python中luigi.contrib.ssh.RemoteTarget的典型用法代碼示例。如果您正苦於以下問題:Python RemoteTarget類的具體用法?Python RemoteTarget怎麽用?Python RemoteTarget使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: test_exists

 def test_exists(self):
     self.assertTrue(self.target.exists())
     no_file = RemoteTarget(
         "/tmp/_file_that_doesnt_exist_",
         working_ssh_host,
     )
     self.assertFalse(no_file.exists())
開發者ID:strategist922,項目名稱:luigi,代碼行數:7,代碼來源:_test_ssh.py

示例2: test_get

 def test_get(self):
     self.ctx.check_output(["echo -n 'hello' >", self.path])
     t = RemoteTarget(self.path, working_ssh_host)
     t.get(self.local_file)
     f = open(self.local_file, 'r')
     file_content = f.read()
     self.assertEqual(file_content, 'hello')
開發者ID:edhodapp,項目名稱:luigi,代碼行數:7,代碼來源:test_ssh.py

示例3: test_close

 def test_close(self):
     t = RemoteTarget(self.path, working_ssh_host)
     p = t.open('w')
     print >> p, 'test'
     self.assertFalse(self._exists(self.path))
     p.close()
     self.assertTrue(self._exists(self.path))
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:7,代碼來源:_test_ssh.py

示例4: test_put

 def test_put(self):
     f = open(self.local_file, 'w')
     f.write('hello')
     f.close()
     t = RemoteTarget(self.path, working_ssh_host)
     t.put(self.local_file)
     self.assertTrue(self._exists(self.path))
開發者ID:edhodapp,項目名稱:luigi,代碼行數:7,代碼來源:test_ssh.py

示例5: test_write_cleanup_with_error

 def test_write_cleanup_with_error(self):
     t = RemoteTarget(self.path, working_ssh_host)
     try:
         with t.open('w'):
             raise Exception('something broke')
     except:
         pass
     self.assertFalse(t.exists())
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:8,代碼來源:_test_ssh.py

示例6: test_write_cleanup_no_close

    def test_write_cleanup_no_close(self):
        t = RemoteTarget(self.path, working_ssh_host)

        def context():
            f = t.open('w')
            f.write('stuff')
        context()
        gc.collect()  # force garbage collection of f variable
        self.assertFalse(t.exists())
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:9,代碼來源:_test_ssh.py

示例7: test_del

    def test_del(self):
        t = RemoteTarget(self.path, working_ssh_host)
        p = t.open('w')
        print >> p, 'test'
        tp = p.tmp_path
        del p

        self.assertFalse(self._exists(tp))
        self.assertFalse(self._exists(self.path))
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:9,代碼來源:_test_ssh.py

示例8: TestRemoteTarget

class TestRemoteTarget(unittest.TestCase):

    """ These tests assume RemoteContext working
    in order for setUp and tearDown to work
    """

    def setUp(self):
        self.ctx = RemoteContext(working_ssh_host)
        self.filepath = "/tmp/luigi_remote_test.dat"
        self.target = RemoteTarget(
            self.filepath,
            working_ssh_host,
        )
        self.ctx.check_output(["rm", "-rf", self.filepath])
        self.ctx.check_output(["echo -n 'hello' >", self.filepath])

    def tearDown(self):
        self.ctx.check_output(["rm", "-rf", self.filepath])

    def test_exists(self):
        self.assertTrue(self.target.exists())
        no_file = RemoteTarget(
            "/tmp/_file_that_doesnt_exist_",
            working_ssh_host,
        )
        self.assertFalse(no_file.exists())

    def test_remove(self):
        self.target.remove()
        self.assertRaises(
            subprocess.CalledProcessError,
            self.ctx.check_output,
            ["cat", self.filepath]
        )

    def test_open(self):
        f = self.target.open('r')
        file_content = f.read()
        f.close()
        self.assertEqual(file_content, "hello")

        self.assertTrue(self.target.fs.exists(self.filepath))
        self.assertFalse(self.target.fs.isdir(self.filepath))

    def test_context_manager(self):
        with self.target.open('r') as f:
            file_content = f.read()

        self.assertEqual(file_content, "hello")
開發者ID:edhodapp,項目名稱:luigi,代碼行數:49,代碼來源:test_ssh.py

示例9: TestRemoteFilesystem

class TestRemoteFilesystem(unittest.TestCase):
    def setUp(self):
        self.fs = RemoteFileSystem(working_ssh_host)
        self.root = '/tmp/luigi-remote-test'
        self.directory = self.root + '/dir'
        self.filepath = self.directory + '/file'
        self.target = RemoteTarget(
            self.filepath,
            working_ssh_host,
        )

        self.fs.remote_context.check_output(['rm', '-rf', self.root])
        self.addCleanup(self.fs.remote_context.check_output, ['rm', '-rf', self.root])

    def test_mkdir(self):
        self.assertFalse(self.fs.isdir(self.directory))

        self.assertRaises(MissingParentDirectory, self.fs.mkdir, self.directory, parents=False)
        self.fs.mkdir(self.directory)
        self.assertTrue(self.fs.isdir(self.directory))

        # Shouldn't throw
        self.fs.mkdir(self.directory)

        self.assertRaises(FileAlreadyExists, self.fs.mkdir, self.directory, raise_if_exists=True)

    def test_list(self):
        with self.target.open('w'):
            pass

        self.assertEqual([self.target.path], list(self.fs.listdir(self.directory)))
開發者ID:edhodapp,項目名稱:luigi,代碼行數:31,代碼來源:test_ssh.py

示例10: setUp

 def setUp(self):
     self.ctx = RemoteContext(working_ssh_host)
     self.filepath = "/tmp/luigi_remote_test.dat"
     self.target = RemoteTarget(
         self.filepath,
         working_ssh_host,
     )
     self.ctx.check_output(["rm", "-rf", self.filepath])
     self.ctx.check_output(["echo -n 'hello' >", self.filepath])
開發者ID:strategist922,項目名稱:luigi,代碼行數:9,代碼來源:_test_ssh.py

示例11: setUp

    def setUp(self):
        self.fs = RemoteFileSystem(working_ssh_host)
        self.root = '/tmp/luigi-remote-test'
        self.directory = self.root + '/dir'
        self.filepath = self.directory + '/file'
        self.target = RemoteTarget(
            self.filepath,
            working_ssh_host,
        )

        self.fs.remote_context.check_output(['rm', '-rf', self.root])
        self.addCleanup(self.fs.remote_context.check_output, ['rm', '-rf', self.root])
開發者ID:edhodapp,項目名稱:luigi,代碼行數:12,代碼來源:test_ssh.py

示例12: test_gzip

    def test_gzip(self):
        t = RemoteTarget(self.path, working_ssh_host, luigi.format.Gzip)
        p = t.open('w')
        test_data = 'test'
        p.write(test_data)
        self.assertFalse(self._exists(self.path))
        p.close()
        self.assertTrue(self._exists(self.path))

        # Using gzip module as validation
        cmd = 'scp -q %s:%s %s' % (working_ssh_host, self.path, self.local_file)
        assert os.system(cmd) == 0
        f = gzip.open(self.local_file, 'rb')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own gzip remote reader
        f = RemoteTarget(self.path, working_ssh_host, luigi.format.Gzip).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:20,代碼來源:_test_ssh.py

示例13: test_recursion_on_delete

 def test_recursion_on_delete(self):
     target = RemoteTarget("/etc/this/does/not/exist", working_ssh_host)
     with self.assertRaises(RemoteCalledProcessError):
         with target.open('w') as fh:
             fh.write("test")
開發者ID:edhodapp,項目名稱:luigi,代碼行數:5,代碼來源:test_ssh.py

示例14: test_write_with_success

 def test_write_with_success(self):
     t = RemoteTarget(self.path, working_ssh_host)
     with t.open('w') as p:
         p.write("hello")
     self.assertTrue(t.exists())
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:5,代碼來源:_test_ssh.py


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