Skip to content

Commit

Permalink
Merge pull request #1999 from davidmarin/test-touchz
Browse files Browse the repository at this point in the history
test hadoop fs touchz() (fixes #1981)
  • Loading branch information
David Marin committed Feb 27, 2019
2 parents b756231 + 960349a commit a71c3d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/fs/test_hadoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def test_rm_nonexistent(self):
self.fs.rm('hdfs:///baz')

def test_touchz(self):
# mockhadoop doesn't implement this (see #1981)
pass
self.assertEqual(list(self.fs.ls('hdfs:///')), [])

self.fs.touchz('hdfs:///empty')

self.assertEqual(list(self.fs.ls('hdfs:///')),
['hdfs:///empty'])


class Hadoop1FSTestCase(HadoopFSTestCase):
Expand Down
29 changes: 29 additions & 0 deletions tests/mockhadoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,35 @@ def hadoop_fs_test(stdout, stderr, environ, *args):
return 1


def hadoop_fs_touchz(stdout, stderr, environ, *args):
"""Implements hadoop fs -touchz'"""
if len(args) < 1:
print('Usage: hadoop fs [generic options] -touchz <path> ...]',
file=stderr)
return -1

uri = args[0]
path = hdfs_uri_to_real_path(uri, environ)

if os.path.exists(path):
if os.path.getsize(path) == 0:
return 0
else:
print(
"touchz: `%s': Not a zero-length file" % uri, file=stderr)
return 1
else:
try:
with open(path, 'w'):
pass
return 0
except FileNotFoundError:
print(
"touchz: `%s': No such file or directory: `%s'" % (
uri, uri), file=stderr)
return 1


def hadoop_jar(stdout, stderr, environ, *args):
if len(args) < 1:
print('RunJar jarFile [mainClass] args...', file=stderr)
Expand Down

0 comments on commit a71c3d0

Please sign in to comment.