-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix remaining self.assert tests; move strange test integrated into ut…
…il file into its own file
- Loading branch information
1 parent
67d4f08
commit 8eb470e
Showing
4 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]>" | ||
|
||
|
@@ -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) | ||
|
@@ -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") | ||
|
@@ -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( | ||
[ | ||
|
@@ -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" | ||
|
||
|
@@ -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__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters