Exemplo n.º 1
0
class JoinTestCase(SandboxedTestCase):

    def setUp(self):
        super(JoinTestCase, self).setUp()

        # os.path.join() and posixpath.join() do the same thing in
        # UNIX and OS X, so track which one we called
        self.start(patch('os.path.join', wraps=os.path.join))
        self.start(patch('posixpath.join', wraps=posixpath.join))

        self.fs = Filesystem()

    def test_local_paths(self):
        self.assertEqual(self.fs.join('foo', 'bar'),
                         'foo%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', '%sbar' % os.path.sep),
                         '%sbar' % os.path.sep)

        self.assertTrue(os.path.join.called)

    def test_path_onto_uri(self):
        self.assertEqual(self.fs.join('hdfs://host', 'path'),
                         'hdfs://host/path')

        self.assertTrue(posixpath.join.called)

    def test_uri_onto_anything(self):
        self.assertEqual(self.fs.join('hdfs://host', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path'),
                         'hdfs://host2/path')

        self.assertFalse(os.path.join.called)
        self.assertFalse(posixpath.join.called)
Exemplo n.º 2
0
class JoinTestCase(SandboxedTestCase):
    def setUp(self):
        super(JoinTestCase, self).setUp()

        # os.path.join() and posixpath.join() do the same thing in
        # UNIX and OS X, so track which one we called
        self.start(patch('os.path.join', wraps=os.path.join))
        self.start(patch('posixpath.join', wraps=posixpath.join))

        self.fs = Filesystem()

    def test_local_paths(self):
        self.assertEqual(self.fs.join('foo', 'bar'), 'foo%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', '%sbar' % os.path.sep),
                         '%sbar' % os.path.sep)

        self.assertTrue(os.path.join.called)

    def test_path_onto_uri(self):
        self.assertEqual(self.fs.join('hdfs://host', 'path'),
                         'hdfs://host/path')

        self.assertTrue(posixpath.join.called)

    def test_uri_onto_anything(self):
        self.assertEqual(self.fs.join('hdfs://host', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path'),
                         'hdfs://host2/path')

        self.assertFalse(os.path.join.called)
        self.assertFalse(posixpath.join.called)
Exemplo n.º 3
0
    def test_path_exists(self):
        fs = Filesystem()

        with patch.object(fs, "exists"):
            with no_handlers_for_logger("mrjob.fs.base"):
                fs.path_exists("foo")

            fs.exists.assert_called_once_with("foo")
Exemplo n.º 4
0
    def test_path_join(self):
        fs = Filesystem()

        with patch.object(fs, "join"):
            with no_handlers_for_logger("mrjob.fs.base"):
                fs.path_join("foo", "bar")

            fs.join.assert_called_once_with("foo", "bar")
Exemplo n.º 5
0
    def test_path_exists(self):
        fs = Filesystem()

        with patch.object(fs, 'exists'):
            with no_handlers_for_logger('mrjob.fs.base'):
                fs.path_exists('foo')

            fs.exists.assert_called_once_with('foo')
Exemplo n.º 6
0
    def test_path_exists(self):
        fs = Filesystem()

        with patch.object(fs, 'exists'):
            with no_handlers_for_logger('mrjob.fs.base'):
                fs.path_exists('foo')

            fs.exists.assert_called_once_with('foo')
Exemplo n.º 7
0
    def test_path_join(self):
        fs = Filesystem()

        with patch.object(fs, 'join'):
            with no_handlers_for_logger('mrjob.fs.base'):
                fs.path_join('foo', 'bar')

            fs.join.assert_called_once_with('foo', 'bar')
Exemplo n.º 8
0
    def test_path_join(self):
        fs = Filesystem()

        with patch.object(fs, 'join'):
            with no_handlers_for_logger('mrjob.fs.base'):
                fs.path_join('foo', 'bar')

            fs.join.assert_called_once_with('foo', 'bar')
Exemplo n.º 9
0
    def setUp(self):
        super(JoinTestCase, self).setUp()

        # os.path.join() and posixpath.join() do the same thing in
        # UNIX and OS X, so track which one we called
        self.start(patch('os.path.join', wraps=os.path.join))
        self.start(patch('posixpath.join', wraps=posixpath.join))

        self.fs = Filesystem()
Exemplo n.º 10
0
    def test_multiple_files(self):
        fs = Filesystem()

        fs.ls = Mock(return_value=['path1', 'path2', 'path3'])
        fs._cat_file = Mock(return_value=[b'chunk1\n', b'chunk2'])

        chunks = list(fs.cat('whatever'))

        self.assertEqual(chunks, [
            b'chunk1\n', b'chunk2', b'', b'chunk1\n', b'chunk2', b'',
            b'chunk1\n', b'chunk2'
        ])
Exemplo n.º 11
0
    def test_multiple_files(self):
        fs = Filesystem()

        fs.ls = Mock(return_value=['path1', 'path2', 'path3'])
        fs._cat_file = Mock(return_value=[b'chunk1\n', b'chunk2'])

        chunks = list(fs.cat('whatever'))

        self.assertEqual(
            chunks,
            [b'chunk1\n', b'chunk2', b'',
             b'chunk1\n', b'chunk2', b'',
             b'chunk1\n', b'chunk2'])
Exemplo n.º 12
0
class JoinTestCase(SandboxedTestCase):

    def setUp(self):
        super(JoinTestCase, self).setUp()

        self.fs = Filesystem()

    def test_local_paths(self):
        self.assertEqual(self.fs.join('foo', 'bar'),
                         'foo%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', '%sbar' % os.path.sep),
                         '%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', 'bar', 'baz'),
                         'foo%sbar%sbaz' % (os.path.sep, os.path.sep))

    def test_path_onto_uri(self):
        self.assertEqual(self.fs.join('hdfs://host', 'path'),
                         'hdfs://host/path')

    def test_uri_onto_anything(self):
        self.assertEqual(self.fs.join('hdfs://host', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path', 'subdir'),
                         'hdfs://host2/path/subdir')
Exemplo n.º 13
0
    def setUp(self):
        super(JoinTestCase, self).setUp()

        # os.path.join() and posixpath.join() do the same thing in
        # UNIX and OS X, so track which one we called
        self.start(patch('os.path.join', wraps=os.path.join))
        self.start(patch('posixpath.join', wraps=posixpath.join))

        self.fs = Filesystem()
Exemplo n.º 14
0
class JoinTestCase(SandboxedTestCase):
    def setUp(self):
        super(JoinTestCase, self).setUp()

        self.fs = Filesystem()

    def test_local_paths(self):
        self.assertEqual(self.fs.join("foo", "bar"), "foo%sbar" % os.path.sep)
        self.assertEqual(self.fs.join("foo", "%sbar" % os.path.sep), "%sbar" % os.path.sep)
        self.assertEqual(self.fs.join("foo", "bar", "baz"), "foo%sbar%sbaz" % (os.path.sep, os.path.sep))

    def test_path_onto_uri(self):
        self.assertEqual(self.fs.join("hdfs://host", "path"), "hdfs://host/path")

    def test_uri_onto_anything(self):
        self.assertEqual(self.fs.join("hdfs://host", "hdfs://host2/path"), "hdfs://host2/path")
        self.assertEqual(self.fs.join("/", "hdfs://host2/path"), "hdfs://host2/path")
        self.assertEqual(self.fs.join("/", "hdfs://host2/path", "subdir"), "hdfs://host2/path/subdir")
Exemplo n.º 15
0
class JoinTestCase(SandboxedTestCase):
    def setUp(self):
        super(JoinTestCase, self).setUp()

        self.fs = Filesystem()

    def test_local_paths(self):
        self.assertEqual(self.fs.join('foo', 'bar'), 'foo%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', '%sbar' % os.path.sep),
                         '%sbar' % os.path.sep)
        self.assertEqual(self.fs.join('foo', 'bar', 'baz'),
                         'foo%sbar%sbaz' % (os.path.sep, os.path.sep))

    def test_path_onto_uri(self):
        self.assertEqual(self.fs.join('hdfs://host', 'path'),
                         'hdfs://host/path')

    def test_uri_onto_anything(self):
        self.assertEqual(self.fs.join('hdfs://host', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path'),
                         'hdfs://host2/path')
        self.assertEqual(self.fs.join('/', 'hdfs://host2/path', 'subdir'),
                         'hdfs://host2/path/subdir')
Exemplo n.º 16
0
    def setUp(self):
        super(JoinTestCase, self).setUp()

        self.fs = Filesystem()
Exemplo n.º 17
0
    def setUp(self):
        super(JoinTestCase, self).setUp()

        self.fs = Filesystem()