shaarli / python-shaarli-client

Python3 CLI to interact with a Shaarli instance
https://python-shaarli-client.readthedocs.io/
MIT License
44 stars 10 forks source link

Add output file (--outfile) command line argument #23

Closed nodiscc closed 6 years ago

nodiscc commented 6 years ago
add --outfile optional parameter: specify a filename to write the API request result to
 * by default output is redirected to standard output
 * add -f and -o short options (format/output)
 * overwrite output file on each run, don't append (appending will cause a malformed json file)
 * move json import to utils.py
 * move response formatting and output to separate functions
 * styling fixes, tab to spaces, alignment, sort imports
 * use a context manager to handle writing output file
 * Handle OSError execptions
nodiscc commented 6 years ago

https://github.com/shaarli/python-shaarli-client/pull/23/commits/a2a3190212d3feb85fa01f39689779ec61821244 tries to address

printing to console and writing to files should be split over two separate functions, with a bit of logic to process argparse flags in the main() function

Or did you mean something else?

TODO test scenarii: for each supported format:

nodiscc commented 6 years ago

Hi, sorry for the delay, I think this PR should be in working order now (?).
I will have a look at https://github.com/shaarli/python-shaarli-client/commit/95623f43dbbfbf10d7590cecfc47def9b26b06a8 and try to add the tests you suggested.

nodiscc commented 6 years ago

Fixed, but at this point I have no idea how to implement the tests, because I see nothing that deals with the program output or files on disk in the current tests...

Pardon my weak Python-fu, if you could point me to a draft test/pseudocode/similar example to do this the right way I could probably start from there

virtualtam commented 6 years ago

Sure :)

Basically what such tests do is:

This is done by using Pytest's tmpdir fixture, which in turn leverages the py.path high-level filesystem API.

More specifically, tests could cover these functionalities:

nodiscc commented 6 years ago

Superseded by #31