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)
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")
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")
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')
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')
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_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' ])
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'])
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')
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")
def setUp(self): super(JoinTestCase, self).setUp() self.fs = Filesystem()