From 01bc61e7eb009f31f7a1680a72092d9245debd58 Mon Sep 17 00:00:00 2001
From: Enrique Garcia <garcia@lapp.in2p3.fr>
Date: Wed, 8 Sep 2021 10:17:30 +0200
Subject: [PATCH] tests help for all scripts

---
 .gitlab-ci.yml                      |  5 -----
 eossr/scripts/tests/test_scripts.py | 28 ++++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1a223418..abc50b24 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,11 +17,6 @@ install_py37:
     - eossr-codemeta2zenodo --help
     - eossr-codemeta2zenodo --input_codemeta_file ./codemeta.json
     - cat .zenodo.json
-    - echo "testing all entry points and bash scripts"
-    - eossr-upload-new-deposit -h
-    - eossr-upload-new-version-deposit -h
-    - eossr-check-connection-zenodo -h
-    - which parse_last_release_git.sh
   only:
     - branches
 
diff --git a/eossr/scripts/tests/test_scripts.py b/eossr/scripts/tests/test_scripts.py
index 316b254c..ead140b0 100644
--- a/eossr/scripts/tests/test_scripts.py
+++ b/eossr/scripts/tests/test_scripts.py
@@ -1,9 +1,27 @@
+# Various tests taken/based from
+# https://github.com/cta-observatory/cta-lstchain/blob/master/lstchain/scripts/tests/test_lstchain_scripts.py
+
+import pytest
 import subprocess
+import pkg_resources
 from os.path import dirname, realpath, join
 
 ROOT_DIR = dirname(realpath("codemeta.json"))
 
 
+def find_entry_points(package_name):
+    """from: https://stackoverflow.com/a/47383763/3838691"""
+    entrypoints = [
+        ep.name
+        for ep in pkg_resources.iter_entry_points("console_scripts")
+        if ep.module_name.startswith(package_name)
+    ]
+    return entrypoints
+
+
+ALL_SCRIPTS = find_entry_points("eossr")
+
+
 def run_script(*args):
     result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
 
@@ -16,3 +34,13 @@ def run_script(*args):
 
 def test_codemeta2zenodo():
     run_script("eossr-codemeta2zenodo", "-i", join(ROOT_DIR, "codemeta.json"))
+
+
+def test_parse_last_release_git_bash():
+    run_script("which", "parse_last_release_git.sh")
+
+
+@pytest.mark.parametrize("script", ALL_SCRIPTS)
+def test_help_all_scripts(script):
+    """Test for all scripts if at least the help works"""
+    run_script(script, "--help")
-- 
GitLab