From 76bd0f7c2be3c243f298f4452fd6660bf1e42af1 Mon Sep 17 00:00:00 2001 From: Oleksii Leonov Date: Thu, 23 Mar 2023 16:20:47 +0000 Subject: [PATCH 1/2] chore: apply isort to all files in project --- setup.py | 1 + tests/cgu/test_convert.py | 14 ++++++----- tests/cgu/test_discgraph.py | 5 ++-- tests/cgu/test_iron.py | 2 +- tests/cgu/test_syngraph.py | 13 +++++++---- tests/cgu/test_translate.py | 23 ++++++++++-------- tests/cheminfo/test_atom_mapping.py | 15 ++++++++---- tests/cheminfo/test_chemical_similarity.py | 9 ++++---- tests/cheminfo/test_constructors.py | 25 ++++++++++++-------- tests/cheminfo/test_functions.py | 27 ++++++++++++++++------ tests/conftest.py | 1 + tests/interfaces/test_cli.py | 2 +- tests/interfaces/test_facade.py | 13 ++++++----- tests/interfaces/test_workflows.py | 7 +++--- tests/io/test_io_functions.py | 1 + tests/rem/test_clustering.py | 8 +++++-- tests/rem/test_graph_distance.py | 22 +++++++++++------- tests/rem/test_node_metrics.py | 5 ++-- tests/rem/test_route_descriptors.py | 16 +++++++++---- tests/rem/test_route_scoring.py | 7 +++--- 20 files changed, 139 insertions(+), 77 deletions(-) diff --git a/setup.py b/setup.py index 8bf1ba9..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,3 @@ from setuptools import setup + setup() diff --git a/tests/cgu/test_convert.py b/tests/cgu/test_convert.py index 7691d64..deedd08 100644 --- a/tests/cgu/test_convert.py +++ b/tests/cgu/test_convert.py @@ -1,11 +1,13 @@ -from linchemin.cgu.convert import converter -from linchemin.cgu.translate import translator -from linchemin.cgu.syngraph import (SynGraph, BipartiteSynGraph, MonopartiteReacSynGraph) - -import pytest import json -from pathlib import Path import os +from pathlib import Path + +import pytest + +from linchemin.cgu.convert import converter +from linchemin.cgu.syngraph import (BipartiteSynGraph, MonopartiteReacSynGraph, + SynGraph) +from linchemin.cgu.translate import translator def test_strategy_structure(ibm1_path): diff --git a/tests/cgu/test_discgraph.py b/tests/cgu/test_discgraph.py index 99fee61..2cfe6e1 100644 --- a/tests/cgu/test_discgraph.py +++ b/tests/cgu/test_discgraph.py @@ -1,7 +1,8 @@ +import pytest + from linchemin.cgu.discgraph import DisconnectionGraph, MissingAtomMapping -from linchemin.cheminfo.constructors import ChemicalEquationConstructor from linchemin.cgu.syngraph import MonopartiteReacSynGraph -import pytest +from linchemin.cheminfo.constructors import ChemicalEquationConstructor mapped_reactions = {'r1': 'CN(C)C=O.F[c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11].O=C([O-])[O-].[CH3:1][CH:2]([CH3:3])[' 'SH:4].[K+].[K+]>>[CH3:1][CH:2]([CH3:3])[S:4][c:5]1[n:6][cH:7][cH:8][cH:9][c:10]1[F:11]'} diff --git a/tests/cgu/test_iron.py b/tests/cgu/test_iron.py index 0648f83..70f80cf 100644 --- a/tests/cgu/test_iron.py +++ b/tests/cgu/test_iron.py @@ -1,4 +1,4 @@ -from linchemin.cgu.iron import Node, Edge, Direction, Iron +from linchemin.cgu.iron import Direction, Edge, Iron, Node def test_direction(): diff --git a/tests/cgu/test_syngraph.py b/tests/cgu/test_syngraph.py index c6939aa..ab716dc 100644 --- a/tests/cgu/test_syngraph.py +++ b/tests/cgu/test_syngraph.py @@ -1,10 +1,15 @@ -from linchemin.cgu.syngraph import (BipartiteSynGraph, MonopartiteReacSynGraph, MonopartiteMolSynGraph, merge_syngraph, - extract_reactions_from_syngraph) -from linchemin.cgu.translate import translator -from linchemin.cheminfo.constructors import ChemicalEquationConstructor, MoleculeConstructor import json + import pytest +from linchemin.cgu.syngraph import (BipartiteSynGraph, MonopartiteMolSynGraph, + MonopartiteReacSynGraph, + extract_reactions_from_syngraph, + merge_syngraph) +from linchemin.cgu.translate import translator +from linchemin.cheminfo.constructors import (ChemicalEquationConstructor, + MoleculeConstructor) + def test_bipartite_syngraph_instance(az_path): """ To test that a BipartiteSynGraph instance is correctly generated. """ diff --git a/tests/cgu/test_translate.py b/tests/cgu/test_translate.py index 349e0a7..3e32374 100644 --- a/tests/cgu/test_translate.py +++ b/tests/cgu/test_translate.py @@ -1,15 +1,20 @@ -from linchemin.cgu.iron import Iron, Node, Edge, Direction -from linchemin.cgu.translate import (translator, ibm_dict_to_iron, get_available_formats, az_dict_to_iron, - get_available_data_models, get_output_formats, get_input_formats, TranslationError) -from linchemin.cgu.syngraph import BipartiteSynGraph, MonopartiteReacSynGraph -from linchemin.cheminfo.models import ChemicalEquation import json -import pydot -import networkx as nx -import pytest +import logging import os import unittest.mock -import logging + +import networkx as nx +import pydot +import pytest + +from linchemin.cgu.iron import Direction, Edge, Iron, Node +from linchemin.cgu.syngraph import BipartiteSynGraph, MonopartiteReacSynGraph +from linchemin.cgu.translate import (TranslationError, az_dict_to_iron, + get_available_data_models, + get_available_formats, get_input_formats, + get_output_formats, ibm_dict_to_iron, + translator) +from linchemin.cheminfo.models import ChemicalEquation def generate_iron_test_graph(): diff --git a/tests/cheminfo/test_atom_mapping.py b/tests/cheminfo/test_atom_mapping.py index 8027b85..f25164b 100644 --- a/tests/cheminfo/test_atom_mapping.py +++ b/tests/cheminfo/test_atom_mapping.py @@ -1,11 +1,16 @@ -from linchemin.cheminfo.atom_mapping import pipeline_atom_mapping, perform_atom_mapping, get_available_mappers -from linchemin.cgu.syngraph import extract_reactions_from_syngraph, MonopartiteReacSynGraph, merge_syngraph -from linchemin.cgu.translate import translator - -import pytest import json import unittest.mock +import pytest + +from linchemin.cgu.syngraph import (MonopartiteReacSynGraph, + extract_reactions_from_syngraph, + merge_syngraph) +from linchemin.cgu.translate import translator +from linchemin.cheminfo.atom_mapping import (get_available_mappers, + perform_atom_mapping, + pipeline_atom_mapping) + def test_basic_factory(capfd): with pytest.raises(KeyError) as ke: diff --git a/tests/cheminfo/test_chemical_similarity.py b/tests/cheminfo/test_chemical_similarity.py index 904d9c8..b34f58b 100644 --- a/tests/cheminfo/test_chemical_similarity.py +++ b/tests/cheminfo/test_chemical_similarity.py @@ -1,8 +1,9 @@ -import linchemin.cheminfo.functions as cif -from linchemin.cheminfo.chemical_similarity import (compute_reaction_fingerprint, compute_similarity, - compute_mol_fingerprint) import pytest -from rdkit.Chem import rdChemReactions, DataStructs +from rdkit.Chem import DataStructs, rdChemReactions + +import linchemin.cheminfo.functions as cif +from linchemin.cheminfo.chemical_similarity import ( + compute_mol_fingerprint, compute_reaction_fingerprint, compute_similarity) def test_rdkit_reaction_fingerprints_basics_non_mapped_molecules(): diff --git a/tests/cheminfo/test_constructors.py b/tests/cheminfo/test_constructors.py index 34bf3ce..63d693c 100644 --- a/tests/cheminfo/test_constructors.py +++ b/tests/cheminfo/test_constructors.py @@ -1,15 +1,22 @@ +import unittest from itertools import combinations -from linchemin.cheminfo.constructors import (MoleculeConstructor, ChemicalEquationConstructor, RatamConstructor, - BadMapping, PatternConstructor, TemplateConstructor, - DisconnectionConstructor, calculate_molecular_hash_values, - UnavailableMolIdentifier) -from linchemin.cheminfo.models import Template -from linchemin.utilities import create_hash + +import pytest + +import linchemin.cheminfo.depiction as cid import linchemin.cheminfo.functions as cif +from linchemin.cheminfo.constructors import (BadMapping, + ChemicalEquationConstructor, + DisconnectionConstructor, + MoleculeConstructor, + PatternConstructor, + RatamConstructor, + TemplateConstructor, + UnavailableMolIdentifier, + calculate_molecular_hash_values) +from linchemin.cheminfo.models import Template from linchemin.IO import io as lio -import linchemin.cheminfo.depiction as cid -import unittest -import pytest +from linchemin.utilities import create_hash # Molecule tests diff --git a/tests/cheminfo/test_functions.py b/tests/cheminfo/test_functions.py index 8c25d40..c41bbdc 100644 --- a/tests/cheminfo/test_functions.py +++ b/tests/cheminfo/test_functions.py @@ -1,15 +1,28 @@ +import unittest + import pytest from rdkit import Chem from rdkit.Chem import DataStructs, rdChemReactions -import unittest -from linchemin.cheminfo.constructors import ChemicalEquationConstructor, MoleculeConstructor +from linchemin.cheminfo.constructors import (ChemicalEquationConstructor, + MoleculeConstructor) +from linchemin.cheminfo.functions import (bstr_to_rdmol, + canonicalize_mapped_rdmol, + canonicalize_rdmol, + canonicalize_rdmol_lite, + compute_oxidation_numbers, + get_canonical_order, + has_mapped_products, + is_mapped_molecule, + mapping_diagnosis, + rdchiral_extract_template) from linchemin.cheminfo.functions import rdkit as rdkit -from linchemin.cheminfo.functions import canonicalize_rdmol, get_canonical_order, rdmol_from_string, \ - rdrxn_to_string, rdrxn_from_string, rdmol_to_bstr, bstr_to_rdmol, \ - rdrxn_from_string, is_mapped_molecule, has_mapped_products, canonicalize_rdmol_lite,\ - compute_oxidation_numbers, rdrxn_role_reassignment, rdrxn_to_rxn_mol_catalog, \ - remove_rdmol_atom_mapping, rdchiral_extract_template, canonicalize_mapped_rdmol, mapping_diagnosis +from linchemin.cheminfo.functions import (rdmol_from_string, rdmol_to_bstr, + rdrxn_from_string, + rdrxn_role_reassignment, + rdrxn_to_rxn_mol_catalog, + rdrxn_to_string, + remove_rdmol_atom_mapping) def test_build_rdrxn_from_smiles(): diff --git a/tests/conftest.py b/tests/conftest.py index 6dd467e..4f354c3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ from pathlib import Path + import pytest diff --git a/tests/interfaces/test_cli.py b/tests/interfaces/test_cli.py index c94591a..e411f92 100644 --- a/tests/interfaces/test_cli.py +++ b/tests/interfaces/test_cli.py @@ -1,5 +1,5 @@ -import unittest.mock import os +import unittest.mock def test_cli_basic(capfd, cli): diff --git a/tests/interfaces/test_facade.py b/tests/interfaces/test_facade.py index 634f300..cfa4a99 100644 --- a/tests/interfaces/test_facade.py +++ b/tests/interfaces/test_facade.py @@ -1,11 +1,12 @@ -from linchemin.interfaces.facade import facade, facade_helper -from linchemin.cgu.syngraph import MonopartiteReacSynGraph, BipartiteSynGraph -from rdkit.Chem import rdChemReactions +import json +import unittest +import unittest.mock + import pandas as pd +from rdkit.Chem import rdChemReactions -import unittest.mock -import unittest -import json +from linchemin.cgu.syngraph import BipartiteSynGraph, MonopartiteReacSynGraph +from linchemin.interfaces.facade import facade, facade_helper def test_translate(ibm2_path): diff --git a/tests/interfaces/test_workflows.py b/tests/interfaces/test_workflows.py index 13b2da5..f028ae5 100644 --- a/tests/interfaces/test_workflows.py +++ b/tests/interfaces/test_workflows.py @@ -1,8 +1,9 @@ -from linchemin.interfaces.workflows import process_routes, get_workflow_options -from linchemin.interfaces.facade import facade +import unittest.mock import pytest -import unittest.mock + +from linchemin.interfaces.facade import facade +from linchemin.interfaces.workflows import get_workflow_options, process_routes @unittest.mock.patch('linchemin.IO.io.write_json') diff --git a/tests/io/test_io_functions.py b/tests/io/test_io_functions.py index 7b8efc7..e94ca6e 100644 --- a/tests/io/test_io_functions.py +++ b/tests/io/test_io_functions.py @@ -1,4 +1,5 @@ import pytest + from linchemin.IO import io as lio diff --git a/tests/rem/test_clustering.py b/tests/rem/test_clustering.py index ad6a60b..3069bbc 100644 --- a/tests/rem/test_clustering.py +++ b/tests/rem/test_clustering.py @@ -1,8 +1,12 @@ -from linchemin.rem.clustering import (clusterer, get_available_clustering, get_clustered_routes_metrics, ClusteringError) -from linchemin.cgu.translate import translator import json + import pytest +from linchemin.cgu.translate import translator +from linchemin.rem.clustering import (ClusteringError, clusterer, + get_available_clustering, + get_clustered_routes_metrics) + def test_clusterer(az_path): graph = json.loads(open(az_path).read()) diff --git a/tests/rem/test_graph_distance.py b/tests/rem/test_graph_distance.py index 596471c..ff7ef87 100644 --- a/tests/rem/test_graph_distance.py +++ b/tests/rem/test_graph_distance.py @@ -1,16 +1,22 @@ -from linchemin.rem.graph_distance import (graph_distance_factory, compute_nodes_fingerprints, build_similarity_matrix, - get_available_ged_algorithms, get_ged_default_parameters, - compute_distance_matrix, get_ged_parameters, GraphDistanceError) -from linchemin.cgu.translate import translator -from linchemin.cgu.convert import converter - import json -import pytest + import networkx as nx -import pandas as pd import numpy as np +import pandas as pd +import pytest from rdkit.Chem import rdChemReactions +from linchemin.cgu.convert import converter +from linchemin.cgu.translate import translator +from linchemin.rem.graph_distance import (GraphDistanceError, + build_similarity_matrix, + compute_distance_matrix, + compute_nodes_fingerprints, + get_available_ged_algorithms, + get_ged_default_parameters, + get_ged_parameters, + graph_distance_factory) + def test_similarity_factory(az_path): # Test similarity with oneself with monopartite syngraphs and factory workflow diff --git a/tests/rem/test_node_metrics.py b/tests/rem/test_node_metrics.py index a689551..90ee51b 100644 --- a/tests/rem/test_node_metrics.py +++ b/tests/rem/test_node_metrics.py @@ -1,7 +1,8 @@ -from linchemin.rem.node_metrics import node_score_calculator, reaction_mapping -from linchemin.cheminfo.constructors import ChemicalEquationConstructor import pytest +from linchemin.cheminfo.constructors import ChemicalEquationConstructor +from linchemin.rem.node_metrics import node_score_calculator, reaction_mapping + def test_factory(): smile1 = 'CC(O)=O.CN>>CNC(C)=O' diff --git a/tests/rem/test_route_descriptors.py b/tests/rem/test_route_descriptors.py index b750190..0c2eb32 100644 --- a/tests/rem/test_route_descriptors.py +++ b/tests/rem/test_route_descriptors.py @@ -1,11 +1,17 @@ -from linchemin.cgu.convert import converter -from linchemin.rem.route_descriptors import (find_path, descriptor_calculator, is_subset, find_duplicates, - get_nodes_consensus, get_available_descriptors, DescriptorError) -from linchemin.cgu.syngraph import SynGraph, merge_syngraph, MonopartiteReacSynGraph import json -from linchemin.cgu.translate import translator + import pytest +from linchemin.cgu.convert import converter +from linchemin.cgu.syngraph import (MonopartiteReacSynGraph, SynGraph, + merge_syngraph) +from linchemin.cgu.translate import translator +from linchemin.rem.route_descriptors import (DescriptorError, + descriptor_calculator, + find_duplicates, find_path, + get_available_descriptors, + get_nodes_consensus, is_subset) + def test_unavailable_metrics(ibm1_path): """ To test that a KeyError is raised if an unavailable metrics is requested. """ diff --git a/tests/rem/test_route_scoring.py b/tests/rem/test_route_scoring.py index c53c266..7fb46c1 100644 --- a/tests/rem/test_route_scoring.py +++ b/tests/rem/test_route_scoring.py @@ -1,8 +1,9 @@ -from linchemin.rem.route_scoring import route_scorer -from linchemin.cgu.translate import translator +import json import pytest -import json + +from linchemin.cgu.translate import translator +from linchemin.rem.route_scoring import route_scorer def test_scoring_factory(ibm1_path): From 1d742a5455365a0fd4297bf44a45b0ed703849c4 Mon Sep 17 00:00:00 2001 From: Oleksii Leonov Date: Thu, 23 Mar 2023 16:21:25 +0000 Subject: [PATCH 2/2] ci: turn on isort pre-commit check for all files --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 05c9758..9636da6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: rev: 5.12.0 hooks: - id: isort - files: '^src/.*\.pyi?$' + files: '.*\.pyi?$' - repo: https://github.com/asottile/pyupgrade rev: v3.3.1 hooks: