Repository: bird-house/birdy

Issue:
Don't show ipython warnings when using command-line interface.
## Description

When running the birdy command line ipython warnings are show when they are not installed:

The CLI does not need ipython, so warnings can be deactivate in this case.

## Environment

* Birdy version used, if any: 0.5.0
* Python version, if any:
* Operating System:

## Steps to Reproduce
```
$ birdy -h
/Users/pingu/Documents/GitHub/birdhouse/birdy/birdy/dependencies.py:20: IPythonWarning: Jupyter Notebook is not supported. Please install *ipywidgets*.
  warnings.warn('Jupyter Notebook is not supported. Please install *ipywidgets*.', IPythonWarning)
/Users/pingu/Documents/GitHub/birdhouse/birdy/birdy/dependencies.py:26: IPythonWarning: IPython is not supported. Please install *ipython*.
  warnings.warn('IPython is not supported. Please install *ipython*.', IPythonWarning)
Usage: birdy [OPTIONS] COMMAND [ARGS]...

  Birdy is a command line client for Web Processing Services.
```

## Additional Information




Comments:

Patch:
diff --git a/birdy/client/base.py b/birdy/client/base.py
index 71f8eec..1fd5855 100644
--- a/birdy/client/base.py
+++ b/birdy/client/base.py
@@ -165,20 +165,6 @@ class WPSClient(object):
 
         process = self._processes[pid]
 
-        def sort_inputs_key(i):
-            """Function used as key when sorting process inputs.
-
-            The order is:
-             - Inputs that have minOccurs >= 1 and no default value
-             - Inputs that have minOccurs >= 1 and a default value
-             - Every other input
-            """
-            return list(reversed([
-                i.minOccurs >= 1 and i.defaultValue is None,
-                i.minOccurs >= 1,
-                i.minOccurs == 0,
-            ]))
-
         required_inputs_first = sorted(process.dataInputs, key=sort_inputs_key)
 
         input_names = []
@@ -325,6 +311,27 @@ class WPSClient(object):
             self.logger.info("{} failed.".format(execution.process.identifier))
 
 
+def sort_inputs_key(i):
+    """Function used as key when sorting process inputs.
+
+    The order is:
+     - Inputs that have minOccurs >= 1 and no default value
+     - Inputs that have minOccurs >= 1 and a default value
+     - Every other input
+
+    Parameters
+    ----------
+    i: owslib.wps.Input
+      An owslib Input
+    """
+    conditions = [
+        i.minOccurs >= 1 and i.defaultValue is None,
+        i.minOccurs >= 1,
+        i.minOccurs == 0,
+    ]
+    return [not c for c in conditions]  # False values are sorted first
+
+
 def nb_form(wps, pid):
     """Return a Notebook form to enter input values and launch process."""
     if wps._notebook:
diff --git a/birdy/dependencies.py b/birdy/dependencies.py
index f5ccac5..a59d49b 100644
--- a/birdy/dependencies.py
+++ b/birdy/dependencies.py
@@ -11,7 +11,9 @@ Example usage::
 import warnings
 from .exceptions import IPythonWarning
 
-warnings.filterwarnings('default', category=IPythonWarning)
+# TODO: we ignore warnings for now. They are only needed when birdy is used in a notebook,
+# but we currently don't know how to handle this (see #89 and #138).
+warnings.filterwarnings('ignore', category=IPythonWarning)
 
 try:
     import ipywidgets


Test patch:
diff --git a/tests/test_client.py b/tests/test_client.py
index f9881d0..97bb7bc 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -1,15 +1,17 @@
 import datetime
 import os
-import pytest
 import json
+import tempfile
+from pathlib import Path
+from unittest import mock
+
+import pytest
 # from owslib import crs
 
-from pathlib import Path
 from birdy.client import converters, nb_form
+from birdy.client.base import sort_inputs_key
 from birdy.client.utils import is_embedded_in_request
 from birdy import WPSClient
-from io import StringIO, BytesIO
-import tempfile
 
 
 # These tests assume Emu is running on the localhost
@@ -253,6 +255,34 @@ def test_xarray_converter(wps):
     assert isinstance(ncdata, xr.Dataset)
 
 
+def test_sort_inputs():
+    """
+    The order should be:
+     - Inputs that have minOccurs >= 1 and no default value
+     - Inputs that have minOccurs >= 1 and a default value
+     - Every other input
+    """
+
+    i = mock.Mock()
+    i.minOccurs = 1
+    i.defaultValue = None
+    assert sort_inputs_key(i) == [False, False, True]
+
+    i = mock.Mock()
+    i.minOccurs = 1
+    i.defaultValue = "default"
+    assert sort_inputs_key(i) == [True, False, True]
+
+    i = mock.Mock()
+    i.minOccurs = 0
+    assert sort_inputs_key(i) == [True, True, False]
+
+    i = mock.Mock()
+    i.minOccurs = 0
+    i.defaultValue = "default"
+    assert sort_inputs_key(i) == [True, True, False]
+
+
 def test_all_subclasses():
     c = converters.all_subclasses(converters.BaseConverter)
     assert converters.Meta4Converter in c