summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-01-25 14:13:00 -0800
committerbnewbold <bnewbold@robocracy.org>2016-01-25 14:13:00 -0800
commit161ad38959e7bea6967760c0418f90850f77a9c9 (patch)
tree8e984942d403d8b99f101e104a61adffbcb4dbb8
parent5bcc6a37f76af99843dc82524bdf7c666da5eafd (diff)
downloadbasebasebase-161ad38959e7bea6967760c0418f90850f77a9c9.tar.gz
basebasebase-161ad38959e7bea6967760c0418f90850f77a9c9.zip
more tests
-rwxr-xr-xtests/run_all_tests.sh8
-rw-r--r--tests/test_json.py27
-rw-r--r--tests/test_local_server.py39
-rw-r--r--tests/test_objects.py46
-rw-r--r--tests/test_wikidata_org.py5
5 files changed, 84 insertions, 41 deletions
diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh
index b391a61..afac4e6 100755
--- a/tests/run_all_tests.sh
+++ b/tests/run_all_tests.sh
@@ -2,14 +2,16 @@
set -e
+# Check that tools are installed first
nosetests3 --version > /dev/null
+#python-coverage --version > /dev/null
+python3-coverage --version > /dev/null
+
nosetests3 -v --logging-level INFO --with-coverage --cover-erase
-#python-coverage --version > /dev/null
#python-coverage html --omit="*/test*" -d tests/coverage2_html_report 2> /dev/null
-python3-coverage --version > /dev/null
-python3-coverage html --omit="*/test*" -d tests/coverage3_html_report 2> /dev/null
+python3-coverage html -d tests/coverage3_html_report 2> /dev/null
echo ""
echo "To see coverage results open tests/coverage3_html_report/index.html"
diff --git a/tests/test_json.py b/tests/test_json.py
deleted file mode 100644
index 19dfc18..0000000
--- a/tests/test_json.py
+++ /dev/null
@@ -1,27 +0,0 @@
-"""
-This file contains tests that parse and dump JSON serialized entities.
-
-It requires the 'nose' python package. To run it, just enter this directory and
-do:
-
- $ nosetests
-
-If there are errors it can be helpful to debug with:
-
- $ nosetests --pdb
-"""
-
-from nose.tools import *
-from nose.plugins.skip import SkipTest
-import unittest
-import random
-import json
-
-from bbb import *
-
-class TestJSON(unittest.TestCase):
-
- def test_wikidata_org_item(self):
- with open('tests/example_item_nyc.json', 'r') as f:
- d = json.loads(''.join(f.readlines()))
- wi = WikibaseItem.from_dict(d)
diff --git a/tests/test_local_server.py b/tests/test_local_server.py
index 5bd8760..8521d6f 100644
--- a/tests/test_local_server.py
+++ b/tests/test_local_server.py
@@ -77,22 +77,42 @@ class TestLocalServer(unittest.TestCase):
with assert_raises(WikibaseAccountError):
self.srv.login(TEST_SERVER_USER, TEST_SERVER_PASSWD+"BADBAD", force_http=True)
+ def test_bad_action(self):
+ with assert_raises(WikibaseAPIError):
+ self.srv._get("wbbogusapiactionname", dict(entity="Q42"))
+
def test_get_item(self):
item = self.srv.get_item("Coffee")
item = self.srv.get_item("Q2")
item = self.srv.get_item(2)
+ item = self.srv.get_items([])
+ item = self.srv.get_items(['Q2', 'Q3'])
+ with assert_raises(MissingItemError):
+ item = self.srv.get_item("Totally Bogus Name For Item That Will Never Exist")
+ with assert_raises(ValueError):
+ item = self.srv.get_item("P2")
def test_get_property(self):
- raise SkipTest("UNIMPLEMENTED")
- item = self.srv.get_property("Mass")
- item = self.srv.get_property(pid="P2")
- item = self.srv.get_property(pid=2)
+ # XXX: item = self.srv.get_property("Mass")
+ item = self.srv.get_property("P2")
+ item = self.srv.get_property(2)
+ item = self.srv.get_properties([])
+ item = self.srv.get_properties(['P2', 'P3'])
+ # XXX: with assert_raises(MissingEntityError):
+ # item = self.srv.get_property("Totally Bogus Name For Item That Will Never Exist")
+ with assert_raises(ValueError):
+ item = self.srv.get_item("Q2")
+
+ def test_search_items(self):
+ l = self.srv.search_items("love", limit=5)
+ l = self.srv.search_items("robot", limit=5)
+ l = self.srv.search_items("Imposible_String_" + str(random.randint(10e19, 10e20)), limit=5)
+ assert len(l) == 0
- def test_find_items(self):
- raise SkipTest("UNIMPLEMENTED")
- l = self.srv.find_items("love", limit=5)
- l = self.srv.find_items("robot", limit=5)
- l = self.srv.find_items("Imposible_String_" + random.randint(10e19, 10e20), limit=5)
+ def test_search_properties(self):
+ l = self.srv.search_properties("love", limit=5)
+ l = self.srv.search_properties("robot", limit=5)
+ l = self.srv.search_properties("Imposible_String_" + str(random.randint(10e19, 10e20)), limit=5)
assert len(l) == 0
def test_create_item(self):
@@ -104,4 +124,3 @@ class TestLocalServer(unittest.TestCase):
qualifiers={'year_of_invention': 1860},
refs=['http://www.smithsonianmag.com/arts-culture/fact-of-fiction-the-legend-of-the-qwerty-keyboard-49863249/']))
self.srv.save(item)
-
diff --git a/tests/test_objects.py b/tests/test_objects.py
new file mode 100644
index 0000000..7b1c6ac
--- /dev/null
+++ b/tests/test_objects.py
@@ -0,0 +1,46 @@
+"""
+This file contains tests for generic object classes.
+
+It requires the 'nose' python package. To run it, just enter this directory and
+do:
+
+ $ nosetests
+
+If there are errors it can be helpful to debug with:
+
+ $ nosetests --pdb
+"""
+
+from nose.tools import *
+from nose.plugins.skip import SkipTest
+import unittest
+import random
+import json
+
+from bbb import *
+
+class TestObjects(unittest.TestCase):
+
+ def test_wikidata_org_item(self):
+ with open('tests/example_item_nyc.json', 'r') as f:
+ d = json.loads(''.join(f.readlines()))
+ wi = WikibaseItem.from_dict(d)
+ wi.qid()
+ wi.to_dict()
+
+ def test_item(self):
+ WikibaseItem()
+ item = WikibaseItem({"en": "Some Item", "de": "Deutsch Item"})
+ WikibaseItem("Some Label", "Some Description", ['Another Name'], "Q93594")
+ item.to_dict()
+ item.qid()
+
+ def test_property(self):
+ prop = WikibaseProperty()
+ prop.to_dict()
+ prop.pid()
+
+ def test_statement(self):
+ stmt = WikibaseStatement()
+ raise SkipTest("Not Implemented Yet")
+ stmt.to_dict()
diff --git a/tests/test_wikidata_org.py b/tests/test_wikidata_org.py
index 7f6e377..3222870 100644
--- a/tests/test_wikidata_org.py
+++ b/tests/test_wikidata_org.py
@@ -34,5 +34,8 @@ class TestWikidataOrg(unittest.TestCase):
raise SkipTest("Couldn't connect wikidata.org")
def test_low_level(self):
- self.srv._get("wbgetclaims", dict(entity="Q42"))
+ self.srv._get("wbgetclaims", dict(entity="Q11"))
+ def test_item_object(self):
+ item = self.srv.get_item("Q10")
+ item.to_dict()