Repository: dayyass/graph-based-clustering (language: python)

Issue:
add coverage



Discussion / hints:

Fix patch:
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..08f970c
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,14 @@
+[run]
+branch = True
+source = graph_clustering
+
+[report]
+exclude_lines =
+    pragma: no cover
+    if self\.debug
+    raise AssertionError
+    raise NotImplementedError
+    if __name__ == .__main__.:
+
+show_missing = True
+ignore_errors = False
diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml
new file mode 100644
index 0000000..f388704
--- /dev/null
+++ b/.github/workflows/codecov.yml
@@ -0,0 +1,38 @@
+# This workflow will install Python dependencies and run codecov
+# https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action
+
+name: codecov
+
+on:
+  push:
+    branches: [main, develop]
+  pull_request:
+    branches: [main, develop]
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-latest]
+    steps:
+    - uses: actions/checkout@master
+    - name: Set up Python
+      uses: actions/setup-python@master
+      with:
+        python-version: 3.7
+    - name: Install dependencies
+      run: |
+        pip install --upgrade pip
+        pip install -r requirements.txt
+        pip install pytest pytest-cov
+    - name: Generate coverage report
+      run: |
+        pytest --cov=./ --cov-report=xml
+    - name: Upload coverage to Codecov
+      uses: codecov/codecov-action@v1
+      with:
+        flags: unittests
+        env_vars: OS,PYTHON
+        fail_ci_if_error: true
+        verbose: true
diff --git a/requirements.txt b/requirements.txt
index 0339674..3191c2d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
+coverage==5.5
 jupyter==1.0.0
 matplotlib==3.4.3
 numpy==1.21.2


Test patch:
diff --git a/tests/test_graph_clustering.py b/tests/test_graph_clustering.py
index 3625993..1bb5bcd 100644
--- a/tests/test_graph_clustering.py
+++ b/tests/test_graph_clustering.py
@@ -5,7 +5,13 @@
 from sklearn.metrics import rand_score
 from sklearn.preprocessing import StandardScaler
 
-from graph_clustering.check import check_adjacency_matrix, check_symmetric
+from graph_clustering.check import (
+    _check_matrix,
+    _check_matrix_is_square,
+    _check_square_matrix_is_symmetric,
+    check_adjacency_matrix,
+    check_symmetric,
+)
 from graph_clustering.main import (
     ConnectedComponentsClustering,
     SpanTreeConnectedComponentsClustering,
@@ -14,9 +20,14 @@
 
 from .utils import prepare_sklearn_clustering_datasets
 
+np.random.seed(0)
+
 
 class TestCheck(unittest.TestCase):
 
+    # diag matrix - graph with loops
+    diag_matrix = np.eye(3)
+
     X = np.array([[0, 1], [1, 0], [1, 1]])
 
     distances = _pairwise_distances(X)
@@ -26,12 +37,36 @@ class TestCheck(unittest.TestCase):
         threshold=1.25,
     )
 
+    def test_basic_checks(self):
+        # _check_matrix
+        a = np.random.randn(1, 2, 3)
+        self.assertFalse(_check_matrix(a))
+        self.assertFalse(check_symmetric(a))
+
+        # _check_matrix_is_square
+        a = np.random.randn(2, 3)
+        self.assertFalse(_check_matrix_is_square(a))
+        self.assertFalse(check_symmetric(a))
+
+        # _check_square_matrix_is_symmetric
+        a = np.random.randn(2, 2)
+        self.assertFalse(_check_square_matrix_is_symmetric(a))
+        self.assertFalse(check_symmetric(a))
+
     def test_check_symmetric(self):
+        # diag matrix
+        self.assertTrue(check_symmetric(self.diag_matrix))
+
+        # X
         self.assertFalse(check_symmetric(self.X))
         self.assertTrue(check_symmetric(self.distances))
         self.assertTrue(check_symmetric(self.adjacency_matrix))
 
     def test_check_adjacency_matrix(self):
+        # diag matrix
+        self.assertFalse(check_adjacency_matrix(self.diag_matrix))
+
+        # X
         self.assertFalse(check_adjacency_matrix(self.X))
         self.assertFalse(check_adjacency_matrix(self.distances))
         self.assertTrue(check_adjacency_matrix(self.adjacency_matrix))