Repository: git-big-picture/git-big-picture (language: python)

Issue:
Migrate from unmaintained Cram to maintained Scruf
Just an idea for consideration.

PS: Not sure why GitHub displays the rename as remove and add. Maybe more fun to review locally :thinking: 


Discussion / hints:

Fix patch:
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..91d92f5
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,27 @@
+# This file is part of git-big-picture
+#
+# Copyright (C) 2020 Sebastian Pipping <sebastian@pipping.org>
+#
+# git-big-picture is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# git-big-picture is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with git-big-picture.  If not, see <http://www.gnu.org/licenses/>.
+
+[run]
+branch = True
+concurrency = multiprocessing
+data_file = ./.coverage
+disable_warnings = no-data-collected
+omit =
+    ./setup.py
+    ./test.py
+    ./venv/*
+source = ./
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a2e3f51
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/htmlcov/
+/.coverage


Test patch:
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index bef0bce..ab36288 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -42,12 +42,8 @@ jobs:
       if: runner.os == 'macOS'
       run: |
         brew install graphviz
-    - name: Install build dependencies (Linux and macOS)
-      run: |
-        pip install -r test_requirements.txt
     - name: Run the test suite
       run: |
         git config --global user.email tests@git-big-picture.test
         git config --global user.name 'git-big-picture test suite'
-        ./test.py
-        PATH="${PATH}:${PWD}" ./test.scf
+        ./run-tests-with-coverage.sh
diff --git a/run-tests-with-coverage.sh b/run-tests-with-coverage.sh
new file mode 100755
index 0000000..32a8581
--- /dev/null
+++ b/run-tests-with-coverage.sh
@@ -0,0 +1,78 @@
+#! /usr/bin/env bash
+# This file is part of git-big-picture
+#
+# Copyright (C) 2020 Sebastian Pipping <sebastian@pipping.org>
+#
+# git-big-picture is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# git-big-picture is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with git-big-picture.  If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+# Constants
+venv=.coverage-venv
+source_dir="${PWD}"
+
+
+# Create a tempdir, jump into it, wipe its content on exit
+temp_dir="$(mktemp -d)"
+wipe_tempdir() {
+    rm -R "${temp_dir}"
+}
+trap wipe_tempdir EXIT
+cd "${temp_dir}"
+
+
+# NOTE: Collecting code coverage across subprocesses is a bit tricky in general,
+#       see https://coverage.readthedocs.io/en/coverage-5.1/api_coverage.html for background.
+#
+#       On top of that we are dealing with subprocesses here that have a different working directory
+#       than their parents and hence interpret relative paths in .coveragerc differently.
+#
+#       To deal with this problem, we (1) run the tests outside of the source directory and
+#       (2) use a dedicated virtualenv so that:
+#
+#        - We can tinker with file sitecustomize.py without worry of affecting any existing
+#          environments.
+#
+#        - We can create an copy of .coveragerc with absolute path on the fly so that all processes
+#          work with the same set of absolute paths, no matter their initial working directory,
+#          while still not hardcoding a specific temp directory.
+
+# Prepare a virtualenv ready to run tests with subprocess coverage
+python3 -m venv ${venv}
+source ${venv}/bin/activate
+pip install --quiet --disable-pip-version-check -r "${source_dir}"/test_requirements.txt
+sed "s,\./,${source_dir}/,g" "${source_dir}"/.coveragerc > .coveragerc
+cat <<SITECUSTOMIZE_PY_EOF > "$(ls -1d ${venv}/lib/python*)"/site-packages/sitecustomize.py
+try:
+    import coverage
+    coverage.process_startup()
+except ImportError:
+    pass
+SITECUSTOMIZE_PY_EOF
+
+
+# Actually run the tests
+exit_code=0
+coverage erase
+
+coverage run ${venv}/bin/nosetests "${source_dir}"/test.py \
+    || exit_code=$?
+PATH="${source_dir}:${PATH}" COVERAGE_PROCESS_START=.coveragerc \
+    coverage run ${venv}/bin/scruf "${source_dir}"/test.scf \
+    || exit_code=$?
+
+coverage combine
+coverage html -d "${source_dir}"/htmlcov/
+coverage report
+exit ${exit_code}
diff --git a/test_requirements.txt b/test_requirements.txt
index bbc5f28..37a3121 100644
--- a/test_requirements.txt
+++ b/test_requirements.txt
@@ -1,2 +1,3 @@
+coverage
 scruf
 nose