Repository: drvinceknight/nbchkr

Issue:
Clear up variable naming
In particular the following two conventions are currently being used:

- `nb_json`
- `nb_node`

Aim for `nb_node`.

Discussion:

Patch:
diff --git a/src/nbchkr/utils/__init__.py b/src/nbchkr/utils/__init__.py
index 67a65c1..9a8afba 100644
--- a/src/nbchkr/utils/__init__.py
+++ b/src/nbchkr/utils/__init__.py
@@ -27,7 +27,7 @@ def read(nb_path: pathlib.Path, as_version: int = 4) -> dict:
 
 
 def remove_cells(
-    nb_json, tags_regex_patterns_to_ignore=None, solution_regex=None
+    nb_node, tags_regex_patterns_to_ignore=None, solution_regex=None
 ):  # TODO Add typing to this function
     """
     Given a dictionary representation of a notebook, removes:
@@ -42,7 +42,7 @@ def remove_cells(
     if solution_regex is None:
         solution_regex = SOLUTION_REGEX
     cells = []
-    for cell in nb_json["cells"]:
+    for cell in nb_node["cells"]:
         if "tags" not in cell["metadata"] or all(
             not bool(re.match(pattern=pattern, string=tag))
             for tag in cell["metadata"]["tags"]
@@ -61,21 +61,21 @@ def remove_cells(
             except KeyError:  # pragma: no cover
                 pass  # TODO Add test coverage for this statement
             cells.append(cell)
-    nb_json["cells"] = cells
-    return nb_json
+    nb_node["cells"] = cells
+    return nb_node
 
 
-def write(output_path: pathlib.Path, nb_json):
+def write(output_path: pathlib.Path, nb_node: dict):
     """
     Write the python dict representation of a notebook to `output_path`.
     """
-    output_path.write_text(json.dumps(nb_json))
+    output_path.write_text(json.dumps(nb_node))
 
 
-def add_checks(nb_json: dict, source_nb_json: dict, answer_tag_regex=None) -> dict:
+def add_checks(nb_node: dict, source_nb_node: dict, answer_tag_regex=None) -> dict:
     """
-    Given a `nb_json` and a source `source_nb_json`, add the cells in
-    `source_nb` with tags matching `answer_tag_regex` to `source_nb_json`
+    Given a `nb_node` and a source `source_nb_node`, add the cells in
+    `source_nb` with tags matching `answer_tag_regex` to `source_nb_node`
 
     This is used to add a student's answers to the source notebook.
     """
@@ -83,15 +83,15 @@ def add_checks(nb_json: dict, source_nb_json: dict, answer_tag_regex=None) -> di
         answer_tag_regex = ANSWER_TAG_REGEX
     answers = {
         tag: cell
-        for cell in nb_json["cells"]
+        for cell in nb_node["cells"]
         for tag in cell["metadata"].get("tags", [])
         if bool(re.match(pattern=answer_tag_regex, string=tag))
     }
-    for i, cell in enumerate(source_nb_json["cells"]):
+    for i, cell in enumerate(source_nb_node["cells"]):
         for tag in cell["metadata"].get("tags", []):
             if tag in answers:
-                source_nb_json["cells"][i] = answers[tag]
-    return source_nb_json
+                source_nb_node["cells"][i] = answers[tag]
+    return source_nb_node
 
 
 def get_tags(cell: dict, tag_seperator: str = "|") -> Optional[str]:


Test patch:
diff --git a/tests/test_check.py b/tests/test_check.py
index 94c9006..ebef0b3 100644
--- a/tests/test_check.py
+++ b/tests/test_check.py
@@ -20,16 +20,16 @@ def test_read_nb_gives_dictionary():
 
 
 def test_add_checks_creates_notebook_with_assertions():
-    nb_json = nbchkr.utils.read(nb_path=NB_PATH / "submission.ipynb")
-    source_nb_json = nbchkr.utils.read(nb_path=NB_PATH / "test.ipynb")
+    nb_node = nbchkr.utils.read(nb_path=NB_PATH / "submission.ipynb")
+    source_nb_node = nbchkr.utils.read(nb_path=NB_PATH / "test.ipynb")
     nb_with_checks = nbchkr.utils.add_checks(
-        nb_json=nb_json, source_nb_json=source_nb_json
+        nb_node=nb_node, source_nb_node=source_nb_node
     )
     assert "assert _ == 55" in str(nb_with_checks)
     assert "sum(i for i in range(10))" in str(nb_with_checks)
 
     output_path = NB_PATH / "feedback.ipynb"
-    nbchkr.utils.write(output_path=output_path, nb_json=nb_with_checks)
+    nbchkr.utils.write(output_path=output_path, nb_node=nb_with_checks)
 
 
 def test_check_with_no_errors_for_original_source():
@@ -65,7 +65,7 @@ Assertion passed:
 def test_check_with_no_errors_for_test_submission():
     nb_node = nbchkr.utils.read(nb_path=NB_PATH / "submission.ipynb")
     source_nb_node = nbchkr.utils.read(nb_path=NB_PATH / "test.ipynb")
-    nb_node = nbchkr.utils.add_checks(nb_json=nb_node, source_nb_json=source_nb_node)
+    nb_node = nbchkr.utils.add_checks(nb_node=nb_node, source_nb_node=source_nb_node)
     score, maximum_score, feedback = nbchkr.utils.check(nb_node=nb_node)
     expected_score = 2
     expected_maximum_score = 10
diff --git a/tests/test_release.py b/tests/test_release.py
index bf5feb6..79b04d9 100644
--- a/tests/test_release.py
+++ b/tests/test_release.py
@@ -46,33 +46,33 @@ def test_read_nb_cells_gives_list():
 
 def test_remove_cells():
     nb_path = NB_PATH / "test.ipynb"
-    nb_json = nbchkr.utils.read(nb_path=nb_path)
-    student_nb = nbchkr.utils.remove_cells(nb_json=nb_json)
+    nb_node = nbchkr.utils.read(nb_path=nb_path)
+    student_nb = nbchkr.utils.remove_cells(nb_node=nb_node)
     expected_length = 4
     assert type(student_nb["cells"]) is list
     assert len(student_nb["cells"]) == expected_length
 
 
-def test_remove_solution_and_keep_original_nb_json_unchanged():
+def test_remove_solution_and_keep_original_nb_node_unchanged():
     """
     This checks that solutions text is not included.
 
-    Note that, as implemented both `nb_json` and `student_nb` are modified. This
+    Note that, as implemented both `nb_node` and `student_nb` are modified. This
     should be fixed. TODO When fixed remove this line of documentation.
     """
     nb_path = NB_PATH / "test.ipynb"
-    nb_json = nbchkr.utils.read(nb_path=nb_path)
-    assert "sum(i for i in range(11))" in str(nb_json)
-    assert "sum(i for i in range(n + 1))" in str(nb_json)
-    assert "55" in str(nb_json)
+    nb_node = nbchkr.utils.read(nb_path=nb_path)
+    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)
 
-    student_nb = nbchkr.utils.remove_cells(nb_json=nb_json)
+    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)
     # 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_json)
+    assert "sum(i for i in range(n + 1))" not in str(nb_node)
 
 
 def test_write_nb():
@@ -83,9 +83,9 @@ def test_write_nb():
     except FileNotFoundError:  # TODO Ensure py3.8 is used so that can pass
         # `missing_ok=True` to `path.unlink`.
         pass
-    nb_json = nbchkr.utils.read(nb_path=nb_path)
-    student_nb = nbchkr.utils.remove_cells(nb_json=nb_json)
-    nbchkr.utils.write(output_path=output_path, nb_json=student_nb)
+    nb_node = nbchkr.utils.read(nb_path=nb_path)
+    student_nb = nbchkr.utils.remove_cells(nb_node=nb_node)
+    nbchkr.utils.write(output_path=output_path, nb_node=student_nb)
 
     student_nb = nbchkr.utils.read(nb_path=output_path)
     assert "sum(i for i in range(11))" not in str(student_nb)