Skip to content

Speedup metadata tests #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 2, 2015
Prev Previous commit
Next Next commit
Splitting Sample tests between ReadOnly and ReadWrite
  • Loading branch information
josenavas committed Apr 2, 2015
commit 92cee23a8264f118ba78e766fa5e9c08b1733196
38 changes: 21 additions & 17 deletions qiita_db/metadata_template/test/test_sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
QiitaDBExecutionError,
QiitaDBColumnError, QiitaDBError,
QiitaDBWarning)
from qiita_db.sql_connection import SQLConnectionHandler
from qiita_db.study import Study, StudyPerson
from qiita_db.user import User
from qiita_db.util import exists_table, get_table_cols
from qiita_db.metadata_template.sample_template import SampleTemplate, Sample
from qiita_db.metadata_template.prep_template import PrepTemplate, PrepSample


@qiita_test_checker()
class TestSample(TestCase):
"""Tests the Sample class"""

class SetUpTestSample(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before.

def setUp(self):
self.sample_template = SampleTemplate(1)
self.sample_id = '1.SKB8.640193'
Expand All @@ -52,6 +50,8 @@ def setUp(self):
'tot_org_carb', 'description_duplicate',
'env_feature', 'latitude', 'longitude'}


class TestSampleReadOnly(SetUpTestSample):
def test_init_unknown_error(self):
"""Init raises an error if the sample id is not found in the template
"""
Expand Down Expand Up @@ -98,7 +98,8 @@ def test_exists_false(self):

def test_get_categories(self):
"""Correctly returns the set of category headers"""
obs = self.tester._get_categories(self.conn_handler)
conn_handler = SQLConnectionHandler()
obs = self.tester._get_categories(conn_handler)
self.assertEqual(obs, self.exp_categories)

def test_len(self):
Expand Down Expand Up @@ -130,18 +131,6 @@ def test_getitem_error(self):
with self.assertRaises(KeyError):
self.tester['Not_a_Category']

def test_setitem(self):
with self.assertRaises(QiitaDBColumnError):
self.tester['column that does not exist'] = 0.30
self.assertEqual(self.tester['tot_nitro'], 1.41)
self.tester['tot_nitro'] = '1234.5'
self.assertEqual(self.tester['tot_nitro'], 1234.5)

def test_delitem(self):
"""delitem raises an error (currently not allowed)"""
with self.assertRaises(QiitaDBNotImplementedError):
del self.tester['DEPTH']

def test_iter(self):
"""iter returns an iterator over the category headers"""
obs = self.tester.__iter__()
Expand Down Expand Up @@ -214,6 +203,21 @@ def test_get_none(self):
self.assertTrue(self.tester.get('Not_a_Category') is None)


@qiita_test_checker()
class TestSampleReadWrite(SetUpTestSample):
def test_setitem(self):
with self.assertRaises(QiitaDBColumnError):
self.tester['column that does not exist'] = 0.30
self.assertEqual(self.tester['tot_nitro'], 1.41)
self.tester['tot_nitro'] = '1234.5'
self.assertEqual(self.tester['tot_nitro'], 1234.5)

def test_delitem(self):
"""delitem raises an error (currently not allowed)"""
with self.assertRaises(QiitaDBNotImplementedError):
del self.tester['DEPTH']


@qiita_test_checker()
class TestSampleTemplate(TestCase):
"""Tests the SampleTemplate class"""
Expand Down