-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_excel_context_context_only.py
58 lines (48 loc) · 2.17 KB
/
test_excel_context_context_only.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import warnings
warnings.filterwarnings("ignore")
import unittest
import os
import pandas as pd
import json
import sys
if os.path.isfile('./db.sqlite'):
os.remove('./db.sqlite')
import __main__
__main__.CIDS_URL = 'http://ontology.commonapproach.org/owl/cids_v2.1.owl'
__main__.LOG_FILE = f"./logs/logs.txt" # Log file used to log errors or warnings that should not stop the processing (e.g. invalid address is found)
if os.path.exists(__main__.LOG_FILE):
os.remove(__main__.LOG_FILE)
__main__.INPUT_FILE = './tests/ExceltoJSONTemplate-test.xlsx'
__main__.CIDS_URL = 'http://ontology.commonapproach.org/owl/cids_v2.1.owl'
__main__.CONTEXT_PATH = "https://ontology.commonapproach.org/contexts/cidsContext.json"
JSON_OUTPATH = './tests/output.json'
class TestExcelContextContextOnly(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.input_path=__main__.INPUT_FILE
cls.json_out_path=JSON_OUTPATH
cls.xls = pd.ExcelFile(cls.input_path)
def test_load_organization_replace_prefix_context_only(self):
from src.utils.contexts import load_context_mapping
__main__.MAPPING_CONTEXT, _ = load_context_mapping(path=__main__.CONTEXT_PATH)
__main__.REPLACE_PREFIX = 'context_only'
from src.generators.organization import generate_organization
from src.map_data import load_indicators
from src.map_data import load_uris
from src.utils.utils import global_db
global_db = {}
_=load_uris(input_path=__main__.INPUT_FILE)
_ = generate_organization(input_path=__main__.INPUT_FILE)
_=load_indicators(input_path=__main__.INPUT_FILE)
from src.utils.utils import db_to_json
from src.utils.utils import global_db
global_db_hold = global_db.copy()
objects = db_to_json(dict_db=global_db_hold)
orgs = [o for o in objects if o['@type'] == 'cids:Organization']
self.assertEqual(len(orgs), 1)
org = orgs[0]
self.assertIsNone(org.get('org:hasLegalName'))
self.assertIsNotNone(org.get('hasLegalName'))
self.assertEqual(org['hasLegalName'], 'Test Organization Name')
if __name__ == '__main__':
unittest.main(exit=False)