示例#1
0
    def test_root_local_override(self):
        chainerio.set_root('file://' + self.tmpdir.name)
        with chainerio.open(self.tmpfile_name, "r") as fp:
            self.assertEqual(fp.read(), self.test_string_str)

        # override with full URI
        with open(__file__, "r") as my_script:
            with chainerio.open('file://' + __file__) as fp:
                self.assertEqual(fp.read(), my_script.read().encode("utf-8"))
示例#2
0
    def test_set_root(self):
        # Set default context globally in this process
        chainerio.set_root('posix')

        # Using the context to open local file
        with chainerio.open(self.tmpfile_path, "r") as fp:
            self.assertEqual(fp.read(), self.test_string_str)

        chainerio.set_root('file://' + self.dir_name)
        with chainerio.open(self.tmpfile_name, "r") as fp:
            self.assertEqual(fp.read(), self.test_string_str)
示例#3
0
    def test_root_fs_override(self):
        from pyarrow import hdfs

        hdfs_tmpfile = "tmpfile_hdfs"
        hdfs_file_string = "this is a test string for hdfs"

        conn = hdfs.connect()
        with conn.open(hdfs_tmpfile, "wb") as f:
            f.write(hdfs_file_string.encode('utf-8'))

        chainerio.set_root("hdfs")
        with chainerio.open(hdfs_tmpfile, "r") as fp:
            self.assertEqual(fp.read(), hdfs_file_string)

        # override with full URI
        with open(__file__, "r") as my_script:
            with chainerio.open("file://" + __file__, "r") as fp:
                self.assertEqual(fp.read(), my_script.read())

        with chainerio.open(hdfs_tmpfile, "r") as fp:
            self.assertEqual(fp.read(), hdfs_file_string)

        conn.delete(hdfs_tmpfile)
        conn.close()