def testVolumeFS(self):
        if self.odps.exist_volume(TEST_FS_VOLUME_NAME):
            self.odps.delete_volume(TEST_FS_VOLUME_NAME)
        self.odps.create_fs_volume(TEST_FS_VOLUME_NAME)

        vol = self.odps.get_volume(TEST_FS_VOLUME_NAME)

        self.odps.create_volume_directory(vol.path + '/' + TEST_DIR_NAME)
        dir_obj = vol[TEST_DIR_NAME]
        self.assertIsInstance(dir_obj, VolumeFSDir)
        self.assertIs(
            dir_obj, self.odps.get_volume_file(vol.path + '/' + TEST_DIR_NAME))
        self.assertEqual(dir_obj.path,
                         '/' + TEST_FS_VOLUME_NAME + '/' + TEST_DIR_NAME)
        self.assertTrue(
            any(f.path in (dir_obj.path, dir_obj.path + '/')
                for f in self.odps.list_volume_files(vol.path)))

        with self.odps.open_volume_writer(dir_obj.path + '/' +
                                          TEST_FILE_NAME) as writer:
            writer.write(FILE_CONTENT)
        self.assertNotIn('non_existing_file', dir_obj)
        self.assertIn(TEST_FILE_NAME, dir_obj)
        self.assertTrue(
            any(f.basename == TEST_FILE_NAME
                for f in self.odps.list_volume_files(dir_obj.path)))
        with self.odps.open_volume_reader(dir_obj.path + '/' +
                                          TEST_FILE_NAME) as reader:
            content = reader.read()
            self.assertEqual(to_str(content), FILE_CONTENT)

        file_obj = dir_obj[TEST_FILE_NAME]
        self.assertIsInstance(file_obj, VolumeFSFile)
        self.assertIs(file_obj, dir_obj[TEST_FILE_NAME])
        with file_obj.open_reader() as reader:
            content = reader.read()
            self.assertEqual(to_str(content), FILE_CONTENT)
        file_obj.replication = 5
        self.assertEqual(file_obj.replication, 5)

        old_dir_name = file_obj.dirname
        self.odps.move_volume_file(file_obj.path,
                                   './/' + TEST_NEW_FILE_NAME,
                                   replication=10)
        self.assertEqual(old_dir_name, file_obj.dirname)
        self.assertEqual(file_obj.basename, TEST_NEW_FILE_NAME)
        self.assertEqual(file_obj.replication, 10)
        self.assertNotIn(TEST_FILE_NAME, dir_obj)
        self.odps.delete_volume_file(file_obj.path)
        self.assertNotIn(TEST_NEW_FILE_NAME, dir_obj)

        dir_obj.delete()
        self.assertNotIn(TEST_DIR_NAME, vol)
    def testVolumeFS(self):
        if self.odps.exist_volume(TEST_FS_VOLUME_NAME):
            self.odps.delete_volume(TEST_FS_VOLUME_NAME)
        self.odps.create_fs_volume(TEST_FS_VOLUME_NAME)

        vol = self.odps.get_volume(TEST_FS_VOLUME_NAME)

        self.odps.create_volume_directory(vol.path + '/' + TEST_DIR_NAME)
        dir_obj = vol[TEST_DIR_NAME]
        self.assertIsInstance(dir_obj, VolumeFSDir)
        self.assertIs(dir_obj, self.odps.get_volume_file(vol.path + '/' + TEST_DIR_NAME))
        self.assertEqual(dir_obj.path, '/' + TEST_FS_VOLUME_NAME + '/' + TEST_DIR_NAME)
        self.assertTrue(any(f.path in (dir_obj.path, dir_obj.path + '/')
                            for f in self.odps.list_volume_files(vol.path)))

        with self.odps.open_volume_writer(dir_obj.path + '/' + TEST_FILE_NAME) as writer:
            writer.write(FILE_CONTENT)
        self.assertNotIn('non_existing_file', dir_obj)
        self.assertIn(TEST_FILE_NAME, dir_obj)
        self.assertTrue(any(f.basename == TEST_FILE_NAME
                            for f in self.odps.list_volume_files(dir_obj.path)))
        with self.odps.open_volume_reader(dir_obj.path + '/' + TEST_FILE_NAME) as reader:
            content = reader.read()
            self.assertEqual(to_str(content), FILE_CONTENT)

        file_obj = dir_obj[TEST_FILE_NAME]
        self.assertIsInstance(file_obj, VolumeFSFile)
        self.assertIs(file_obj, dir_obj[TEST_FILE_NAME])
        with file_obj.open_reader() as reader:
            content = reader.read()
            self.assertEqual(to_str(content), FILE_CONTENT)
        file_obj.replication = 5
        self.assertEqual(file_obj.replication, 5)

        old_dir_name = file_obj.dirname
        self.odps.move_volume_file(file_obj.path, './/' + TEST_NEW_FILE_NAME, replication=10)
        self.assertEqual(old_dir_name, file_obj.dirname)
        self.assertEqual(file_obj.basename, TEST_NEW_FILE_NAME)
        self.assertEqual(file_obj.replication, 10)
        self.assertNotIn(TEST_FILE_NAME, dir_obj)
        self.odps.delete_volume_file(file_obj.path)
        self.assertNotIn(TEST_NEW_FILE_NAME, dir_obj)

        dir_obj.delete()
        self.assertNotIn(TEST_DIR_NAME, vol)
Exemple #3
0
 def test_unicode(self, engine, connection):
     """Verify that unicode strings make it through SQLAlchemy and the backend"""
     unicode_str = "中文"
     one_row = Table('one_row', MetaData(bind=engine))
     returned_str = sqlalchemy.select(
         [expression.bindparam("好", unicode_str)],
         from_obj=one_row,
     ).scalar()
     self.assertEqual(to_str(returned_str), unicode_str)
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function

from odps.tests.core import TestBase, tn
from odps.compat import six
from odps.utils import to_str
from odps.models import PartedVolume, FSVolume, VolumeFSDir, VolumeFSFile

FILE_CONTENT = to_str("""
Four score and seven years ago our fathers brought forth,
upon this continent,
a new nation,
conceived in liberty,
and dedicated to the proposition that "all men are created equal"
""")
FILE_CONTENT2 = to_str("""
Were it to benefit my country I would lay down my life;
What then is risk to me?
""")
TEST_PARTED_VOLUME_NAME = tn('pyodps_test_parted_volume')
TEST_FS_VOLUME_NAME = tn('pyodps_test_fs_volume')

TEST_PARTITION_NAME = 'pyodps_test_partition'
TEST_FILE_NAME = 'test_output_file'
TEST_FILE_NAME2 = 'test_output_file2'
TEST_NEW_FILE_NAME = 'test_new_output_file'
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

from __future__ import print_function

from odps.tests.core import TestBase, tn
from odps.compat import six
from odps.utils import to_str
from odps.models import PartedVolume, FSVolume, VolumeFSDir, VolumeFSFile

FILE_CONTENT = to_str("""
Four score and seven years ago our fathers brought forth,
upon this continent,
a new nation,
conceived in liberty,
and dedicated to the proposition that "all men are created equal"
""")
FILE_CONTENT2 = to_str("""
Were it to benefit my country I would lay down my life;
What then is risk to me?
""")
TEST_PARTED_VOLUME_NAME = tn('pyodps_test_parted_volume')
TEST_FS_VOLUME_NAME = tn('pyodps_test_fs_volume')

TEST_PARTITION_NAME = 'pyodps_test_partition'
TEST_FILE_NAME = 'test_output_file'
TEST_FILE_NAME2 = 'test_output_file2'
TEST_NEW_FILE_NAME = 'test_new_output_file'