示例#1
0
 def test_list_s3(self, mock_list):
     mock_list.return_value = [
         S3Path('s3://a/b/c'),
         S3Path('s3://a/file1'),
         S3Path('s3://a/file2')
     ]
     self.parse_args('stor list s3://a')
     self.assertEquals(sys.stdout.getvalue(),
                       's3://a/b/c\ns3://a/file1\ns3://a/file2\n')
     mock_list.assert_called_once_with(S3Path('s3://a'))
示例#2
0
 def test_listdir_s3(self, mock_listdir):
     mock_listdir.return_value = [
         S3Path('s3://bucket/file1'),
         S3Path('s3://bucket/file2'),
         S3Path('s3://bucket/dir/')
     ]
     self.parse_args('stor ls s3://bucket')
     self.assertEquals(sys.stdout.getvalue(),
                       's3://bucket/file1\n'
                       's3://bucket/file2\n'
                       's3://bucket/dir/\n')
     mock_listdir.assert_called_once_with(S3Path('s3://bucket'))
    def test_properties(self):
        # Create sample path object.
        f = S3Path('s3://bucket/prefix/whatever.csv')

        self.assertEqual(f.parent, S3Path('s3://bucket/prefix'))

        # .name
        self.assertEqual(f.name, 'whatever.csv')
        self.assertEqual(f.parent.name, 'prefix')
        self.assertEqual(f.parent.parent.name, 'bucket')

        # .ext
        self.assertEqual(f.ext, '.csv')
        self.assertEqual(f.parent.ext, '')
示例#4
0
文件: test_cli.py 项目: jdavisp3/stor
    def test_list_options(self, mock_list):
        mock_list.side_effect = [[
            S3Path('s3://some-bucket/dir/a'),
            S3Path('s3://some-bucket/dir/b'),
            S3Path('s3://some-bucket/dir/c/d')
        ], [S3Path('s3://some-bucket/a'),
            S3Path('s3://some-bucket/b')]]

        self.parse_args('stor list s3://some-bucket -s dir')
        self.assertEquals(
            sys.stdout.getvalue(), 's3://some-bucket/dir/a\n'
            's3://some-bucket/dir/b\n'
            's3://some-bucket/dir/c/d\n')

        # clear stdout
        sys.stdout = six.StringIO()

        self.parse_args('stor list s3://some-bucket -l2')
        self.assertEquals(sys.stdout.getvalue(), 's3://some-bucket/a\n'
                          's3://some-bucket/b\n')

        mock_list.assert_has_calls([
            mock.call(S3Path('s3://some-bucket'), starts_with='dir'),
            mock.call(S3Path('s3://some-bucket'), limit=2)
        ])
    def test_string_compatibility(self):
        """ Test compatibility with ordinary strings. """
        x = S3Path('s3://xyzzy')
        assert x == 's3://xyzzy'
        assert x == str('s3://xyzzy')
        assert 'xyz' in x
        assert 'analysis' not in x

        # sorting
        items = [S3Path('s3://fhj'),
                 S3Path('s3://fgh'),
                 's3://E',
                 S3Path('s3://d'),
                 's3://A',
                 S3Path('s3://B'),
                 's3://c']
        items.sort()
        self.assertEqual(items,
                         ['s3://A', 's3://B', 's3://E', 's3://c',
                          's3://d', 's3://fgh', 's3://fhj'])

        # Test p1/p1.
        p1 = S3Path("s3://foo")
        p2 = "bar"
        self.assertEqual(p1 / p2, S3Path("s3://foo/bar"))
示例#6
0
文件: test_cli.py 项目: jdavisp3/stor
 def test_walkfiles_s3(self, mock_walkfiles):
     mock_walkfiles.return_value = [
         's3://bucket/a/b.txt', 's3://bucket/c.txt', 's3://bucket/d.txt'
     ]
     self.parse_args('stor walkfiles -p=*.txt s3://bucket')
     self.assertEquals(
         sys.stdout.getvalue(), 's3://bucket/a/b.txt\n'
         's3://bucket/c.txt\n'
         's3://bucket/d.txt\n')
     mock_walkfiles.assert_called_once_with(S3Path('s3://bucket'),
                                            pattern='*.txt')
示例#7
0
    def test_list_options(self, mock_list):
        mock_list.side_effect = [[
            S3Path('s3://some-bucket/dir/a'),
            S3Path('s3://some-bucket/dir/b'),
            S3Path('s3://some-bucket/dir/c/d')
        ], [
            S3Path('s3://some-bucket/a'),
            S3Path('s3://some-bucket/b')
        ]]

        self.parse_args('stor list s3://some-bucket -s dir -l2 --canonicalize')
        self.assertEquals(sys.stdout.getvalue(),
                          's3://some-bucket/dir/a\n'
                          's3://some-bucket/dir/b\n'
                          's3://some-bucket/dir/c/d\n')

        mock_list.assert_has_calls([
            mock.call(S3Path('s3://some-bucket'), starts_with='dir', limit=2, canonicalize=True)
        ])
示例#8
0
 def test_cat_s3(self, mock_read):
     mock_read.return_value = b'hello world\n'
     self.parse_args('stor cat s3://test/file')
     self.assertEquals(sys.stdout.getvalue(), 'hello world\n')
     mock_read.assert_called_once_with(S3Path('s3://test/file'))
示例#9
0
 def test_rmtree_s3(self, mock_rmtree):
     self.parse_args('stor rm -r s3://bucket/dir')
     mock_rmtree.assert_called_once_with(S3Path('s3://bucket/dir'))
示例#10
0
 def test_remove_s3(self, mock_remove):
     self.parse_args('stor rm s3://bucket/file1')
     mock_remove.assert_called_once_with(S3Path('s3://bucket/file1'))
示例#11
0
 def test_relpath_nested_parent(self, mock_pwd):
     mock_pwd.return_value = 's3://a/b/c'
     self.assertEquals(cli.get_path('s3:../../d'), S3Path('s3://a/d'))
     mock_pwd.return_value = 'swift://a/b/c/'
     self.assertEquals(cli.get_path('swift:../../d'), SwiftPath('swift://a/d'))
示例#12
0
 def test_relpath_parent_subdir_s3(self, mock_pwd):
     mock_pwd.return_value = 's3://test/dir'
     self.assertEquals(cli.get_path('s3:../b/c'), S3Path('s3://test/b/c'))
     mock_pwd.return_value = 's3://test/dir/'
     self.assertEquals(cli.get_path('s3:../b/c'), S3Path('s3://test/b/c'))
示例#13
0
 def test_relpath_current_subdir_no_dot_s3(self, mock_pwd):
     mock_pwd.return_value = 's3://test'
     self.assertEquals(cli.get_path('s3:b/c'), S3Path('s3://test/b/c'))
     mock_pwd.return_value = 's3://test/'
     self.assertEquals(cli.get_path('s3:b/c'), S3Path('s3://test/b/c'))
 def test_relpath(self):
     with self.assertRaises(AttributeError):
         S3Path('s3://bucket').relpathto()
     with self.assertRaises(AttributeError):
         S3Path('s3://bucket').relpath()
 def test_construction_from_none(self):
     with self.assertRaises(ValueError):
         S3Path(None)
示例#16
0
文件: test_utils.py 项目: ying-w/stor
 def test_success(self):
     path = 's3://stor-test/foo/bar'
     self.assertTrue(utils.is_writeable(path))
     self.mock_remove.assert_called_with(
         S3Path('{}/{}'.format(path, self.filename)))