Skip to content

Commit

Permalink
Moving extra datatypes to be added to BaseDatatype subclasses. (#799)
Browse files Browse the repository at this point in the history
* Moving extra datatypes to be added to BaseDatatype subclasses.

* Using direct import to avoid circular dependencies.

* Add unit test

---------

Co-authored-by: Lukas Rajala <[email protected]>
Co-authored-by: Myst <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2024
1 parent 051fd84 commit 8612c78
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
25 changes: 25 additions & 0 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ def test_mediainfo():
assert mediainfo_item_by_id.id == 'M75908279'


def test_entity_in_basedatatype():
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'commonsMedia']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'entity-schema']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'external-id']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'wikibase-form']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'geo-shape']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'globe-coordinate']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'wikibase-item']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'wikibase-lexeme']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'math']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'monolingualtext']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'musical-notation']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'wikibase-property']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'quantity']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'wikibase-sense']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'string']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'tabular-data']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'time']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'url']) == 1

# Extra datatypes
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'edtf']) == 1
assert len([x for x in BaseDataType.subclasses if x.DTYPE == 'localMedia']) == 1


def test_wikibaseintegrator():
nwbi = WikibaseIntegrator(is_bot=False)
assert nwbi.item.api.is_bot is False
Expand Down
5 changes: 5 additions & 0 deletions wikibaseintegrator/datatypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
from .tabulardata import TabularData
from .time import Time
from .url import URL

# Extra datatypes
# isort: off
from .extra import EDTF
from .extra import LocalMedia
2 changes: 1 addition & 1 deletion wikibaseintegrator/datatypes/extra/edtf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from wikibaseintegrator.datatypes import String
from wikibaseintegrator.datatypes.string import String


class EDTF(String):
Expand Down
2 changes: 1 addition & 1 deletion wikibaseintegrator/datatypes/extra/localmedia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from wikibaseintegrator.datatypes import String
from wikibaseintegrator.datatypes.string import String


class LocalMedia(String):
Expand Down

0 comments on commit 8612c78

Please sign in to comment.