Skip to content

Commit

Permalink
Add first tests for helpers.py
Browse files Browse the repository at this point in the history
Covers the initiation of SQLiteBroker class
Includes the various extras needed to run the py.test/coverage scripts
  • Loading branch information
biologyguy committed Jan 9, 2017
1 parent e1fd5f1 commit f1aa918
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
25 changes: 1 addition & 24 deletions rdmcl/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from copy import copy
from hashlib import md5
from multiprocessing import SimpleQueue, Process, Pipe
from buddysuite.buddy_resources import pretty_time


class SQLiteBroker(object):
Expand Down Expand Up @@ -117,30 +118,6 @@ def total_elapsed(self, prefix="", postfix=""):
return "%s%s%s" % (prefix, pretty_time(round(time()) - self.start), postfix)


def pretty_time(seconds):
if seconds < 60:
output = "%i sec" % seconds
elif seconds < 3600:
minutes = floor(seconds / 60)
seconds -= minutes * 60
output = "%i min, %i sec" % (minutes, seconds)
elif seconds < 86400:
hours = floor((seconds / 60) / 60)
seconds -= hours * 60 * 60
minutes = floor(seconds / 60)
seconds -= minutes * 60
output = "%i hrs, %i min, %i sec" % (hours, minutes, seconds)
else:
days = floor(((seconds / 60) / 60) / 24)
seconds -= (days * 60 * 60 * 24)
hours = floor((seconds / 60) / 60)
seconds -= (hours * 60 * 60)
minutes = floor(seconds / 60)
seconds -= (minutes * 60)
output = "%i days, %i hrs, %i min, %i sec" % (days, hours, minutes, seconds)
return output


def md5_hash(in_str):
in_str = str(in_str).encode()
return md5(in_str).hexdigest()
Expand Down
4 changes: 4 additions & 0 deletions rdmcl/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ echo "test_fixtures.py"
TEST_SCRIPTS=${DIR}'/tests/test_fixtures.py '
py.test ${TEST_SCRIPTS} --cov ${DIR}/tests/__init__.py --cov-report html -n 4 -p no:cacheprovider --durations=10 $@

echo "test_helpers.py"
TEST_SCRIPTS=${DIR}'/tests/test_helpers.py '
py.test ${TEST_SCRIPTS} --cov ${DIR}/helpers.py --cov-report html -n 1 -p no:cacheprovider --durations=10 $@

echo "test_rdmcl.py"
TEST_SCRIPTS=${DIR}'/tests/test_rdmcl.py '
py.test ${TEST_SCRIPTS} --cov ${DIR}/rdmcl.py --cov-report html -n 8 -p no:cacheprovider --durations=10 $@
21 changes: 21 additions & 0 deletions rdmcl/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pytest
from .. import helpers
import os
import buddysuite.SeqBuddy
import buddysuite.buddy_resources as br
from hashlib import md5
import sqlite3
from multiprocessing.queues import SimpleQueue


def test_sqlitebroker_init(hf):
tmpdir = br.TempDir()
broker = helpers.SQLiteBroker("%s%sdb.sqlite" % (tmpdir.path, hf.sep))
assert broker.db_file == "%s%sdb.sqlite" % (tmpdir.path, hf.sep)
assert type(broker.connection) == sqlite3.Connection
assert type(broker.cursor) == sqlite3.Cursor
assert type(broker.broker_queue) == SimpleQueue
assert broker.broker is None
2 changes: 1 addition & 1 deletion rdmcl/tests/test_rdmcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-

import pytest
from .. import rdmcl
import os
import pandas as pd
from collections import OrderedDict
from .. import rdmcl
from buddysuite import buddy_resources as br


Expand Down
8 changes: 8 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ then
FAILURE=1
fi

#### Helper tests
TEST_SCRIPTS='test_helpers.py '
py.test ${TEST_SCRIPTS} --cache-clear -p no:cacheprovider --cov --cov-report= --cov-config ../.coveragerc --durations=10
if [ $? -ne 0 ]
then
FAILURE=1
fi

#### RD-MCL tests
TEST_SCRIPTS='test_rdmcl.py '
py.test ${TEST_SCRIPTS} --cache-clear -p no:cacheprovider --cov --cov-report= --cov-config ../.coveragerc --durations=10
Expand Down

0 comments on commit f1aa918

Please sign in to comment.