Skip to content

Commit

Permalink
Fix remaining self.assert tests; move strange test integrated into ut…
Browse files Browse the repository at this point in the history
…il file into its own file
  • Loading branch information
ialarmedalien committed Nov 13, 2023
1 parent 67d4f08 commit 8eb470e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/biokbase/narrative/tests/test_appmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_run_app__good_inputs(self, auth, c):
assert self.jm.get_job(self.test_job_id) == new_job
self._verify_comm_success(c.return_value.send_comm_message, False)

assert False is self.jm._running_jobs[new_job.job_id]["refresh"]
assert self.jm._running_jobs[new_job.job_id]["refresh"] is False

@mock.patch(CLIENTS_AM, get_mock_client)
@mock.patch(JOB_COMM_MOCK)
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_run_legacy_batch_app__good_inputs(self, auth, c):
assert self.jm.get_job(self.test_job_id) == new_job
self._verify_comm_success(c.return_value.send_comm_message, False)

assert False is self.jm._running_jobs[new_job.job_id]["refresh"]
assert self.jm._running_jobs[new_job.job_id]["refresh"] is False

@mock.patch(CLIENTS_AM, get_mock_client)
@mock.patch(JOB_COMM_MOCK)
Expand Down Expand Up @@ -797,7 +797,7 @@ def test_run_app_batch__good_inputs(self, auth, c):
self._verify_comm_success(c.return_value.send_comm_message, True, num_jobs=4)

for job in [parent_job, *child_jobs]:
assert False is self.jm._running_jobs[job.job_id]["refresh"]
assert self.jm._running_jobs[job.job_id]["refresh"] is False

@mock.patch(CLIENTS_AM, get_mock_client)
@mock.patch(JOB_COMM_MOCK)
Expand Down
13 changes: 13 additions & 0 deletions src/biokbase/narrative/tests/test_kvp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from biokbase.narrative.common.kvp import parse_kvp


def test_parse_kvp() -> None:
for user_input, text, kvp in (
("foo", "foo", {}),
("name=val", "", {"name": "val"}),
("a name=val boy", "a boy", {"name": "val"}),
):
rkvp = {}
rtext = parse_kvp(user_input, rkvp)
assert text == rtext
assert kvp == rkvp
44 changes: 27 additions & 17 deletions src/biokbase/narrative/tests/test_log_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import time
import unittest

from biokbase.narrative.common import log_proxy as proxy
import pytest
from biokbase.narrative.common import log_proxy

__author__ = "Dan Gunter <[email protected]>"

Expand All @@ -21,8 +22,8 @@ class MainTestCase(unittest.TestCase):

def setUp(self):
self._config(["db: test", "collection: kblog"])
if proxy.g_log is None:
proxy.g_log = logging.getLogger(proxy.LOGGER_NAME)
if log_proxy.g_log is None:
log_proxy.g_log = logging.getLogger(log_proxy.LOGGER_NAME)

def _config(self, lines):
text = "\n".join(lines)
Expand All @@ -33,7 +34,7 @@ def test_run_proxy(self):
pid = os.fork()
if pid == 0:
print("Run child")
proxy.run(self)
log_proxy.run(self)
else:
time.sleep(1)
print("Wait for child to start")
Expand All @@ -51,16 +52,21 @@ def test_run_proxy(self):
def test_configuration(self):
# empty
self._config([])
self.assertRaises(ValueError, proxy.DBConfiguration, self.conf)
with pytest.raises(ValueError):
log_proxy.DBConfiguration(self.conf)
# , proxy.DBConfiguration, self.conf)
# missing collection
self._config(["db: test"])
self.assertRaises(KeyError, proxy.DBConfiguration, self.conf)
with pytest.raises(KeyError):
log_proxy.DBConfiguration(self.conf)
# bad db name
self._config(["db: 1test", "collection: kblog"])
self.assertRaises(ValueError, proxy.DBConfiguration, self.conf)
with pytest.raises(ValueError):
log_proxy.DBConfiguration(self.conf)
# bad db name
self._config(["db: test.er", "collection: kblog"])
self.assertRaises(ValueError, proxy.DBConfiguration, self.conf)
with pytest.raises(ValueError):
log_proxy.DBConfiguration(self.conf)
# too long
self._config(
[
Expand All @@ -69,24 +75,27 @@ def test_configuration(self):
"ddddddddddddddddddddddddddddddd",
]
)
self.assertRaises(ValueError, proxy.DBConfiguration, self.conf)
with pytest.raises(ValueError):
log_proxy.DBConfiguration(self.conf)
# bad collection
self._config(["db: test", "collection: kb$log"])
self.assertRaises(ValueError, proxy.DBConfiguration, self.conf)
with pytest.raises(ValueError):
log_proxy.DBConfiguration(self.conf)
# user, no pass
self._config(["db: test", "collection: kblog", "user: joe"])
self.assertRaises(KeyError, proxy.DBConfiguration, self.conf)
with pytest.raises(KeyError):
log_proxy.DBConfiguration(self.conf)


class LogRecordTest(unittest.TestCase):
def setUp(self):
if proxy.g_log is None:
proxy.g_log = logging.getLogger(proxy.LOGGER_NAME)
if log_proxy.g_log is None:
log_proxy.g_log = logging.getLogger(log_proxy.LOGGER_NAME)

def test_basic(self):
for input in {}, {"message": "hello"}:
kbrec = proxy.DBRecord(input)
kbrec = proxy.DBRecord({"message": "greeting;Hello=World"})
kbrec = log_proxy.DBRecord(input)
kbrec = log_proxy.DBRecord({"message": "greeting;Hello=World"})
assert kbrec.record["event"] == "greeting"
assert kbrec.record["Hello"] == "World"

Expand All @@ -96,8 +105,9 @@ def test_strict(self):
{12: "xanthium"},
{"message": "Hello=World;greeting"},
):
proxy.DBRecord(inp)
self.assertRaises(ValueError, proxy.DBRecord, inp, strict=True)
log_proxy.DBRecord(inp)
with pytest.raises(ValueError):
log_proxy.DBRecord(inp, strict=True)


if __name__ == "__main__":
Expand Down
14 changes: 0 additions & 14 deletions src/biokbase/narrative/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,6 @@ def read_json_file(path):
return data


class MyTestCase(unittest.TestCase):
def test_kvparse(self):
for user_input, text, _kvp in (
("foo", "foo", {}),
("name=val", "", {"name": "val"}),
("a name=val boy", "a boy", {"name": "val"}),
):
rkvp = {}
rtext = util.parse_kvp(user_input, rkvp)
assert text == rtext

assert text == rtext


class SocketServerBuf(socketserver.TCPServer):
allow_reuse_address = True

Expand Down

0 comments on commit 8eb470e

Please sign in to comment.