Repository: mintproject/dame_cli

Issue:
add testing
test a simple command in:
- osx, windows, python

language: python
python:
  - "3.4"
  - "3.5"
  - "3.6"      # current default Python on Travis CI
  - "3.7"
  - "3.8"

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 22abdd9..5fa1290 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,57 @@
-dist: xenial
 language: python
-python:
-- '3.7'
+
+jobs:
+  include:
+    - name: 'Linux - py3.6, 3.7, 3.8' 
+      python: 
+        - "3.6"      # current default Python on Travis CI
+        - "3.7"
+        - "3.8"
+      dist: xenial
+    - name: "macOS 10.13 - py3.6.5"
+      os: osx
+      osx_image: xcode9.4
+      language: shell
+      before_install:
+        - python3 --version
+        - pip3 install -U pip
+        - pip3 install -U tox
+        - pip3 install codecov
+      script: python3 -m tox
+      after_success: python 3 -m codecov
+    - name: "xcode10.2 - py3.7.3"
+      os: osx
+      osx_image: xcode10.2
+      language: shell
+      before_install:
+        - python3 --version
+        - pip3 install -U pip
+        - pip3 install -U tox
+        - pip3 install codecov
+      script: python3 -m tox
+      after_success: python 3 -m codecov
+    - name: "Python 3.6.8 on Windows"
+      os: windows           # Windows 10.0.17134 N/A Build 17134
+      language: shell       # 'language: python' is an error on Travis CI Windows
+      before_install:
+        - choco install python --version  3.6.8
+        - python --version
+        - python -m pip install --upgrade pip
+        - pip3 install --upgrade tox
+        - pip3 install codecov
+      env: PATH=/c/Python36:/c/Python35/Scripts:$PATH
+    - name: "Python 3.7.4 on Windows"
+      os: windows           # Windows 10.0.17134 N/A Build 17134
+      language: shell       # 'language: python' is an error on Travis CI Windows
+      before_install:
+        - choco install python --version 3.7.4
+        - python --version
+        - python -m pip install --upgrade pip
+        - pip3 install --upgrade tox
+        - pip3 install codecov
+      env: PATH=/c/Python37:/c/Python35/Scripts:$PATH
+  allow_failures:
+    - os: windows
 install: pip install tox-travis
 script: tox
 deploy:
diff --git a/README.md b/README.md
index fa575d0..ff9eb7b 100644
--- a/README.md
+++ b/README.md
@@ -13,9 +13,9 @@ The application needs Singularity to run the containers.
 
 If you would like support for Docker, let us know: [Support Docker](https://github.com/mintproject/dame_cli/issues/15)
 
-### Python 3
+### Python
 
-The applications needs Python. 
+The applications needs Python >=3.6
 
 - [Installation on Linux](https://realpython.com/installing-python/#linux)
 - [Installation on Windows](https://realpython.com/installing-python/#windows)
diff --git a/VERSION b/VERSION
deleted file mode 100644
index 3debf3b..0000000
--- a/VERSION
+++ /dev/null
@@ -1,1 +0,0 @@
-2.3.0-0
diff --git a/src/dame/__main__.py b/src/dame/__main__.py
index 05d8fcd..6780264 100644
--- a/src/dame/__main__.py
+++ b/src/dame/__main__.py
@@ -12,7 +12,7 @@ from modelcatalog import OpenApiException
 
 import dame
 from dame import _utils
-from dame.cli_methods import verify_input_parameters, run_method_setup
+from dame.cli_methods import verify_input_parameters, run_method_setup, show_model_configuration_details
 from dame.modelcatalogapi import get_setup, get_model_configuration
 
 try:
@@ -65,10 +65,10 @@ def run(name):
 
     if "ModelConfigurationSetup" in config.type:
         resource = get_setup(name)
-        verify_input_parameters(resource)
     elif "ModelConfiguration" in config.type:
         resource = get_model_configuration(name)
-        verify_input_parameters(resource)
+    show_model_configuration_details(resource)
+    verify_input_parameters(resource)
     # setup = get_setup(name)
     # edit_inputs_setup(setup)
     run_method_setup(resource)
diff --git a/src/dame/cli_methods.py b/src/dame/cli_methods.py
index ddf94ee..ddf96ba 100644
--- a/src/dame/cli_methods.py
+++ b/src/dame/cli_methods.py
@@ -12,6 +12,33 @@ from dame._utils import log
 from dame.modelcatalogapi import get_setup
 from modelcatalog import ApiException, SampleResource
 
+data_set_property = ["id", "label"]
+parameter_set_property = ["id", "label", "has_default_value"]
+
+
+def show_model_configuration_details(model_configuration):
+    click.echo(click.style("Information about the model configuration", bold=True))
+    if model_configuration and hasattr(model_configuration, "has_input"):
+        click.echo(click.style("Inputs", bold=True))
+        for _input in model_configuration.has_input:
+            if hasattr(_input, "has_fixed_resource") and hasattr(_input.has_fixed_resource[0], "value"):
+                click.echo("{}: {}".format(_input.label[0], _input.has_fixed_resource[0].value[0]))
+            else:
+                label = getattr(_input, "label") if hasattr(_input, "label") else getattr(_input, "id")
+                click.echo("{}: {}".format(label[0], "No information"))
+    if model_configuration and hasattr(model_configuration, "has_parameter"):
+        click.echo(click.style("Parameters", bold=True))
+        for _parameter in model_configuration.has_parameter:
+            short_value(_parameter, "has_default_value")
+
+
+
+def short_value(resource, prop):
+    if hasattr(resource, prop):
+        value = getattr(resource, prop)
+        click.echo("{}: {}".format(getattr(resource, "label")[0], value[0]))
+
+
 def verify_input_parameters(model_configuration):
     for _input in model_configuration.has_input:
         if not hasattr(_input, "has_fixed_resource"):
@@ -45,7 +72,10 @@ def edit_parameter_config_or_setup(resource, auto=False):
                 value = click.prompt('Enter the value for the parameter:', default=default_value)
         parameter["hasFixedValue"] = [value]
 
-def print_data_property_table(resource):
+
+
+
+def print_data_property_table(resource, property_selected={}):
     resource_dict = resource.to_dict()
     tab = tt.Texttable(max_width=100)
     headings = ['Property', 'Value']
@@ -53,6 +83,9 @@ def print_data_property_table(resource):
     for key, value in resource_dict.items():
         if isinstance(value, dict) or key == "type" or key == "has_presentation":
             continue
+        if property_selected:
+            if key not in property_selected:
+                continue
         tab.add_row([key,value])
     print(tab.draw())
 
diff --git a/tox.ini b/tox.ini
index 797e5ee..4601ef1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,7 +5,7 @@ envlist  = py37,py35
 
 [testenv]
 
-commands = pytest --cov {envsitepackagesdir}/mint {posargs}
+commands = pytest --cov {envsitepackagesdir}/dame {posargs}
 
 setenv   = PYTHONPATH         = {toxinidir}/src
            PYTHONUNBUFFERED   = yes


Test patch:
diff --git a/src/dame/tests/test___main__.py b/src/dame/tests/test___main__.py
new file mode 100644
index 0000000..a241b97
--- /dev/null
+++ b/src/dame/tests/test___main__.py
@@ -0,0 +1,28 @@
+from unittest import TestCase
+
+from click.testing import CliRunner
+
+from dame.__main__ import version, run
+import dame
+
+SETUP_FULL_INFO = "cycles-0.10.2-alpha-collection-oromia-single-point"
+
+
+class Test(TestCase):
+    def test_version(self):
+        runner = CliRunner()
+        result = runner.invoke(version)
+        assert result.exit_code == 0
+        assert result.output == f"DAME: v{dame.__version__}\n"
+
+
+    # def test_run(self):
+    #     runner = CliRunner()
+    #     result = runner.invoke(run, SETUP_FULL_INFO)
+    #     assert not result.exception
+
+
+    # def test_run_partial(self):
+    #     runner = CliRunner()
+    #     result = runner.invoke(run, SETUP_FULL_INFO)
+    #     assert not result.exception
diff --git a/src/dame/tests/test_cli_methods.py b/src/dame/tests/test_cli_methods.py
new file mode 100644
index 0000000..ccc9476
--- /dev/null
+++ b/src/dame/tests/test_cli_methods.py
@@ -0,0 +1,35 @@
+from unittest import TestCase
+
+from dame.cli_methods import verify_input_parameters, print_data_property_table, show_model_configuration_details
+from dame.modelcatalogapi import get_setup, list_setup, list_model_configuration
+
+from click.testing import CliRunner
+
+SETUP_PARTIAL_INFO = "dsi_1.0_cfg"
+SETUP_FULL_INFO = "cycles-0.10.2-alpha-collection-oromia-single-point"
+
+
+class Test(TestCase):
+    def test_verify_input_parameters(self):
+        runner = CliRunner()
+        partial_setup = get_setup(SETUP_FULL_INFO)
+        assert verify_input_parameters(partial_setup) == partial_setup
+
+    def test_print_data_property_table(self):
+        full = get_setup(SETUP_FULL_INFO)
+        partial = get_setup(SETUP_PARTIAL_INFO)
+        print_data_property_table(full)
+        print_data_property_table(partial)
+
+    def test_show_model_configuration_details(self):
+        full = get_setup(SETUP_FULL_INFO)
+        partial = get_setup(SETUP_PARTIAL_INFO)
+        show_model_configuration_details(full)
+        show_model_configuration_details(partial)
+
+
+    def test_show_model_configuration_details(self):
+        for setup in list_setup():
+            show_model_configuration_details(setup)
+        for model_configuration in list_model_configuration():
+            show_model_configuration_details(model_configuration)
diff --git a/src/dame/tests/test_modelcatalogapi.py b/src/dame/tests/test_modelcatalogapi.py
new file mode 100644
index 0000000..0e93ae3
--- /dev/null
+++ b/src/dame/tests/test_modelcatalogapi.py
@@ -0,0 +1,12 @@
+from unittest import TestCase
+
+from dame.modelcatalogapi import get_setup
+from dame.utils import obtain_id
+
+SETUP_FULL_INFO = "cycles-0.10.2-alpha-collection-oromia-single-point"
+SETUP_PARTIAL_INFO = "dsi_1.0_cfg"
+
+class Test(TestCase):
+    def test_get_setup(self):
+        assert obtain_id(get_setup(SETUP_FULL_INFO).id) == SETUP_FULL_INFO
+        assert obtain_id(get_setup(SETUP_PARTIAL_INFO).id) == SETUP_PARTIAL_INFO
diff --git a/src/dame/tests/test_utils.py b/src/dame/tests/test_utils.py
new file mode 100644
index 0000000..8fb86be
--- /dev/null
+++ b/src/dame/tests/test_utils.py
@@ -0,0 +1,9 @@
+from unittest import TestCase
+
+from dame.utils import obtain_id
+
+
+class Test(TestCase):
+    def test_obtain_id(self):
+        url = "https://w3id.org/okn/i/mint/cycles-0.10.2-alpha-collection-oromia-single-point"
+        assert obtain_id(url) == "cycles-0.10.2-alpha-collection-oromia-single-point"