Skip to content

Commit 98d3d5d

Browse files
committed
refactor: edit doc strings, names used, type hints
For easier maintenance, the internal documentation was revised. Signed-off-by: Norwid Behrnd <nbehrnd@yahoo.com>
2 parents 469a412 + 67f734e commit 98d3d5d

File tree

6 files changed

+57
-35
lines changed

6 files changed

+57
-35
lines changed

.github/workflows/build_wheel.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: CI_wheel_datawarrior_clustersort
22

33
# name: build_wheel.yml
44
# purpose: build a .whl as an artifact without a secret/GitHub token
5-
# date: [2025-07-31 Thus]
6-
# edit:
5+
# date: [2025-07-31 Thu]
6+
# edit: [2025-08-01 Fri]
77

88
on:
99
workflow_dispatch: # launch only by the manual trigger
@@ -33,10 +33,10 @@ jobs:
3333
pip install build
3434
python -m build
3535
36-
- name: delivery within an archive `pubchem_wheel.zip`
36+
- name: package archive `datawarrior_clustersort_wheel.zip`
3737
uses: actions/upload-artifact@v4
3838
with:
39-
name: datawarrior_saturate_Murcko_scaffolds_wheel
39+
name: datawarrior_clustersort_wheel
4040
path: |
4141
dist/*.whl
4242
dist/*.tar.gz

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Local analysis by pytest, coverage run pytest, flake8, and badge generation.
22
#
33
# This Makefile presumes an activated virtual environment of Python and an
4-
# internet connection for pytest's checks on pubchempy's interaction with NIH.
4+
# internet connection to resolve the dependencies (rule `analysis_setup`).
55
# In contast to e.g., the coverage badge by coveralls, the setup here does not
66
# rely on a separate account, nor a GitHub token to work. By flag `-l`, the
77
# badges are created locally, independent of genbadge's default to reach out
@@ -11,7 +11,6 @@ default:
1111
@echo "Tap the tabulator key twice to display the options available."
1212

1313
analysis_setup:
14-
# For now, the partial overlap with `requirements/dev.txt` is intentional.
1514
pip install coverage flake8 genbadge[all] pyclean pytest
1615

1716
coverage_analysis:

coverage-badge.svg

Lines changed: 4 additions & 4 deletions
Loading

src/datawarrior_clustersort/datawarrior_clustersort.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# author: nbehrnd@yahoo.com
77
# license: GPL v2, 2022, 2023
88
# date: [2022-04-22 Fri]
9-
# edit: [2025-07-31 Thu]
9+
# edit: [2025-08-01 Fri]
1010
"""Provide a sort on DataWarrior clusters by popularity of the cluster.
1111
1212
DataWarrior can recognize structure similarity in a set of molecules. The
@@ -269,5 +269,5 @@ def main(arg_list=None) -> None:
269269
read_dw_list(report_list, old_cluster_label)
270270

271271

272-
if __name__ == "__main__":
272+
if __name__ == "__main__": # pragma: no cover
273273
main()

tests/test_blackbox.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# author: nbehrnd@yahoo.com
77
# license: GPL v2, 2025
88
# date: [2025-03-19 Wed]
9-
# edit: [2025-07-31 Thu]
9+
# edit: [2025-08-01 Fri]
1010

1111
"""External pytest checks by pytest on datawarrior_clustersort.py.
1212
@@ -29,17 +29,14 @@
2929
REFERENCE_REVERSE_SORT = "tests/100Random_Molecules_rev_sort_ref.txt"
3030

3131

32-
def test_script_exists():
33-
"""check for the script's presence"""
32+
def test_script_exists() -> None:
33+
"""Check for the script's presence."""
3434
assert os.path.isfile(PRG), f"script {PRG} was not found"
3535

3636

37-
# section of black-box tests (the inner working doesn't matter):
38-
39-
4037
@pytest.mark.blackbox
41-
def test_get_test_data():
42-
"""get a copy of the test's input data"""
38+
def test_get_test_data() -> None:
39+
"""Check copy/paste of test input data to the script."""
4340
source = os.path.join("tests", INPUT_FILE)
4441
target = os.path.join(os.getcwd(), INPUT_FILE)
4542

@@ -54,10 +51,16 @@ def test_get_test_data():
5451
except OSError as e:
5552
print(f"failed to copy '{INPUT_FILE}' for the test; {e}")
5653

54+
assert os.path.isfile(INPUT_FILE)
55+
5756

5857
@pytest.mark.blackbox
59-
def test_default_sort():
60-
"""check the results of the normal sort"""
58+
def test_default_sort() -> None:
59+
"""Check the results of the normal sort.
60+
61+
By this logic, label `1` is assigned to the cluster containing the
62+
most structures. Any cluster label higher than `1` is about a subsequent
63+
cluster with equal or less structures."""
6164
if os.path.exists(OUTPUT_FILE):
6265
try:
6366
os.remove(OUTPUT_FILE)
@@ -77,8 +80,12 @@ def test_default_sort():
7780

7881

7982
@pytest.mark.blackbox
80-
def test_reverse_sort():
81-
"""check the results of the normal sort"""
83+
def test_reverse_sort() -> None:
84+
"""Check the results of the reversed sort.
85+
86+
By this logic, label `1` is for the cluster with the lowest number of
87+
structures. The higher the label (`2`, `3`, etc.), either the same, or
88+
a higher number of structures are in this particular cluster."""
8289
if os.path.exists(OUTPUT_FILE):
8390
try:
8491
os.remove(OUTPUT_FILE)
@@ -98,8 +105,8 @@ def test_reverse_sort():
98105

99106

100107
@pytest.mark.blackbox
101-
def test_space_cleaning():
102-
"""remove copy of the input file"""
108+
def test_space_cleaning() -> None:
109+
"""Check the removal of the local copy of the input file."""
103110
if os.path.exists(INPUT_FILE):
104111
try:
105112
os.remove(INPUT_FILE)

tests/test_with_imports.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# author: nbehrnd@yahoo.com
77
# license: GPL v2, 2025
88
# date: [2025-03-19 Wed]
9-
# edit: [2025-04-17 Thu]
9+
# edit: [2025-08-01 Fri]
1010

1111
"""pytest script of datawarrior_clustersort.py
1212
@@ -29,7 +29,8 @@
2929

3030

3131
@pytest.mark.imported
32-
def test_file_reader():
32+
def test_file_reader() -> None:
33+
"""Check recognizing headline, table body, DW's lowest cluster label."""
3334
probe_data = r"""Structure [idcode] Cluster No Is Representative record_number
3435
edR\FD@KFncOLbji`HbHHrJIJYKJYSQRJiSIQITLRJ@pp@@DtuKMMP@@PARBj@ 1 No 1
3536
elRRF@@DLCH`FMLfilbbRbrTVtTTRbtqbRRJzAQZijfhHbbZBA@@@@ 2 No 2
@@ -50,16 +51,21 @@ def test_file_reader():
5051

5152

5253
@pytest.mark.imported
53-
def test_identify_cluster_column():
54-
"""identification of the cluster column"""
54+
def test_identify_cluster_column() -> None:
55+
"""Check identification of the cluster column."""
5556
input_string = "Structure [idcode] Cluster No Is Representative record_number"
5657
expected_column = 1
5758
test_column = identify_cluster_column(input_string)
5859
assert test_column == expected_column, "wrong column index"
5960

6061

6162
@pytest.mark.imported
62-
def test_read_dw_list():
63+
def test_read_dw_list() -> None:
64+
"""Perform a frequency analysis on DW assigned cluster labels.
65+
66+
This checks if DW assigned cluster labels are used to build a
67+
dictionary where DW labels indicate (as key) to the number of
68+
times they are assigned by DW (as value)."""
6369
# some records of DW cluster 1, 5, and 8 of `100Random_Molecules.txt`
6470
mock_table_body = [
6571
r"fko`H@D@yHsQ{OdTRbbbtRLLRTvRfoEjuTuUTAAUSPSBiAKL@@ 1 No 6",
@@ -83,7 +89,11 @@ def test_read_dw_list():
8389

8490

8591
@pytest.mark.imported
86-
def test_label_sorter_default_sort():
92+
def test_label_sorter_default_sort() -> None:
93+
"""Check the normal sort of a new frequency dictionary.
94+
95+
By default, the lowest key (label) describes the cluster with the
96+
most structures (value)."""
8797
mock_dictionary = {"1": 4, "5": 3, "8": 2}
8898
reversed_order = False
8999
expected_dictionary = {"1": 1, "5": 2, "8": 3}
@@ -92,7 +102,11 @@ def test_label_sorter_default_sort():
92102

93103

94104
@pytest.mark.imported
95-
def test_label_sorter_reverse_sort():
105+
def test_label_sorter_reverse_sort() -> None:
106+
"""Check the reverse sort of a new frequency dictionary.
107+
108+
By default, the lowest key (label) describes the cluster with the
109+
least number of structures (value)."""
96110
mock_dictionary = {"1": 4, "5": 3, "8": 2}
97111
reversed_order = True
98112
expected_dictionary = {"1": 3, "5": 2, "8": 1}
@@ -101,7 +115,8 @@ def test_label_sorter_reverse_sort():
101115

102116

103117
@pytest.mark.imported
104-
def test_update_cluster_labels():
118+
def test_update_cluster_labels() -> None:
119+
"""Check the reassignment of cluster labels."""
105120
# some of DW clusters 1, 5, and 8
106121
mock_table_body = [
107122
r"fko`H@D@yHsQ{OdTRbbbtRLLRTvRfoEjuTuUTAAUSPSBiAKL@@ 1 No 6",
@@ -134,7 +149,8 @@ def test_update_cluster_labels():
134149

135150

136151
@pytest.mark.imported
137-
def test_permanent_report(tmp_path):
152+
def test_permanent_report(tmp_path) -> None:
153+
"""Probe the generation of a permanent record."""
138154
# prepare data to write
139155
input_file = "test_input.txt"
140156
headline = "Structure [idcode] Cluster No Is Representative record_number"

0 commit comments

Comments
 (0)