From 71616fe3a0cc2c561bf00f563ce3c788a68119e5 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Sun, 12 Apr 2020 21:20:26 +0200
Subject: [PATCH] [tests] Move CLI test units from conda/meta.yaml to nose

---
 bob/ip/binseg/test/test_cli.py | 144 +++++++++++++++++++++++++++++++++
 conda/meta.yaml                |  20 -----
 2 files changed, 144 insertions(+), 20 deletions(-)
 create mode 100644 bob/ip/binseg/test/test_cli.py

diff --git a/bob/ip/binseg/test/test_cli.py b/bob/ip/binseg/test/test_cli.py
new file mode 100644
index 00000000..5fab2a89
--- /dev/null
+++ b/bob/ip/binseg/test/test_cli.py
@@ -0,0 +1,144 @@
+#!/usr/bin/env python
+# coding=utf-8
+
+"""Tests for our CLI applications"""
+
+from click.testing import CliRunner
+
+
+def _check_help(entry_point):
+
+    runner = CliRunner()
+    result = runner.invoke(entry_point, ["--help"])
+    assert result.exit_code == 0
+    assert result.output.startswith("Usage:")
+
+
+def test_main_help():
+    from ..script.binseg import binseg
+
+    _check_help(binseg)
+
+
+def test_train_help():
+    from ..script.train import train
+
+    _check_help(train)
+
+
+def test_predict_help():
+    from ..script.predict import predict
+
+    _check_help(predict)
+
+
+def test_evaluate_help():
+    from ..script.evaluate import evaluate
+
+    _check_help(evaluate)
+
+
+def test_compare_help():
+    from ..script.compare import compare
+
+    _check_help(compare)
+
+
+def test_config_help():
+    from ..script.config import config
+
+    _check_help(config)
+
+
+def test_config_list_help():
+    from ..script.config import list
+
+    _check_help(list)
+
+
+def test_config_list():
+    from ..script.config import list
+
+    runner = CliRunner()
+    result = runner.invoke(list)
+    assert result.exit_code == 0
+    assert "module: bob.ip.binseg.configs.datasets" in result.output
+    assert "module: bob.ip.binseg.configs.models" in result.output
+
+
+def test_config_list_v():
+    from ..script.config import list
+
+    runner = CliRunner()
+    result = runner.invoke(list, ["--verbose"])
+    assert result.exit_code == 0
+    assert "module: bob.ip.binseg.configs.datasets" in result.output
+    assert "module: bob.ip.binseg.configs.models" in result.output
+
+
+def test_config_describe_help():
+    from ..script.config import describe
+
+    _check_help(describe)
+
+
+def test_config_describe_drive():
+    from ..script.config import describe
+
+    runner = CliRunner()
+    result = runner.invoke(describe, ["drive"])
+    assert result.exit_code == 0
+    assert "[DRIVE-2004]" in result.output
+
+
+def test_config_copy_help():
+    from ..script.config import copy
+
+    _check_help(copy)
+
+
+def test_config_copy():
+    from ..script.config import copy
+
+    runner = CliRunner()
+    with runner.isolated_filesystem():
+        result = runner.invoke(copy, ["drive", "test.py"])
+        assert result.exit_code == 0
+        with open("test.py") as f:
+            data = f.read()
+        assert "[DRIVE-2004]" in data
+
+
+def test_dataset_help():
+    from ..script.dataset import dataset
+
+    _check_help(dataset)
+
+
+def test_dataset_list_help():
+    from ..script.dataset import list
+
+    _check_help(list)
+
+
+def test_dataset_list():
+    from ..script.dataset import list
+
+    runner = CliRunner()
+    result = runner.invoke(list)
+    assert result.exit_code == 0
+    assert result.output.startswith("Supported datasets:")
+
+
+def test_dataset_check_help():
+    from ..script.dataset import check
+
+    _check_help(check)
+
+
+def test_dataset_check():
+    from ..script.dataset import check
+
+    runner = CliRunner()
+    result = runner.invoke(check, ["--verbose", "--verbose"])
+    assert result.exit_code == 0
diff --git a/conda/meta.yaml b/conda/meta.yaml
index acf7858c..f014c001 100644
--- a/conda/meta.yaml
+++ b/conda/meta.yaml
@@ -47,26 +47,6 @@ test:
   imports:
     - {{ name }}
   commands:
-    # test commands ("script" entry-points) from your package here
-    - bob binseg --help
-    - bob binseg config --help
-    - bob binseg config list --help
-    - bob binseg config list
-    - bob binseg config list -v
-    - bob binseg config describe --help
-    - bob binseg config describe drive
-    - bob binseg config describe drive -v
-    - bob binseg config copy --help
-    - bob binseg config copy drive /tmp/test.py
-    - bob binseg dataset --help
-    - bob binseg dataset list --help
-    - bob binseg dataset list
-    - bob binseg dataset check --help
-    - bob binseg dataset check
-    - bob binseg train --help
-    - bob binseg predict --help
-    - bob binseg evaluate --help
-    - bob binseg compare --help
     - nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
     - sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
     - sphinx-build -aEb doctest {{ project_dir }}/doc sphinx
-- 
GitLab