Skip to content

Commit

Permalink
adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 7, 2024
1 parent cdddf9d commit 7cd2522
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ez_wikidata/__init__.py
@@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "0.2.1"
96 changes: 96 additions & 0 deletions tests/test_property_mapping.py
@@ -0,0 +1,96 @@
"""
Created on 2023-01-14
@author: wf
"""
from ez_wikidata.wdproperty import PropertyMapping, WdDatatype, WikidataPropertyManager
from tests.basetest import BaseTest

class TestPropertyMapping(BaseTest):
"""
test the property Mapping
"""

def setUp(self, debug=False, profile=True):
BaseTest.setUp(self, debug=debug, profile=profile)
self.wpm=WikidataPropertyManager.get_instance()


def test_from_record(self):
"""
tests from_record
"""
test_params = [
(
"languageOfWork",
"language of work or name",
"P407",
"itemid",
"official website",
"",
)
]
for params in test_params:
col, name, p_id, p_type, qualifier, lookup = params
record = {
"column": col,
"propertyName": name,
"propertyType": p_type,
"propertyId": p_id,
"qualifierOf": qualifier,
"valueLookupType": lookup,
}
legacy_record = {
"Column": col,
"PropertyName": name,
"PropertyId": p_id,
"Type": p_type,
"Qualifier": qualifier,
"Lookup": lookup,
}
for i, rec in enumerate([record, legacy_record]):
mode = "legacy" if i == 1 else ""
with self.subTest(f"test parsing from {mode} record", rec=rec):
mapping = PropertyMapping.from_record(wpm=self.wpm,record=rec)
for key, expected_value in record.items():
actual_value = getattr(mapping, key)
self.assertEqual(expected_value, actual_value)

def test_is_qualifier(self):
"""
tests id_qualifier
"""
positive_case = PropertyMapping(
column="volume",
propertyId="P478",
propertyName="volume",
propertyType=WdDatatype.string,
qualifierOf="part of the series",
)
negative_case = PropertyMapping(
column="acronym",
propertyId="P1813",
propertyName="short name",
propertyType=WdDatatype.text,
)
self.assertTrue(positive_case.is_qualifier())
self.assertFalse(negative_case.is_qualifier())

def test_WdDatatype_lookup(self):
"""
tests the WdDatatype lookup for None and empty string as key
"""
test_params = [(None, WdDatatype.text), ("", WdDatatype.text)]
for param in test_params:
with self.subTest(param=param):
property_type, expected = param
self.assertEqual(expected, WdDatatype(property_type))

def test_DefaultItemPropertyMapping(self):
"""
test the default item PropertyMapping
"""
itemMapping = PropertyMapping.getDefaultItemPropertyMapping()
self.assertIsNotNone(itemMapping)
self.assertTrue(isinstance(itemMapping, PropertyMapping))
self.assertTrue(itemMapping.is_item_itself())

0 comments on commit 7cd2522

Please sign in to comment.