Repository: halluxdev/hallux (language: python)

Issue:
Increase unit-test coverage
query_backend.py -- WIP

DiffTarget tests: - Sergey - DONE
FileDiff - Sergey - DONE

Increase unit-test coverage
query_backend.py -- WIP

DiffTarget tests: - Sergey - DONE
FileDiff - Sergey - DONE

Increase unit-test coverage
query_backend.py -- WIP

DiffTarget tests: - Sergey - DONE
FileDiff - Sergey - DONE

Increase unit-test coverage
query_backend.py -- WIP

DiffTarget tests: - Sergey - DONE
FileDiff - Sergey - DONE



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/hallux.yml b/.github/workflows/hallux.yml
index a7354da..7f8b104 100644
--- a/.github/workflows/hallux.yml
+++ b/.github/workflows/hallux.yml
@@ -21,17 +21,20 @@ jobs:
       run: pip install --no-cache-dir -r requirements.txt
 
     - name: Unit-Tests
-      run: |        
+      run: |
         export PATH=$(pwd)/bin:$PATH
         export PYTHONPATH=$(pwd)/bin:${PYTHONPATH}
-        python -m pytest tests/unit 
+        python -m coverage run -m pytest tests/unit
+
+    - name: Fail if coverage is less than 80%
+      run: |
+        coverage report --fail-under=80
 
     - name: Integration Tests
       run: |
         export PATH=$(pwd)/bin:$PATH
         export PYTHONPATH=$(pwd)/bin:${PYTHONPATH}
-        python -m pytest tests/integration/hallux_fix_test.py 
-        
+        python -m pytest tests/integration/hallux_fix_test.py
 
 #    - name: Run Hallux
 #      run: python ./worker/main.py
diff --git a/requirements.txt b/requirements.txt
index eb9f6eb..5400c9d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ black==23.3.0
 openai==0.27.8
 pyyaml==6.0
 PyGithub==1.59
+coverage==7.2.7


Test patch:
diff --git a/tests/integration/hallux_commit_test.py b/tests/integration/hallux_commit_test.py
index 147b851..57e28e1 100644
--- a/tests/integration/hallux_commit_test.py
+++ b/tests/integration/hallux_commit_test.py
@@ -11,10 +11,10 @@
 import subprocess
 from code_processor import set_directory
 
-from integration.hallux_fix_test import test_hallux_fix
+from integration.hallux_fix_test import test_hallux_fix_python, test_hallux_fix_cpp
 
 
-def test_hallux_commit(proj_name: str = "test-project1", tmp_proj_dir: str | None = None):
+def test_hallux_commit_cpp(proj_name: str = "test-cpp-project", tmp_proj_dir: str | None = None):
     if tmp_proj_dir is None:
         if not Path("/tmp/hallux").exists():
             Path("/tmp/hallux").mkdir()
@@ -48,7 +48,7 @@ def test_hallux_commit(proj_name: str = "test-project1", tmp_proj_dir: str | Non
             len(git_log_output.split("\n")) == 1 + 1
         ), git_log_output  # we have exactly one commit in the repo (+1 empty line)
 
-    test_hallux_fix(proj_name, tmp_proj_dir, command="commit")
+    test_hallux_fix_cpp(proj_name, tmp_proj_dir, command="commit")
 
     with set_directory(Path(tmp_proj_dir)):
         try:
@@ -57,5 +57,52 @@ def test_hallux_commit(proj_name: str = "test-project1", tmp_proj_dir: str | Non
             pytest.fail(e, pytrace=True)  # Cannot call `git log`
 
         assert (
-            len(git_log_output.split("\n")) == 5 + 1
-        ), git_log_output  # we have exactly 5 commits in the repo (+1 empty line)
+            len(git_log_output.split("\n")) == 4 + 1
+        ), git_log_output  # we have exactly 4 commits in the repo (+1 empty line)
+
+
+def test_hallux_commit_python(proj_name: str = "test-python-project", tmp_proj_dir: str | None = None):
+    if tmp_proj_dir is None:
+        if not Path("/tmp/hallux").exists():
+            Path("/tmp/hallux").mkdir()
+        tmp_proj_dir = tempfile.mkdtemp(dir="/tmp/hallux")
+
+    with set_directory(Path(tmp_proj_dir)):
+        try:
+            subprocess.check_output(["git", "init"])
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # Cannot call `git init`
+
+        proj_dir = Path(__file__).resolve().parent.parent.joinpath(proj_name)
+        shutil.copytree(str(proj_dir), tmp_proj_dir, ignore_dangling_symlinks=False, dirs_exist_ok=True)
+        try:
+            subprocess.check_output(["git", "add", "*"])
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # Cannot call `git add *`
+
+        try:
+            subprocess.check_output(["git", "commit", "-m", "initial"])
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # Cannot call `git commit`
+
+        git_log_output: str = ""
+        try:
+            git_log_output = subprocess.check_output(["git", "log", "--pretty=oneline"]).decode("utf8")
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # Cannot call `git log`
+
+        assert (
+            len(git_log_output.split("\n")) == 1 + 1
+        ), git_log_output  # we have exactly one commit in the repo (+1 empty line)
+
+    test_hallux_fix_python(proj_name, tmp_proj_dir, command="commit")
+
+    with set_directory(Path(tmp_proj_dir)):
+        try:
+            git_log_output = subprocess.check_output(["git", "log", "--pretty=oneline"]).decode("utf8")
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # Cannot call `git log`
+
+        assert (
+            len(git_log_output.split("\n")) == 2 + 1
+        ), git_log_output  # we have exactly 2 commit in the repo (+1 empty line)
diff --git a/tests/integration/hallux_fix_test.py b/tests/integration/hallux_fix_test.py
index 61d6f7b..4ea5e9d 100644
--- a/tests/integration/hallux_fix_test.py
+++ b/tests/integration/hallux_fix_test.py
@@ -11,7 +11,7 @@
 from code_processor import set_directory
 
 
-def test_hallux_fix(proj_name: str = "test-project1", tmp_proj_dir: str | None = None, command: str = "fix"):
+def test_hallux_fix_cpp(proj_name: str = "test-cpp-project", tmp_proj_dir: str | None = None, command: str = "fix"):
     # Create temporal dir, if not already exists
     if tmp_proj_dir is None:
         if not Path("/tmp/hallux").exists():
@@ -24,16 +24,6 @@ def test_hallux_fix(proj_name: str = "test-project1", tmp_proj_dir: str | None =
     # copy reference project into temp folder
     shutil.copytree(str(proj_dir), tmp_proj_dir, ignore_dangling_symlinks=False, dirs_exist_ok=True)
 
-    # check that temporal project has ruff issues
-    with set_directory(Path(tmp_proj_dir)):
-        returncode: int = 0
-        try:
-            subprocess.check_output(["ruff", "check", "."])
-        except subprocess.CalledProcessError as e:
-            returncode = e.returncode
-
-        assert returncode != 0, f"Initial state of {proj_name} contains no ruff warnings"
-
     # temporal dir for cmake init
     cmake_tmp_dir = tempfile.mkdtemp(dir="/tmp/hallux")
 
@@ -46,7 +36,7 @@ def test_hallux_fix(proj_name: str = "test-project1", tmp_proj_dir: str | None =
 
         make_succesfull: bool = True
         try:
-            subprocess.check_output(["make", "cpp/test_cpp_project.o"])
+            subprocess.check_output(["make", "cpp/test_cpp_project.o"], stderr=subprocess.DEVNULL)
         except subprocess.CalledProcessError as e:
             make_succesfull = False
             returncode = e.returncode
@@ -61,15 +51,48 @@ def test_hallux_fix(proj_name: str = "test-project1", tmp_proj_dir: str | None =
         except subprocess.CalledProcessError as e:
             pytest.fail(e, pytrace=True)  # hallux must not fail ?
 
-        # ASSERT: ruff must have no remaining issues
+    # ASSERT: must be no remaining c++ compilation issues
+    with set_directory(Path(cmake_tmp_dir)):
+        try:
+            subprocess.check_output(["make", "cpp/test_cpp_project.o"], stderr=subprocess.DEVNULL)
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # make must not find any issues
+
+
+def test_hallux_fix_python(
+    proj_name: str = "test-python-project", tmp_proj_dir: str | None = None, command: str = "fix"
+):
+    # Create temporal dir, if not already exists
+    if tmp_proj_dir is None:
+        if not Path("/tmp/hallux").exists():
+            Path("/tmp/hallux").mkdir()
+        tmp_proj_dir = tempfile.mkdtemp(dir="/tmp/hallux")
+
+    # original/reference test-project directory
+    proj_dir = Path(__file__).resolve().parent.parent.joinpath(proj_name)
+
+    # copy reference project into temp folder
+    shutil.copytree(str(proj_dir), tmp_proj_dir, ignore_dangling_symlinks=False, dirs_exist_ok=True)
+
+    # check that temporal project has ruff issues
+    with set_directory(Path(tmp_proj_dir)):
+        returncode: int = 0
         try:
             subprocess.check_output(["ruff", "check", "."])
         except subprocess.CalledProcessError as e:
-            pytest.fail(e, pytrace=True)  # ruff must not find any issues
+            returncode = e.returncode
 
-    # ASSERT: must be no remaining c++ compilation issues
-    with set_directory(Path(cmake_tmp_dir)):
+        assert returncode != 0, f"Initial state of {proj_name} contains no ruff warnings"
+
+    # run hallux from the temporal project directory
+    with set_directory(Path(tmp_proj_dir)):
         try:
-            subprocess.check_output(["make", "cpp/test_cpp_project.o"])
+            subprocess.check_output(["hallux", command])
         except subprocess.CalledProcessError as e:
-            pytest.fail(e, pytrace=True)  # make must not find any issues
+            pytest.fail(e, pytrace=True)  # hallux must not fail ?
+
+        # ASSERT: ruff must have no remaining issues
+        try:
+            subprocess.check_output(["ruff", "check", "."])
+        except subprocess.CalledProcessError as e:
+            pytest.fail(e, pytrace=True)  # ruff must not find any issues
diff --git a/tests/test-project1/.hallux b/tests/test-cpp-project/.hallux
similarity index 74%
rename from tests/test-project1/.hallux
rename to tests/test-cpp-project/.hallux
index e3f15de..50c0020 100644
--- a/tests/test-project1/.hallux
+++ b/tests/test-cpp-project/.hallux
@@ -14,7 +14,4 @@ cpp:
     cmake: .
     compile: True
 
-python:
-    ruff: python # directory name to work with, may be just "."
-
 
diff --git a/tests/test-project1/CMakeLists.txt b/tests/test-cpp-project/CMakeLists.txt
similarity index 100%
rename from tests/test-project1/CMakeLists.txt
rename to tests/test-cpp-project/CMakeLists.txt
diff --git a/tests/test-project1/cpp/test_cpp_project.cpp b/tests/test-cpp-project/cpp/test_cpp_project.cpp
similarity index 100%
rename from tests/test-project1/cpp/test_cpp_project.cpp
rename to tests/test-cpp-project/cpp/test_cpp_project.cpp
diff --git a/tests/test-project1/dummy.json b/tests/test-cpp-project/dummy.json
similarity index 71%
rename from tests/test-project1/dummy.json
rename to tests/test-cpp-project/dummy.json
index 3978af9..1eabb9c 100644
--- a/tests/test-project1/dummy.json
+++ b/tests/test-cpp-project/dummy.json
@@ -14,15 +14,5 @@
         ]
       }
     }
-  },
-  "python":
-  {
-    "ruff":
-    {
-      "python/parse_cpp_tree_test.py": {
-        "E722 Do not use bare `except`": ["        try:\n            token1 = next(tokens1)\n            token2 = next(tokens2)\n        except StopIteration:\n            break\n\n\n@pytest.mark.parametrize("]
-      }
-
-    }
   }
-}
\ No newline at end of file
+}
diff --git a/tests/test-python-project/.hallux b/tests/test-python-project/.hallux
new file mode 100644
index 0000000..8b63faf
--- /dev/null
+++ b/tests/test-python-project/.hallux
@@ -0,0 +1,14 @@
+backend:
+    dummy: dummy.json
+
+#  openai:
+#      model: gpt-3.5-turbo
+#      max_tokens: 4097
+
+github:
+    github_token:
+
+python:
+    ruff: python # directory name to work with, may be just "."
+
+
diff --git a/tests/test-python-project/dummy.json b/tests/test-python-project/dummy.json
new file mode 100644
index 0000000..ed76c76
--- /dev/null
+++ b/tests/test-python-project/dummy.json
@@ -0,0 +1,11 @@
+{
+  "python": {
+    "ruff": {
+      "python/parse_cpp_tree_test.py": {
+        "E722 Do not use bare `except`": [
+          "        try:\n            token1 = next(tokens1)\n            token2 = next(tokens2)\n        except StopIteration:\n            break\n\n\n@pytest.mark.parametrize("
+        ]
+      }
+    }
+  }
+}
diff --git a/tests/test-project1/pyproject.toml b/tests/test-python-project/pyproject.toml
similarity index 100%
rename from tests/test-project1/pyproject.toml
rename to tests/test-python-project/pyproject.toml
diff --git a/tests/test-project1/python/parse_cpp_tree_test.py b/tests/test-python-project/python/parse_cpp_tree_test.py
similarity index 100%
rename from tests/test-project1/python/parse_cpp_tree_test.py
rename to tests/test-python-project/python/parse_cpp_tree_test.py