Skip to content

Commit

Permalink
Raise Error for File Not Found
Browse files Browse the repository at this point in the history
This raises an error if the file passed on the command line is not
found. This should make the CLI behave more appropriately when
mistakes are made in the arguments on the command line.

Fix pacifica#52

Signed-off-by: David Brown <dmlb2000@gmail.com>
  • Loading branch information
dmlb2000 committed Feb 3, 2020
1 parent 3ce699d commit a0a92c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ test_script:
if ($LastExitCode -eq 0) { $host.SetShouldExit(-1); };
coverage run --include='*/site-packages/pacifica/cli/*' -a -m pacifica.cli upload --dry-run --local-save retry.tar --local-compress BLAH;
if ($LastExitCode -eq 0) { $host.SetShouldExit(-1); };
coverage run --include='*/site-packages/pacifica/cli/*' -a -m pacifica.cli upload --instrument 54 --logon dmlb2001 SOMETHING_THAT_DOES_NOT_EXIST.md;
if ($LastExitCode -eq 0) { $host.SetShouldExit(-1); };
echo "Done with failure testing";
coverage run --include='*/site-packages/pacifica/cli/*' -a -m pacifica.cli upload --dry-run --logon dmlb2001 --project-regex 'expired closed and end';
Invoke-WebRequest -Method POST -Headers @{ "content-type" = "application/json" } -Body '{ "network_id":"appveyor" }' http://localhost:8121/users?_id=10;
Expand Down
3 changes: 3 additions & 0 deletions pacifica/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from threading import Thread
from json import dumps
from copy import deepcopy
import errno
from sys import stdout
from os import pipe, fdopen, walk, stat
from os.path import isfile, isdir, sep, join
Expand Down Expand Up @@ -36,6 +37,8 @@ def build_file_list_from_args(file_list, followlinks):
ret.extend(generate_names_from_dir(path, followlinks))
elif isfile(path):
ret.append(path)
else:
raise OSError(errno.ENOENT, '{} is not a file or directory.'.format(path))
return ret


Expand Down
5 changes: 4 additions & 1 deletion travis/unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ $COV_RUN -a -m pacifica.cli upload --dry-run --logon dmlb2001 --project-regex 'e
############################
curl -X POST -H 'content-type: application/json' 'localhost:8121/users?_id=10' -d'{ "network_id": "'`whoami`'"}'
curl -X POST -H 'content-type: application/json' 'localhost:8121/users?_id=11' -d'{ "network_id": "someoneelse"}'
$COV_RUN -a -m pacifica.cli upload SOMETHING_THAT_DOES_NOT_EXIST.txt || true
if ! $COV_RUN -a -m pacifica.cli upload SOMETHING_THAT_DOES_NOT_EXIST.txt ; then
echo "This should have failed"
exit -1
fi
export PACIFICA_CLI_INI="/home/travis/.pacifica_cli/config.ini"
$COV_RUN -a -m pacifica.cli upload README.md
$COV_RUN -a -m pacifica.cli upload travis
Expand Down

0 comments on commit a0a92c6

Please sign in to comment.