Conditions | 4 |
Total Lines | 52 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import pytest |
||
21 | def test_parents(self): |
||
22 | dat = dict( |
||
23 | target_chembl_id="CHEMBL4444", |
||
24 | pref_name="dopamine transporter", |
||
25 | target_type="SINGLE_PROTEIN", |
||
26 | ) |
||
27 | monoamine = dict( |
||
28 | target_chembl_id="CHEMBL1111", |
||
29 | pref_name="monoamine transporter", |
||
30 | target_type="SINGLE_PROTEIN", |
||
31 | ) |
||
32 | receptor = dict( |
||
33 | target_chembl_id="CHEMBL0000", pref_name="receptor", target_type="PROTEIN_COMPLEX" |
||
34 | ) |
||
35 | relations = [ |
||
36 | dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL1111"), |
||
37 | dict(relationship="SUBSET OF", related_target_chembl_id="CHEMBL0000"), |
||
38 | ] |
||
39 | get_target = { |
||
40 | "DAT": dat, |
||
41 | "CHEMBL4444": dat, |
||
42 | "CHEMBL1111": monoamine, |
||
43 | "CHEMBL0000": receptor, |
||
44 | } |
||
45 | |||
46 | def filter_targets(kwargs): |
||
47 | x = kwargs["target_chembl_id"] |
||
48 | if x == "CHEMBL4444": |
||
49 | return [dat] |
||
50 | elif x == "CHEMBL1111": |
||
51 | return [monoamine] |
||
52 | elif x == "CHEMBL0000": |
||
53 | return [receptor] |
||
54 | |||
55 | def filter_relations(kwargs): |
||
56 | return relations |
||
57 | |||
58 | api = ChemblApi.mock( |
||
59 | { |
||
60 | "target": ChemblEntrypoint.mock(get_target, filter_targets), |
||
61 | "target_relation": ChemblEntrypoint.mock({}, filter_relations), |
||
62 | } |
||
63 | ) |
||
64 | target = TargetFactory.find("CHEMBL4444", api) |
||
65 | assert len(target.links({TargetRelationshipType.subset_of})) == 2 |
||
66 | # should sort by CHEMBL ID first, so 0000 will be first |
||
67 | parent, link_type = target.links({TargetRelationshipType.subset_of})[0] |
||
68 | assert parent.name == "receptor" |
||
69 | assert parent.chembl == "CHEMBL0000" |
||
70 | parent, link_type = target.links({TargetRelationshipType.subset_of})[1] |
||
71 | assert parent.name == "monoamine transporter" |
||
72 | assert parent.chembl == "CHEMBL1111" |
||
73 | |||
132 |