Skip to content

Commit c4d7833

Browse files
committed
No longer treating empty text scripts as an error condition
1 parent e1cde42 commit c4d7833

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

cmd2/cmd2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,9 +3790,8 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
37903790
self.perror("'{}' is not a file".format(expanded_path))
37913791
return
37923792

3793-
# Make sure the file is not empty
3793+
# An empty file is not an error, so just return
37943794
if os.path.getsize(expanded_path) == 0:
3795-
self.perror("'{}' is empty".format(expanded_path))
37963795
return
37973796

37983797
# Make sure the file is ASCII or UTF-8 encoded text

tests/test_cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def test_run_script_with_empty_file(base_app, request):
318318
test_dir = os.path.dirname(request.module.__file__)
319319
filename = os.path.join(test_dir, 'scripts', 'empty.txt')
320320
out, err = run_cmd(base_app, 'run_script {}'.format(filename))
321-
assert "is empty" in err[0]
321+
assert not out and not err
322322

323323
def test_run_script_with_binary_file(base_app, request):
324324
test_dir = os.path.dirname(request.module.__file__)

0 commit comments

Comments
 (0)