forked from enviPath/enviPy
Current Dev State
This commit is contained in:
111
tests/test_datasetgenerator.py
Normal file
111
tests/test_datasetgenerator.py
Normal file
@ -0,0 +1,111 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from epdb.models import ParallelRule
|
||||
from utilities.ml import Compound, Reaction, DatasetGenerator
|
||||
|
||||
|
||||
class CompoundTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.c1 = Compound(smiles="CCN(CC)C(=O)C1=CC(=CC=C1)C", uuid='c1')
|
||||
self.c2 = Compound(smiles="CCN(CC)C(=O)C1=CC(=CC=C1)C", uuid='c2')
|
||||
|
||||
def test_compound_eq_ignores_uuid(self):
|
||||
self.assertEqual(self.c1, self.c2)
|
||||
|
||||
|
||||
class ReactionTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.c1 = Compound(smiles="CCN(CC)C(=O)C1=CC(=CC=C1)C")
|
||||
self.c2 = Compound(smiles="CCN(CCO)C(=O)C1=CC(C)=CC=C1")
|
||||
# self.r1 = Rule(uuid="bt0334")
|
||||
# c1 --r1--> c2
|
||||
self.c3_1 = Compound(smiles="CCNC(=O)C1=CC(C)=CC=C1")
|
||||
self.c3_2 = Compound(smiles="CC=O")
|
||||
# self.r2 = Rule(uuid="bt0243")
|
||||
# c1 --r2--> c3_1, c3_2
|
||||
|
||||
def test_reaction_equality_ignores_uuid(self):
|
||||
r1 = Reaction([self.c1], [self.c2], self.r1, uuid="abc")
|
||||
r2 = Reaction([self.c1], [self.c2], self.r1, uuid="xyz")
|
||||
self.assertEqual(r1, r2)
|
||||
|
||||
def test_reaction_inequality_on_data_change(self):
|
||||
r1 = Reaction([self.c1], [self.c2], self.r1)
|
||||
r2 = Reaction([self.c1], [self.c3_1], self.r1)
|
||||
self.assertNotEqual(r1, r2)
|
||||
|
||||
def test_reaction_is_hashable(self):
|
||||
r = Reaction([self.c1], [self.c2], self.r1)
|
||||
reactions = {r}
|
||||
self.assertIn(Reaction([self.c1], [self.c2], self.r1), reactions)
|
||||
|
||||
def test_rule_is_optional(self):
|
||||
r = Reaction([self.c1], [self.c2])
|
||||
self.assertIsNone(r.rule)
|
||||
|
||||
def test_uuid_is_optional(self):
|
||||
r = Reaction([self.c1], [self.c2], self.r1)
|
||||
self.assertIsNone(r.uuid)
|
||||
|
||||
def test_repr_includes_uuid(self):
|
||||
r = Reaction([self.c1], [self.c2], self.r1, uuid="abc")
|
||||
self.assertIn("abc", repr(r))
|
||||
|
||||
def test_reaction_equality_with_multiple_compounds_different_ordering(self):
|
||||
r1 = Reaction([self.c1], [self.c3_1, self.c3_2], self.r2)
|
||||
r2 = Reaction([self.c1], [self.c3_2, self.c3_1], self.r2)
|
||||
|
||||
self.assertEqual(r1, r2, "Reaction equality should not rely on list order")
|
||||
|
||||
|
||||
class RuleTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
# self.r1 = Rule(uuid="bt0334")
|
||||
# self.r2 = Rule(uuid="bt0243")
|
||||
|
||||
|
||||
class DatasetGeneratorTest(TestCase):
|
||||
fixtures = ['bootstrap.json']
|
||||
|
||||
def setUp(self):
|
||||
self.c1 = Compound(smiles="CCN(CC)C(=O)C1=CC(=CC=C1)C")
|
||||
self.c2 = Compound(smiles="CCN(CCO)C(=O)C1=CC(C)=CC=C1")
|
||||
self.c3_1 = Compound(smiles="CCNC(=O)C1=CC(C)=CC=C1")
|
||||
self.c3_2 = Compound(smiles="CC=O")
|
||||
|
||||
# self.r1 = Rule(uuid="bt0334") # trig
|
||||
# self.r2 = Rule(uuid="bt0243") # trig
|
||||
# self.r3 = Rule(uuid="bt0003") # no trig
|
||||
|
||||
self.reaction1 = Reaction([self.c1], [self.c2], self.r3)
|
||||
self.reaction2 = Reaction([self.c1], [self.c3_1, self.c3_2], self.r2)
|
||||
|
||||
|
||||
|
||||
|
||||
def test_test(self):
|
||||
compounds = [
|
||||
self.c1,
|
||||
self.c2,
|
||||
self.c3_1,
|
||||
self.c3_2,
|
||||
]
|
||||
|
||||
reactions = [
|
||||
self.reaction1,
|
||||
self.reaction2,
|
||||
]
|
||||
|
||||
applicable_rules = [
|
||||
# Rule('bt0334', ParallelRule.objects.get(name='bt0334')),
|
||||
# Rule('bt0243', ParallelRule.objects.get(name='bt0243')),
|
||||
# Rule('bt0003', ParallelRule.objects.get(name='bt0003')),
|
||||
]
|
||||
|
||||
ds = DatasetGenerator.generate_dataset(compounds, reactions, applicable_rules)
|
||||
|
||||
self.assertIsNotNone(ds)
|
||||
Reference in New Issue
Block a user