Skip to content

Commit

Permalink
[test_doc.py] Add Test for Terminologies Cache Refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
fschrader1992 committed Apr 8, 2020
1 parent 9ee7b57 commit c65ecaa
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/test_doc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import datetime
import os
import unittest
import odml.terminology
import tempfile
from hashlib import md5
try:
from urllib.request import pathname2url
except ImportError:
Expand Down Expand Up @@ -109,6 +112,32 @@ def test_get_terminology_equivalent(self):
doc.repository = None
self.assertIsNone(doc.get_terminology_equivalent())

def test_terminology_refresh(self):

cache_dir = os.path.join(tempfile.gettempdir(), "odml.cache")
url = "https://terminologies.g-node.org/v1.1/terminologies.xml"
term_doc = odml.terminology.load(url)

terms = []
for sec in term_doc.sections:
terms += ['.'.join([md5(sec.include.encode()).hexdigest(), os.path.basename(sec.include)])]

before = datetime.datetime.now()

for loaded_file in os.listdir(cache_dir):
for term in terms:
if term in loaded_file:
assert datetime.datetime.fromtimestamp(
os.path.getmtime(os.path.join(cache_dir, loaded_file))) < before

odml.terminology.refresh(url)

for replaced_file in os.listdir(cache_dir):
for term in terms:
if term in replaced_file:
assert datetime.datetime.fromtimestamp(
os.path.getmtime(os.path.join(cache_dir, replaced_file))) > before

def test_append(self):
doc = Document()
self.assertListEqual(doc.sections, [])
Expand Down

0 comments on commit c65ecaa

Please # to comment.