o2r-project / geoextent

Python library for extrating geospatial extent of files and directories with multiple data formats
https://o2r.info/geoextent/
MIT License
1 stars 4 forks source link

Bug: when two inputs entered and one of them is invalid, library does not show result of valid one. #40

Open YouQam opened 4 years ago

nuest commented 4 years ago

To me that is not a bug. It is better if the library fails gracefully, because if it returns the result of the one input, a user might think everything went alright.

YouQam commented 4 years ago

But it doesn't work even if both inputs are valid. I will tackle it by adding a loop and if any of the inputs is invalid it returns exception, otherwise it shows results.

nuest commented 4 years ago

Please create a reproducible example.

YouQam commented 4 years ago

Screenshot from 2020-01-07 15-23-39

YouQam commented 4 years ago
test_cli.py::test_geojson_invalid_second_input[inprocess] # Running console script: geoextent testdata/geojson/muenster_ring_zeit.geojson testdata/geojson/not_existing.geojson
# Script return code: 1
# Script stdout:

# Script stderr:
Traceback (most recent call last):
  File "/home/webteam/.local/bin/geoextent", line 11, in <module>
    load_entry_point('geoextent', 'console_scripts', 'geoextent')()
  File "/home/webteam/o2r/geoextent/geoextent/__main__.py", line 83, in main
    args = vars(argparser.parse_args())
  File "/usr/lib/python3.6/argparse.py", line 1743, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.6/argparse.py", line 1775, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.6/argparse.py", line 1984, in _parse_known_args
    stop_index = consume_positionals(start_index)
  File "/usr/lib/python3.6/argparse.py", line 1940, in consume_positionals
    take_action(action, args)
  File "/usr/lib/python3.6/argparse.py", line 1849, in take_action
    action(self, namespace, argument_values, option_string)
  File "/home/webteam/o2r/geoextent/geoextent/__main__.py", line 36, in __call__
    raise argparse.ArgumentTypeError("{0} is not a valid directory or file".format(candidate))
argparse.ArgumentTypeError: testdata/geojson/not_existing.geojson is not a valid directory or file

FAILED
nuest commented 4 years ago
======================================================================== FAILURES =========================================================================
______________________________________________________ test_geojson_invalid_second_input[inprocess] _______________________________________________________

script_runner = <ScriptRunner inprocess>

    def test_geojson_invalid_second_input(script_runner):
        ret = script_runner.run('geoextent', 'tests/testdata/geojson/muenster_ring_zeit.geojson', 'tests/testdata/not_existing.geojson')
        assert not ret.success, "process should return failue"
        assert ret.stderr != '', "stderr should not be empty"
>       assert 'doesntexist' in ret.stderr, "wrong input is printed to console"
E       AssertionError: wrong input is printed to console
E       assert 'doesntexist' in 'Traceback (most recent call last):\n  File "/home/daniel/.virtualenvs/geoextent/bin/geoextent", line 11, in <module>\...format(candidate))\nargparse.ArgumentTypeError: tests/testdata/not_existing.geojson is not a valid directory or file\n'
E        +  where 'Traceback (most recent call last):\n  File "/home/daniel/.virtualenvs/geoextent/bin/geoextent", line 11, in <module>\...format(candidate))\nargparse.ArgumentTypeError: tests/testdata/not_existing.geojson is not a valid directory or file\n' = <pytest_console_scripts.RunResult object at 0x7f340bb663c8>.stderr

tests/test_cli.py:28: AssertionError
------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------
# Running console script: geoextent tests/testdata/geojson/muenster_ring_zeit.geojson tests/testdata/not_existing.geojson
# Script return code: 1
# Script stdout:

# Script stderr:
Traceback (most recent call last):
  File "/home/daniel/.virtualenvs/geoextent/bin/geoextent", line 11, in <module>
    load_entry_point('geoextent', 'console_scripts', 'geoextent')()
  File "/home/daniel/git/o2r/geoextent/geoextent/__main__.py", line 83, in main
    args = vars(argparser.parse_args())
  File "/usr/lib/python3.7/argparse.py", line 1764, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 1796, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 2005, in _parse_known_args
    stop_index = consume_positionals(start_index)
  File "/usr/lib/python3.7/argparse.py", line 1961, in consume_positionals
    take_action(action, args)
  File "/usr/lib/python3.7/argparse.py", line 1870, in take_action
    action(self, namespace, argument_values, option_string)
  File "/home/daniel/git/o2r/geoextent/geoextent/__main__.py", line 36, in __call__
    raise argparse.ArgumentTypeError("{0} is not a valid directory or file".format(candidate))
argparse.ArgumentTypeError: tests/testdata/not_existing.geojson is not a valid directory or file
nuest commented 3 years ago

We should add a test here to also test more than one zip files as input.

nuest commented 3 years ago

Related to #49