Skip to content

Commit e9b2024

Browse files
committed
[test] Cleanup written odml.cache files
Closes #381
1 parent 2876c13 commit e9b2024

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

test/test_doc.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import unittest
44

5+
from glob import glob
6+
57
try:
68
from urllib.request import pathname2url
79
except ImportError:
@@ -10,11 +12,23 @@
1012
from odml import Document, Section, Property
1113
from odml.doc import BaseDocument
1214
from odml.dtypes import FORMAT_DATE
15+
from .util import ODML_CACHE_DIR as CACHE_DIR
1316

1417

1518
class TestSection(unittest.TestCase):
1619
def setUp(self):
17-
pass
20+
self.local_repo_file = "local_repository_file_v1.1.xml"
21+
22+
def tearDown(self):
23+
"""
24+
Remove all files loaded to the terminology cache directory
25+
to avoid test cross pollution.
26+
"""
27+
temp_file_glob = "*%s" % self.local_repo_file
28+
find_us = os.path.join(CACHE_DIR, temp_file_glob)
29+
30+
for file_path in glob(find_us):
31+
os.remove(file_path)
1832

1933
def test_simple_attributes(self):
2034
author = "HPL"
@@ -96,7 +110,7 @@ def test_date(self):
96110

97111
def test_get_terminology_equivalent(self):
98112
dir_path = os.path.dirname(os.path.realpath(__file__))
99-
repo_file = os.path.join(dir_path, "resources", "local_repository_file_v1.1.xml")
113+
repo_file = os.path.join(dir_path, "resources", self.local_repo_file)
100114
local_url = "file://%s" % pathname2url(repo_file)
101115

102116
doc = Document(repository=local_url)

test/test_terminology.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from urllib import pathname2url
1616

1717
from odml import Document, save, Section, terminology
18-
19-
CACHE_DIR = os.path.join(tempfile.gettempdir(), "odml.cache")
18+
from .util import ODML_CACHE_DIR as CACHE_DIR
2019

2120

2221
class TestTerminology(unittest.TestCase):

test/test_version_converter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import unittest
66

77
from contextlib import contextmanager
8+
from glob import glob
89
from lxml import etree as ET
910

1011
from odml.terminology import REPOSITORY_BASE
1112
from odml.tools.converters import VersionConverter
13+
from .util import ODML_CACHE_DIR as CACHE_DIR
1214

1315
try:
1416
unicode = unicode
@@ -52,9 +54,16 @@ def setUp(self):
5254
self.tmp_dir = None
5355

5456
def tearDown(self):
57+
"""
58+
Cleanup any created temporary files.
59+
"""
5560
if self.tmp_dir and os.path.exists(self.tmp_dir):
5661
shutil.rmtree(self.tmp_dir)
5762

63+
find_us = os.path.join(CACHE_DIR, "*local_repository_file_v1*")
64+
for file_path in glob(find_us):
65+
os.remove(file_path)
66+
5867
@contextmanager
5968
def assertNotRaises(self, exc_type):
6069
try:

0 commit comments

Comments
 (0)