-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --recursive
option to fs ls
command
#513
Open
justinTM
wants to merge
4
commits into
databricks:main
Choose a base branch
from
justinTM:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−14
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,26 @@ | |
|
||
TEST_DBFS_PATH = DbfsPath('dbfs:/test') | ||
DUMMY_TIME = 1613158406000 | ||
TEST_FILE_JSON = { | ||
TEST_FILE_JSON1 = { | ||
'path': '/test', | ||
'is_dir': False, | ||
'file_size': 1, | ||
'modification_time': DUMMY_TIME | ||
} | ||
TEST_FILE_INFO = api.FileInfo(TEST_DBFS_PATH, False, 1, DUMMY_TIME) | ||
TEST_FILE_JSON2 = { | ||
'path': '/dir/test', | ||
'is_dir': False, | ||
'file_size': 1, | ||
'modification_time': DUMMY_TIME | ||
} | ||
TEST_DIR_JSON = { | ||
'path': '/dir', | ||
'is_dir': True, | ||
'file_size': 0, | ||
'modification_time': DUMMY_TIME | ||
} | ||
TEST_FILE_INFO0 = api.FileInfo(TEST_DBFS_PATH, False, 1, DUMMY_TIME) | ||
TEST_FILE_INFO1 = api.FileInfo(TEST_DBFS_PATH2, False, 1, DUMMY_TIME) | ||
|
||
|
||
def get_resource_does_not_exist_exception(): | ||
|
@@ -74,7 +87,7 @@ def test_to_row_long_form_not_absolute(self): | |
assert TEST_DBFS_PATH.basename == row[2] | ||
|
||
def test_from_json(self): | ||
file_info = api.FileInfo.from_json(TEST_FILE_JSON) | ||
file_info = api.FileInfo.from_json(TEST_FILE_JSON0) | ||
assert file_info.dbfs_path == TEST_DBFS_PATH | ||
assert not file_info.is_dir | ||
assert file_info.file_size == 1 | ||
|
@@ -89,15 +102,26 @@ def dbfs_api(): | |
|
||
|
||
class TestDbfsApi(object): | ||
def test_list_files_recursive(self, dbfs_api): | ||
json = { | ||
'files': [TEST_FILE_JSON0, TEST_DIR_JSON, TEST_FILE_JSON1] | ||
} | ||
dbfs_api.client.list.return_value = json | ||
files = dbfs_api.list_files("dbfs:/") | ||
|
||
assert len(files) == 2 | ||
assert TEST_FILE_INFO0 == files[0] | ||
assert TEST_FILE_INFO1 == files[1] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There doesn't seem to be a test for a real recursive call. The variable |
||
def test_list_files_exists(self, dbfs_api): | ||
json = { | ||
'files': [TEST_FILE_JSON] | ||
'files': [TEST_FILE_JSON0] | ||
} | ||
dbfs_api.client.list.return_value = json | ||
files = dbfs_api.list_files(TEST_DBFS_PATH) | ||
files = dbfs_api.list_files(TEST_DBFS_PATH, is_recursive=True) | ||
|
||
assert len(files) == 1 | ||
assert TEST_FILE_INFO == files[0] | ||
assert TEST_FILE_INFO0 == files[0] | ||
|
||
def test_list_files_does_not_exist(self, dbfs_api): | ||
json = {} | ||
|
@@ -107,7 +131,7 @@ def test_list_files_does_not_exist(self, dbfs_api): | |
assert len(files) == 0 | ||
|
||
def test_file_exists_true(self, dbfs_api): | ||
dbfs_api.client.get_status.return_value = TEST_FILE_JSON | ||
dbfs_api.client.get_status.return_value = TEST_FILE_JSON0 | ||
assert dbfs_api.file_exists(TEST_DBFS_PATH) | ||
|
||
def test_file_exists_false(self, dbfs_api): | ||
|
@@ -116,8 +140,8 @@ def test_file_exists_false(self, dbfs_api): | |
assert not dbfs_api.file_exists(TEST_DBFS_PATH) | ||
|
||
def test_get_status(self, dbfs_api): | ||
dbfs_api.client.get_status.return_value = TEST_FILE_JSON | ||
assert dbfs_api.get_status(TEST_DBFS_PATH) == TEST_FILE_INFO | ||
dbfs_api.client.get_status.return_value = TEST_FILE_JSON0 | ||
assert dbfs_api.get_status(TEST_DBFS_PATH) == TEST_FILE_INFO0 | ||
|
||
def test_get_status_fail(self, dbfs_api): | ||
exception = get_resource_does_not_exist_exception() | ||
|
@@ -164,7 +188,7 @@ def test_get_file_check_overwrite(self, dbfs_api, tmpdir): | |
|
||
def test_get_file(self, dbfs_api, tmpdir): | ||
api_mock = dbfs_api.client | ||
api_mock.get_status.return_value = TEST_FILE_JSON | ||
api_mock.get_status.return_value = TEST_FILE_JSON0 | ||
api_mock.read.return_value = { | ||
'bytes_read': 1, | ||
'data': b64encode(b'x'), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to read this a couple times to understand what you're doing. I think it should be simplified to iterate over
paths
just once and then have anif p.is_dir
in there with both dealing with a file or a directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate comment: this also need to pass along the
headers
from the**kwargs
to be consistent with thelist_files
API today. Otherwise you use it on the first call but not later calls.