Skip to content

Commit

Permalink
test: reorganize pytest testing (mult. OSes & Python versions)
Browse files Browse the repository at this point in the history
The logic of pytest tests was edited; now it is based on iterating
lists of tuples.  Eventually, the edits allow to test the script
on multiple operating systems ("runner images" in GitHub's parlance)
vs either Python 3.10, or Python 3.12.

Signed-off-by: Norwid Behrnd <[email protected]>
  • Loading branch information
nbehrnd committed Nov 11, 2024
2 parents 06a1a8a + a381ada commit 6bf9bee
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 430 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI_pytest_datawarrior_saturate_murcko_scaffolds
# name : pytest.yml
# purpose : regularly run pytest on the saturator script
# date : [2024-03-21 Thu]
# edit : [2024-03-27 Wed]
# edit : [2024-11-11 Mon]

on:
push:
Expand All @@ -17,27 +17,31 @@ on:
- cron: "0 0 1 * *" # once each 1st of a month, at 00:00 UTC (cf. https://crontab.guru/)

jobs:
linux-static:
runs-on: ubuntu-latest
timeout-minutes: 2
test:
strategy:
matrix:
# for a factorial test, an explicit selection of GitHUb runner images
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
# state of commit 23478d3 as visited on 2024-11-11 Mon
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-2019, windows-2022, macos-14]
python-version: ["3.10", "3.12"]
runs-on: ${{ matrix.os }}

timeout-minutes: 3 # Timeout for each job individually

steps:
- name: Check number of cores
run: |
lscpu
lscpu | grep "CPU(s): " | awk '{print $2}' > num_cores
echo "NUM_CORES=$(cat num_cores)" >> $GITHUB_ENV
- uses: actions/checkout@v4
# by [2024-10-23 Wed], this version possibly will be considered "old", cf.
# https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/

- uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: ${{ matrix.python-version }}

- name: Install dependencies with PyPI
run: pip install pytest

- name: run the check by pytest
- name: Run the check with pytest
run: python -m pytest


73 changes: 42 additions & 31 deletions saturate_murcko_scaffolds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# name: saturate_murcko_scaffolds.py
# author: [email protected]
# date: [2019-06-07 Fri]
# edit: <2023-05-23 Wed>
# edit: [2024-11-11 Mon]
#
"""Read Smiles of Murcko scaffolds and return these as 'saturated'.
Expand Down Expand Up @@ -36,7 +36,7 @@
http://www.openmolecules.org, https://github.com/thsa/datawarrior
[3] https://en.wikipedia.org/wiki/Benomyl
License: Norwid Behrnd, 2019--2023, GPLv3.
License: Norwid Behrnd, 2019--2024, GPLv3.
"""
import argparse
import io
Expand All @@ -62,24 +62,17 @@ def get_args():
)

parser.add_argument(
"text",
type=str,
help="process a single SMILES from the CLI, or access an input file")
"inputs",
nargs="+",
help="provide one or multiple SMILES from the CLI, or an input text file listing SMILES")

parser.add_argument(
"-o",
"--outfile",
help="output file name, else results are reported back to the CLI",
metavar="",
default="",
)

args = parser.parse_args()

if os.path.isfile(args.text):
args.text = open(file=args.text, mode="rt", encoding="utf-8")
else:
args.text = io.StringIO(args.text + "\n")
# if os.path.isfile(args.text):
# args.text = open(file=args.text, mode="rt", encoding="utf-8")
# else:
# args.text = io.StringIO(args.text + "\n")

return args

Expand Down Expand Up @@ -221,25 +214,43 @@ def write_record(input_file, listing):
sys.exit()


def process_smiles(smiles):
"""sequentially pass a SMILES string to reduction"""
only_single_bonds = saturator(smiles)
on_carbon = saturate_carbon(only_single_bonds)
on_nitrogen = saturate_nitrogen(on_carbon)
on_oxygen = saturate_oxygen(on_nitrogen)
on_phosphorus = saturate_phosphorus(on_oxygen)
on_sulfur = saturate_sulfur(on_phosphorus)
result = on_sulfur

print(f"{result}")


def process_input_files(input_files):
"""sequentially process input files with lists of SMILES strings"""
for file in input_files:
try:
with open (file, mode="r", encoding="utf-8") as source:
for line in source:
smiles = str(line).strip()
process_smiles(smiles)
except:
print(f"file {file} is not accessible")


def main():
"""Join the functions."""
args = get_args()

output = (
open(args.outfile, mode="wt", encoding="utf-8") if args.outfile else sys.stdout
)
for line in args.text:
raw_data = str(line).strip()

only_single_bonds = saturate_bonds(raw_data)
on_carbon = saturate_carbon(only_single_bonds)
on_nitrogen = saturate_nitrogen(on_carbon)
on_oxygen = saturate_oxygen(on_nitrogen)
on_phosphorus = saturate_phosphorus(on_oxygen)
on_sulfur = saturate_sulfur(on_phosphorus)

result = on_sulfur
output.write(result + "\n")
smiles_strings = [arg for arg in args.inputs if not os.path.isfile(arg)]
if smiles_strings:
for smiles in smiles_strings:
process_smiles(smiles)

input_files = [arg for arg in args.inputs if os.path.isfile(arg)]
if input_files:
process_input_files(input_files)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 6bf9bee

Please sign in to comment.