Skip to content

Commit 531581f

Browse files
committed
[test_doc.py] Add Test for Terminologies Cache Refresh
1 parent e96cd41 commit 531581f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test_doc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import datetime
22
import os
33
import unittest
4+
import tempfile
5+
import odml.terminology
6+
from hashlib import md5
47
try:
58
from urllib.request import pathname2url
69
except ImportError:
@@ -109,6 +112,34 @@ def test_get_terminology_equivalent(self):
109112
doc.repository = None
110113
self.assertIsNone(doc.get_terminology_equivalent())
111114

115+
def test_terminology_refresh(self):
116+
117+
cache_dir = os.path.join(tempfile.gettempdir(), "odml.cache")
118+
url = "https://terminologies.g-node.org/v1.1/terminologies.xml"
119+
term_doc = odml.terminology.load(url)
120+
121+
terms = []
122+
for sec in term_doc.sections:
123+
terms += ['.'.join([md5(sec.include.encode()).hexdigest(), os.path.basename(sec.include)])]
124+
125+
before = datetime.datetime.now()
126+
127+
for loaded_file in os.listdir(cache_dir):
128+
for term in terms:
129+
if term in loaded_file:
130+
assert datetime.datetime.fromtimestamp(
131+
os.path.getmtime(os.path.join(cache_dir, loaded_file))) < before
132+
133+
odml.terminology.refresh(url)
134+
135+
for replaced_file in os.listdir(cache_dir):
136+
for term in terms:
137+
if term in replaced_file:
138+
assert datetime.datetime.fromtimestamp(
139+
os.path.getmtime(os.path.join(cache_dir, replaced_file))) > before
140+
141+
142+
112143
def test_append(self):
113144
doc = Document()
114145
self.assertListEqual(doc.sections, [])

0 commit comments

Comments
 (0)