Repository: drvinceknight/nbchkr

Issue:
Fix the regex for solutions here.
Currently the default is to have: 

```
### BEGIN SOLUTION

### END SOLUTION
```

The regex finds that but removes the markers which would be nicer to leave in.

Comments:

Patch:
diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml
index bc1675a..4209e6e 100644
--- a/.github/workflows/config.yml
+++ b/.github/workflows/config.yml
@@ -21,30 +21,42 @@ jobs:
     - name: Update pip
       run: |
         python -m pip install --upgrade pip
-    - name: Check format (only on py3.8 and ubuntu)
+    - name: Install black (only on py3.8 and ubuntu)
       if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
       run: |
         python -m pip install black
+    - name: Check format (only on py3.8 and ubuntu)
+      if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
+      run: |
         python -m black . --check
-    - name: Check format of imports (only on py3.8 and ubuntu)
+    - name: Install isort (only on py3.8 and ubuntu)
       if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
       run: |
         python -m pip install isort
+    - name: Check format of imports (only on py3.8 and ubuntu)
+      if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
+      run: |
         python -m isort --check-only src/nbchkr/.
-    - name: Test with pytest
+    - name: Installing testing dependencies
       run: |
-        python setup.py develop
         python -m pip install pytest
         python -m pip install pytest-cov
         python -m pip install pytest-flake8
         python -m pip install pytest-randomly
         python -m pip install pytest-sugar
+    - name: Test with pytest
+      run: |
+        python setup.py develop
         python -m pytest -v --cov=nbchkr --cov-fail-under=100 --flake8
-    - name: Interrogate docstrings to check docstring coverage
+    - name: Install interrogate
       run: |
         python -m pip install interrogate
+    - name: Interrogate docstrings to check docstring coverage
+      run: |
         interrogate -e setup.py -e tests/ -M -i -v -f 100 .
-    - name: Check static typing
+    - name: Install mypy
       run: |
         python -m pip install mypy
+    - name: Check static typing
+      run: |
         python -m mypy src/ --pretty
diff --git a/src/nbchkr/utils/__init__.py b/src/nbchkr/utils/__init__.py
index 691ded3..d191c2c 100644
--- a/src/nbchkr/utils/__init__.py
+++ b/src/nbchkr/utils/__init__.py
@@ -11,6 +11,10 @@ TAGS_REGEX_PATTERNS_TO_IGNORE = ["hide", r"score:\d"]
 SOLUTION_REGEX = re.compile(
     r"### BEGIN SOLUTION[\s\S](.*?)[\s\S]### END SOLUTION", re.DOTALL
 )
+SOLUTION_REPL = """### BEGIN SOLUTION
+
+
+### END SOLUTION"""
 UNIVERSAL_REGEX = re.compile(r".", re.DOTALL)
 ANSWER_TAG_REGEX = r"answer:*"
 SCORE_REGEX = re.compile(r"score:(\d+)")
@@ -28,7 +32,7 @@ def read(nb_path: pathlib.Path, as_version: int = 4) -> dict:
 
 
 def remove_cells(
-    nb_node, tags_regex_patterns_to_ignore=None, solution_regex=None
+    nb_node, tags_regex_patterns_to_ignore=None, solution_regex=None, solution_repl=None
 ):  # TODO Add typing to this function
     """
     Given a dictionary representation of a notebook, removes:
@@ -42,6 +46,8 @@ def remove_cells(
         tags_regex_patterns_to_ignore = TAGS_REGEX_PATTERNS_TO_IGNORE
     if solution_regex is None:
         solution_regex = SOLUTION_REGEX
+    if solution_repl is None:
+        solution_repl = SOLUTION_REPL
     cells = []
     for cell in nb_node["cells"]:
         if "tags" not in cell["metadata"] or all(
@@ -51,7 +57,9 @@ def remove_cells(
         ):
             try:
                 source = "".join(cell["source"])
-                new_source = re.sub(pattern=solution_regex, repl="", string=source)
+                new_source = re.sub(
+                    pattern=solution_regex, repl=solution_repl, string=source
+                )
                 cell["source"] = new_source
 
                 if bool(re.match(pattern=solution_regex, string=source)) is True:


Test patch:
diff --git a/tests/test_release.py b/tests/test_release.py
index 79b04d9..7f080f2 100644
--- a/tests/test_release.py
+++ b/tests/test_release.py
@@ -65,11 +65,15 @@ def test_remove_solution_and_keep_original_nb_node_unchanged():
     assert "sum(i for i in range(11))" in str(nb_node)
     assert "sum(i for i in range(n + 1))" in str(nb_node)
     assert "55" in str(nb_node)
+    assert "### BEGIN SOLUTION" in str(nb_node)
+    assert "### END SOLUTION" in str(nb_node)
 
     student_nb = nbchkr.utils.remove_cells(nb_node=nb_node)
     assert "sum(i for i in range(11))" not in str(student_nb)
     assert "sum(i for i in range(n + 1))" not in str(student_nb)
     assert "55" not in str(student_nb)
+    assert "BEGIN SOLUTION" in str(student_nb)
+    assert "END SOLUTION" in str(student_nb)
     # TODO Add test that shows wrong behaviour of changing the imported JSON
     # and document.
     assert "sum(i for i in range(n + 1))" not in str(nb_node)