Skip to content

Commit

Permalink
Pytest Port
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleswing committed Jun 5, 2020
1 parent 614d359 commit d2a928b
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install:
- pip install coveralls
- python setup.py install
script:
- nosetests -q --with-flaky -a '!slow' --with-coverage --cover-package=deepchem
- pytest -m "not slow" deepchem
-v deepchem --nologcapture
- if [ $TRAVIS_PYTHON_VERSION == '3.7' ]; then
find ./deepchem | grep .py$ |xargs python -m doctest -v;
Expand Down
2 changes: 1 addition & 1 deletion contrib/autoencoder_models/test_tensorflowEncoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class TestTensorflowEncoders(TestCase):

@attr('slow')
@pytest.mark.slow('slow')
def test_fit(self):
tf_enc = TensorflowMoleculeEncoder.zinc_encoder()

Expand Down
5 changes: 3 additions & 2 deletions deepchem/dock/tests/test_binding_pocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import unittest
import os
import numpy as np
import pytest

import deepchem as dc
from nose.tools import nottest
from deepchem.utils import rdkit_util

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_convex_find_pockets(self):

assert len(pockets) < len(all_pockets)

@nottest
@pytest.mark.skip(reson="Unknown")
def test_rf_convex_find_pockets(self):
"""Test that filter with pre-trained RF models works."""
if sys.version_info >= (3, 0):
Expand Down
22 changes: 12 additions & 10 deletions deepchem/dock/tests/test_docking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@

import unittest
import os
from nose.plugins.attrib import attr
from nose.tools import nottest

import sys

import pytest

import deepchem as dc


class TestDocking(unittest.TestCase):
"""
Does sanity checks on pose generation.
Does sanity checks on pose generation.
"""

@nottest
@pytest.mark.skip(reason="Unknown")
def test_vina_grid_rf_docker_init(self):
"""Test that VinaGridRFDocker can be initialized."""
if sys.version_info >= (3, 0):
return
docker = dc.dock.VinaGridRFDocker(exhaustiveness=1, detect_pockets=False)

@nottest
@pytest.mark.skip(reason="Unknown")
def test_pocket_vina_grid_rf_docker_init(self):
"""Test that VinaGridRFDocker w/pockets can be initialized."""
if sys.version_info >= (3, 0):
Expand All @@ -45,7 +47,7 @@ def test_pocket_vina_grid_dnn_docker_init(self):
docker = dc.dock.VinaGridDNNDocker(exhaustiveness=1, detect_pockets=True)
'''

@attr("slow")
@pytest.mark.slow
def test_vina_grid_rf_docker_dock(self):
"""Test that VinaGridRFDocker can dock."""
if sys.version_info >= (3, 0):
Expand All @@ -64,7 +66,7 @@ def test_vina_grid_rf_docker_dock(self):
assert os.path.exists(protein_docked)
assert os.path.exists(ligand_docked)

@nottest
@pytest.mark.skip(reason="Unknown")
def test_vina_grid_rf_docker_specified_pocket(self):
"""Test that VinaGridRFDocker can dock into spec. pocket."""
if sys.version_info >= (3, 0):
Expand All @@ -85,7 +87,7 @@ def test_vina_grid_rf_docker_specified_pocket(self):
# Check returned files exist
assert score.shape == (1,)

@nottest
@pytest.mark.skip(reason="Unknown")
def test_pocket_vina_grid_rf_docker_dock(self):
"""Test that VinaGridRFDocker can dock."""
if sys.version_info >= (3, 0):
Expand All @@ -106,7 +108,7 @@ def test_pocket_vina_grid_rf_docker_dock(self):
assert score.shape == (1,)

'''
@attr("slow")
@pytest.mark.slow("slow")
def test_vina_grid_dnn_docker_dock(self):
"""Test that VinaGridDNNDocker can dock."""
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -122,7 +124,7 @@ def test_vina_grid_dnn_docker_dock(self):
assert os.path.exists(protein_docked)
assert os.path.exists(ligand_docked)
@attr('slow')
@pytest.mark.slow('slow')
def test_pocket_vina_grid_dnn_docker_dock(self):
"""Test that VinaGridDNNDocker can dock."""
if sys.version_info >= (3, 0):
Expand Down
10 changes: 5 additions & 5 deletions deepchem/dock/tests/test_pose_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
import sys
import unittest
import deepchem as dc
from nose.plugins.attrib import attr
import pytest


class TestPoseGeneration(unittest.TestCase):
"""
Does sanity checks on pose generation.
"""

@attr("slow")
@pytest.mark.slow
def test_vina_initialization(self):
"""Test that VinaPoseGenerator can be initialized."""
# Note this may download autodock Vina...
vpg = dc.dock.VinaPoseGenerator(detect_pockets=False, exhaustiveness=1)

@attr("slow")
@pytest.mark.slow("slow")
def test_pocket_vina_initialization(self):
"""Test that VinaPoseGenerator can be initialized."""
# Note this may download autodock Vina...
if sys.version_info >= (3, 0):
return
vpg = dc.dock.VinaPoseGenerator(detect_pockets=True, exhaustiveness=1)

@attr("slow")
@pytest.mark.slow("slow")
def test_vina_poses(self):
"""Test that VinaPoseGenerator creates pose files."""
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -47,7 +47,7 @@ def test_vina_poses(self):
assert os.path.exists(protein_pose_file)
assert os.path.exists(ligand_pose_file)

@attr('slow')
@pytest.mark.slow('slow')
def test_pocket_vina_poses(self):
"""Test that VinaPoseGenerator creates pose files."""
if sys.version_info >= (3, 0):
Expand Down
3 changes: 3 additions & 0 deletions deepchem/dock/tests/test_pose_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import os
import shutil
import numpy as np
import pytest

import deepchem as dc
from sklearn.ensemble import RandomForestRegressor
from subprocess import call
Expand All @@ -21,6 +23,7 @@
logger = logging.getLogger(__name__)


@pytest.mark.linux_only
class TestPoseScoring(unittest.TestCase):
"""
Does sanity checks on pose generation.
Expand Down
5 changes: 3 additions & 2 deletions deepchem/feat/tests/test_graph_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import unittest
import os
import numpy as np
from nose.plugins.attrib import attr
import pytest

from deepchem.feat.graph_features import ConvMolFeaturizer, AtomicConvFeaturizer


Expand Down Expand Up @@ -94,7 +95,7 @@ def test_alkane(self):

class TestAtomicConvFeaturizer(unittest.TestCase):

@attr("slow")
@pytest.mark.slow
def test_feature_generation(self):
"""Test if featurization works using AtomicConvFeaturizer."""
dir_path = os.path.dirname(os.path.realpath(__file__))
Expand Down
5 changes: 2 additions & 3 deletions deepchem/feat/tests/test_one_hot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase

import deepchem as dc
from nose.tools import assert_equals


class TestOneHotFeaturizer(TestCase):
Expand All @@ -14,6 +13,6 @@ def test_featurize(self):
featurizer = dc.feat.one_hot.OneHotFeaturizer(dc.feat.one_hot.zinc_charset)
one_hots = featurizer.featurize(mols)
untransformed = featurizer.untransform(one_hots)
assert_equals(len(smiles), len(untransformed))
len(smiles) == len(untransformed)
for i in range(len(smiles)):
assert_equals(smiles[i], untransformed[i][0])
assert smiles[i] == untransformed[i][0]
3 changes: 3 additions & 0 deletions deepchem/feat/tests/test_rdkit_grid_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import unittest

import numpy as np
import pytest

np.random.seed(123)
from deepchem.feat import rdkit_grid_featurizer as rgf

Expand Down Expand Up @@ -450,6 +452,7 @@ def test_featurize_splif(self):
self.assertEqual(dicts, expected_dicts)


@pytest.mark.linux_only
class TestRdkitGridFeaturizer(unittest.TestCase):
"""
Test RdkitGridFeaturizer class defined in rdkit_grid_featurizer module.
Expand Down
7 changes: 3 additions & 4 deletions deepchem/feat/tests/test_smiles_featurizers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest import TestCase
import numpy as np
from nose.tools import assert_equals
from deepchem.feat import SmilesToSeq, SmilesToImage
from deepchem.feat.smiles_featurizers import create_char_to_idx
import os
Expand All @@ -27,8 +26,8 @@ def test_smiles_to_seq_featurize(self):
expected_seq_len = self.feat.max_len + 2 * self.feat.pad_len

features = self.feat.featurize(mols)
assert_equals(features.shape[0], len(smiles))
assert_equals(features.shape[-1], expected_seq_len)
assert features.shape[0] == len(smiles)
assert features.shape[-1] == expected_seq_len

def test_reconstruct_from_seq(self):
"""Test SMILES reconstruction from features."""
Expand All @@ -38,4 +37,4 @@ def test_reconstruct_from_seq(self):
features = self.feat.featurize(mols)

reconstructed_smile = self.feat.smiles_from_seq(features[0])
assert_equals(smiles[0], reconstructed_smile)
assert smiles[0] == reconstructed_smile
10 changes: 6 additions & 4 deletions deepchem/models/tests/test_atomic_conv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
Tests for Atomic Convolutions.
"""
from nose.plugins.attrib import attr

import os

import pytest

import deepchem
import numpy as np
import tensorflow as tf
Expand All @@ -16,7 +18,7 @@

class TestAtomicConv(unittest.TestCase):

@attr("slow")
@pytest.mark.slow
def test_atomic_conv(self):
"""A simple test that initializes and fits an AtomicConvModel."""
# For simplicity, let's assume both molecules have same number of
Expand Down Expand Up @@ -64,7 +66,7 @@ def test_atomic_conv(self):
atomic_convnet.fit(train, nb_epoch=300)
assert np.allclose(labels, atomic_convnet.predict(train), atol=0.01)

@attr("slow")
@pytest.mark.slow("slow")
def test_atomic_conv_variable(self):
"""A simple test that initializes and fits an AtomicConvModel on variable input size."""
# For simplicity, let's assume both molecules have same number of
Expand Down Expand Up @@ -100,7 +102,7 @@ def test_atomic_conv_variable(self):
train = NumpyDataset(features, labels)
atomic_convnet.fit(train, nb_epoch=1)

@attr("slow")
@pytest.mark.slow("slow")
def test_atomic_conv_with_feat(self):
"""A simple test for running an atomic convolution on featurized data."""
dir_path = os.path.dirname(os.path.realpath(__file__))
Expand Down
14 changes: 8 additions & 6 deletions deepchem/models/tests/test_chemnet_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import numpy as np
import tempfile

import pytest

import deepchem as dc
from deepchem.data import NumpyDataset
from deepchem.models import Smiles2Vec, ChemCeption
from deepchem.feat import SmilesToSeq, SmilesToImage
from deepchem.molnet.load_function.chembl25_datasets import chembl25_tasks
from deepchem.feat.smiles_featurizers import create_char_to_idx
from nose.plugins.attrib import attr

from flaky import flaky


Expand Down Expand Up @@ -66,7 +68,7 @@ def get_dataset(self, mode="classification", featurizer="smiles2seq"):

return dataset, metric

@attr('slow')
@pytest.mark.slow
def test_smiles_to_vec_regression(self):
dataset, metric = self.get_dataset(
mode="regression", featurizer="smiles2seq")
Expand All @@ -81,7 +83,7 @@ def test_smiles_to_vec_regression(self):
scores = model.evaluate(dataset, [metric], [])
assert all(s < 0.1 for s in scores['mean_absolute_error'])

@attr('slow')
@pytest.mark.slow
def test_smiles_to_vec_classification(self):
dataset, metric = self.get_dataset(
mode="classification", featurizer="smiles2seq")
Expand All @@ -96,7 +98,7 @@ def test_smiles_to_vec_classification(self):
scores = model.evaluate(dataset, [metric], [])
assert scores['mean-roc_auc_score'] >= 0.9

@attr('slow')
@pytest.mark.slow
def test_chemception_regression(self):
dataset, metric = self.get_dataset(
mode="regression", featurizer="smiles2img")
Expand All @@ -109,7 +111,7 @@ def test_chemception_regression(self):
scores = model.evaluate(dataset, [metric], [])
assert all(s < 0.1 for s in scores['mean_absolute_error'])

@attr('slow')
@pytest.mark.slow
def test_chemception_classification(self):
dataset, metric = self.get_dataset(
mode="classification", featurizer="smiles2img")
Expand All @@ -122,7 +124,7 @@ def test_chemception_classification(self):
scores = model.evaluate(dataset, [metric], [])
assert scores['mean-roc_auc_score'] >= 0.9

@attr('slow')
@pytest.mark.slow
def test_chemception_fit_with_augmentation(self):
dataset, metric = self.get_dataset(
mode="classification", featurizer="smiles2img")
Expand Down
1 change: 0 additions & 1 deletion deepchem/models/tests/test_gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import unittest
from tensorflow.keras.layers import Input, Concatenate, Dense
from flaky import flaky
from nose.plugins.attrib import attr


def generate_batch(batch_size):
Expand Down
Loading

0 comments on commit d2a928b

Please sign in to comment.