-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding initial test for import format.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright © 2024 Wacom. All rights reserved. | ||
from unittest import TestCase | ||
|
||
from faker import Faker | ||
|
||
from knowledge.base.entity import Label, USE_NEL_TAG, LABELS_TAG | ||
from knowledge.base.language import EN_US, SUPPORTED_LOCALES | ||
from knowledge.base.ontology import OntologyClassReference, ThingObject | ||
|
||
THING_OBJECT: OntologyClassReference = OntologyClassReference('wacom', 'core', 'Thing') | ||
|
||
|
||
class ImportFlow(TestCase): | ||
""" | ||
Import Flow | ||
---------- | ||
Test the import format flow | ||
""" | ||
|
||
def test_import_use_nel(self): | ||
""" | ||
Test Import Use Nel. | ||
""" | ||
faker: Faker = Faker(EN_US) | ||
entity: ThingObject = ThingObject( | ||
label=[ | ||
Label( | ||
content=faker.word(), | ||
language_code=EN_US, | ||
main=True)], | ||
concept_type=THING_OBJECT, | ||
use_for_nel=False) | ||
|
||
entity_dict = entity.__import_format_dict__() | ||
self.assertEqual(entity_dict[USE_NEL_TAG], entity.use_for_nel) | ||
new_entity = ThingObject.from_import_dict(entity_dict) | ||
self.assertEqual(new_entity.use_for_nel, entity.use_for_nel) | ||
|
||
def test_labels_import(self): | ||
""" | ||
Test Labels Import | ||
""" | ||
entity: ThingObject = ThingObject() | ||
for locale in SUPPORTED_LOCALES: | ||
faker: Faker = Faker(locale) | ||
entity.add_label(label=faker.word(), language_code=locale) | ||
for _ in range(3): | ||
entity.add_alias(alias=faker.word(), language_code=locale) | ||
entity_dict = entity.__import_format_dict__() | ||
self.assertEqual(len(entity_dict[LABELS_TAG]), len(entity.label) + len(entity.alias)) | ||
new_entity = ThingObject.from_import_dict(entity_dict) | ||
self.assertEqual(len(new_entity.label), len(entity.label)) | ||
self.assertEqual(len(new_entity.alias), len(entity.alias)) | ||
|
||
|