Commit 047e5bae authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: test findConfigFile/Dirs

parent 8d7c7ec0
......@@ -105,6 +105,13 @@ def touch(path):
def mktree(filepaths):
for path in filepaths:
os.makedirs(op.dirname(path), exist_ok=True)
def gen_test_data(num_vars,
......@@ -5,14 +5,71 @@
# Author: Paul McCarthy <>
import os
import os.path as op
import multiprocessing as mp
from unittest import mock
import contextlib as ctxlib
import pytest
import funpack.util as util
from . import tempdir, patch_logging
from . import tempdir, patch_logging, mktree
def test_findConfigFile():
# cfgdirs are (in order of precedence):
# site.getsitepackages()
# dirname(funpack.util.__file__)
env = os.environ.copy()
with tempdir() as td, mock.patch.dict('os.environ', env, clear=True):
cfgdir = op.join(td, 'cfgdir')
sitedir = op.join(td, 'sitepack')
fpdir = op.join(td, 'fpdir')
cfgdircfg = op.join(cfgdir, 'myconfig.cfg')
sitedircfg = op.join(sitedir, 'funpack', 'configs', 'myconfig.cfg')
fpdircfg = op.join(fpdir, 'configs', 'myconfig.cfg')
cfgdirplg = op.join(cfgdir, '')
sitedirplg = op.join(sitedir, 'funpack', 'plugins', '')
fpdirplg = op.join(fpdir, 'plugins', '')
mktree((cfgdircfg, sitedircfg, fpdircfg,
cfgdirplg, sitedirplg, fpdirplg))
def mock_cfgdir():
with mock.patch.dict(os.environ, FUNPACK_CONFIG_DIR=cfgdir):
def mock_sitepackages():
with mock.patch('site.getsitepackages', return_value=[sitedir]):
def mock_funpack_dir():
utilfile = op.join(fpdir, '')
with mock.patch('funpack.util.__file__', utilfile):
with mock_funpack_dir():
assert util.findConfigFile('myconfig.cfg') == fpdircfg
assert util.findConfigFile('myconfig') == fpdircfg
assert util.findPluginFile('') == fpdirplg
assert util.findPluginFile('myplugin') == fpdirplg
with mock_funpack_dir(), mock_sitepackages():
assert util.findConfigFile('myconfig.cfg') == sitedircfg
assert util.findConfigFile('myconfig') == sitedircfg
assert util.findPluginFile('') == sitedirplg
assert util.findPluginFile('myplugin') == sitedirplg
with mock_funpack_dir(), mock_sitepackages(), mock_cfgdir():
assert util.findConfigFile('myconfig.cfg') == cfgdircfg
assert util.findConfigFile('myconfig') == cfgdircfg
assert util.findPluginFile('') == cfgdirplg
assert util.findPluginFile('myplugin') == cfgdirplg
def test_parseMatlabRange():
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment