Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb22d11

Browse files
committed
Make globals private
1 parent 9ba81dd commit bb22d11

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,23 @@ def pytest_configure(config):
8080
IGNORED_TESTS['matplotlib'] += 'test_coding_standards'
8181
max_size = config.getoption('--conversion-cache-max-size')
8282
if max_size is not None:
83-
ccache.conversion_cache = \
84-
ccache.ConversionCache(max_size=int(max_size))
83+
ccache._conversion_cache = \
84+
ccache._ConversionCache(max_size=int(max_size))
8585
else:
86-
ccache.conversion_cache = ccache.ConversionCache()
86+
ccache._conversion_cache = ccache._ConversionCache()
8787
if config.pluginmanager.hasplugin('xdist'):
8888
config.pluginmanager.register(DeferPlugin())
8989

9090

9191
def pytest_unconfigure(config):
92-
ccache.conversion_cache.expire()
92+
ccache._conversion_cache.expire()
9393
matplotlib._called_from_pytest = False
9494

9595

9696
def pytest_sessionfinish(session):
9797
if hasattr(session.config, 'slaveoutput'):
98-
session.config.slaveoutput['cache-report'] = ccache.conversion_cache.report()
98+
session.config.slaveoutput['cache-report'] = \
99+
ccache._conversion_cache.report()
99100

100101

101102
def pytest_terminal_summary(terminalreporter):
@@ -107,7 +108,7 @@ def pytest_terminal_summary(terminalreporter):
107108
'gets': reduce(lambda x, y: x.union(y),
108109
(rep['gets'] for rep in reports))}
109110
else:
110-
data = ccache.conversion_cache.report()
111+
data = ccache._conversion_cache.report()
111112
tr.write_sep('=', 'Image conversion cache report')
112113
tr.write_line('Hit rate: %d/%d' % (len(data['hits']), len(data['gets'])))
113114
if tr.config.getoption('--conversion-cache-report-misses'):

lib/matplotlib/testing/_conversion_cache.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from matplotlib import checkdep_inkscape
2222

2323

24-
class ConversionCache(object):
24+
class _ConversionCache(object):
2525
"""A cache that stores png files converted from svg or pdf formats.
2626
2727
The image comparison test cases compare svg and pdf files by
@@ -180,7 +180,7 @@ def expire(self):
180180
def get_cache_dir():
181181
cachedir = _get_cachedir()
182182
if cachedir is None:
183-
raise CacheError('No suitable configuration directory')
183+
raise _CacheError('No suitable configuration directory')
184184
cachedir = os.path.join(cachedir, 'test_cache')
185185
return cachedir
186186

@@ -189,13 +189,14 @@ def ensure_cache_dir(self):
189189
try:
190190
cbook.mkdirs(self.cachedir)
191191
except IOError as e:
192-
raise CacheError("Error creating cache directory %s: %s"
193-
% (self.cachedir, str(e)))
192+
raise _CacheError("Error creating cache directory %s: %s"
193+
% (self.cachedir, str(e)))
194194
if not os.access(self.cachedir, os.W_OK):
195-
raise CacheError("Cache directory %s not writable" % self.cachedir)
195+
raise _CacheError("Cache directory %s not writable"
196+
% self.cachedir)
196197

197198

198-
class CacheError(Exception):
199+
class _CacheError(Exception):
199200
def __init__(self, message):
200201
self.message = message
201202

@@ -204,4 +205,4 @@ def __str__(self):
204205

205206

206207
# A global cache instance, set by the appropriate test runner.
207-
conversion_cache = None
208+
_conversion_cache = None

lib/matplotlib/testing/compare.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def comparable_formats():
121121
return ['png'] + list(converter)
122122

123123

124-
@cbook.deprecated('2.1', addendum='Use ConversionCache instead')
124+
@cbook.deprecated('2.1', addendum='Use _ConversionCache instead')
125125
def get_cache_dir():
126-
return ccache.ConversionCache.get_cache_dir()
126+
return ccache._ConversionCache.get_cache_dir()
127127

128128

129-
@cbook.deprecated('2.1', addendum='Use ConversionCache instead')
129+
@cbook.deprecated('2.1', addendum='Use _ConversionCache instead')
130130
def get_file_hash(path, block_size=2 ** 20):
131131
if path.endswith('.pdf'):
132132
from matplotlib import checkdep_ghostscript
@@ -136,7 +136,7 @@ def get_file_hash(path, block_size=2 ** 20):
136136
version_tag = checkdep_inkscape().encode('utf-8')
137137
else:
138138
version_tag = None
139-
return ccache.ConversionCache._get_file_hash_static(
139+
return ccache._ConversionCache._get_file_hash_static(
140140
path, block_size, version_tag)
141141

142142

@@ -148,7 +148,7 @@ def convert(filename, cache=None):
148148
Parameters
149149
----------
150150
filename : str
151-
cache : ConversionCache, optional
151+
cache : _ConversionCache, optional
152152
153153
Returns
154154
-------
@@ -256,7 +256,7 @@ def compare_images(expected, actual, tol, in_decorator=False, cache=None):
256256
in_decorator : bool
257257
If called from image_comparison decorator, this should be
258258
True. (default=False)
259-
cache : cache.ConversionCache, optional
259+
cache : matplotlib.testing._conversion_cache._ConversionCache, optional
260260
261261
Example
262262
-------

lib/matplotlib/tests/test_cache.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from nose.tools import raises
1414

1515
from matplotlib import cbook
16-
from matplotlib.testing.conversion_cache import ConversionCache, CacheError
16+
from matplotlib.testing._conversion_cache import _ConversionCache, _CacheError
1717

1818

1919
def test_cache_basic():
@@ -22,7 +22,7 @@ def test_cache_basic():
2222
def intmp(f):
2323
return os.path.join(tmpdir, f)
2424
try:
25-
cache = ConversionCache(intmp('cache'))
25+
cache = _ConversionCache(intmp('cache'))
2626
with open(intmp('fake.pdf'), 'w') as pdf:
2727
pdf.write('this is a fake pdf file')
2828
with open(intmp('fake.svg'), 'w') as svg:
@@ -63,7 +63,7 @@ def test_cache_expire():
6363
def intmp(*f):
6464
return os.path.join(tmpdir, *f)
6565
try:
66-
cache = ConversionCache(intmp('cache'), 10)
66+
cache = _ConversionCache(intmp('cache'), 10)
6767
for i in range(5):
6868
filename = intmp('cache', 'file%d.png' % i)
6969
with open(filename, 'w') as f:
@@ -95,9 +95,9 @@ def intmp(*f):
9595

9696
def test_cache_default_dir():
9797
try:
98-
path = ConversionCache.get_cache_dir()
98+
path = _ConversionCache.get_cache_dir()
9999
assert path.endswith('test_cache')
100-
except CacheError:
100+
except _CacheError:
101101
pass
102102

103103

@@ -107,7 +107,7 @@ def test_cache_default_dir():
107107
def test_cache_mkdir_error(mkdirs):
108108
tmpdir = tempfile.mkdtemp()
109109
try:
110-
c = ConversionCache(os.path.join(tmpdir, 'cache'))
110+
c = _ConversionCache(os.path.join(tmpdir, 'cache'))
111111
finally:
112112
shutil.rmtree(tmpdir)
113113

@@ -120,6 +120,6 @@ def test_cache_unwritable_error(access):
120120
cachedir = os.path.join(tmpdir, 'test_cache')
121121
try:
122122
cbook.mkdirs(cachedir)
123-
c = ConversionCache(cachedir)
123+
c = _ConversionCache(cachedir)
124124
finally:
125125
shutil.rmtree(tmpdir)

0 commit comments

Comments
 (0)