Closes #48
This commit is contained in:
parent
335292f03b
commit
25559d53ff
2 changed files with 13 additions and 9 deletions
|
|
@ -7,7 +7,7 @@ def _glymurrc_fname():
|
|||
|
||||
Search order:
|
||||
1) current working directory
|
||||
2) environ var GLYMURCONFIGDIR
|
||||
2) environ var XDG_CONFIG_HOME
|
||||
3) $HOME/.config/glymur/glymurrc
|
||||
"""
|
||||
|
||||
|
|
@ -63,11 +63,11 @@ def _get_configdir():
|
|||
"""Return string representing the configuration directory.
|
||||
|
||||
Default is $HOME/.config/glymur. You can override this with the
|
||||
GLYMURCONFIGDIR environment variable.
|
||||
XDG_CONFIG_HOME environment variable.
|
||||
"""
|
||||
|
||||
if 'GLYMURCONFIGDIR' in os.environ:
|
||||
return os.environ['GLYMURCONFIGDIR']
|
||||
if 'XDG_CONFIG_HOME' in os.environ:
|
||||
return os.path.join(os.environ['XDG_CONFIG_HOME'], 'glymur')
|
||||
|
||||
if 'HOME' in os.environ:
|
||||
return os.path.join(os.environ['HOME'], '.config', 'glymur')
|
||||
|
|
|
|||
|
|
@ -599,13 +599,15 @@ class TestJp2k(unittest.TestCase):
|
|||
def test_config_file_via_environ(self):
|
||||
"""Verify that we can read a configuration file set via environ var."""
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
filename = os.path.join(tdir, 'glymurrc')
|
||||
configdir = os.path.join(tdir, 'glymur')
|
||||
os.mkdir(configdir)
|
||||
filename = os.path.join(configdir, 'glymurrc')
|
||||
with open(filename, 'wb') as tfile:
|
||||
tfile.write('[library]\n'.encode())
|
||||
line = 'openjp2: {0}\n'.format(glymur._OPENJP2._name)
|
||||
tfile.write(line.encode())
|
||||
tfile.flush()
|
||||
with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}):
|
||||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||
imp.reload(glymur)
|
||||
j = Jp2k(self.jp2file)
|
||||
|
||||
|
|
@ -614,13 +616,15 @@ class TestJp2k(unittest.TestCase):
|
|||
def test_config_file_via_environ_is_wrong(self):
|
||||
# A non-existant library location should be rejected.
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
fname = os.path.join(tdir, 'glymurrc')
|
||||
configdir = os.path.join(tdir, 'glymur')
|
||||
os.mkdir(configdir)
|
||||
fname = os.path.join(configdir, 'glymurrc')
|
||||
with open(fname, 'w') as fp:
|
||||
with tempfile.NamedTemporaryFile(suffix='.dylib') as tfile:
|
||||
fp.write('[library]\n')
|
||||
fp.write('openjp2: {0}.not.there\n'.format(tfile.name))
|
||||
fp.flush()
|
||||
with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}):
|
||||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||
# Misconfigured new configuration file should
|
||||
# be rejected.
|
||||
with self.assertWarns(UserWarning) as cw:
|
||||
|
|
@ -632,7 +636,7 @@ class TestJp2k(unittest.TestCase):
|
|||
# Verify that we error out properly if the configuration file
|
||||
# specified via environment variable is not found.
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}):
|
||||
with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}):
|
||||
# Misconfigured new configuration file should
|
||||
# be rejected.
|
||||
with self.assertWarns(UserWarning) as cw:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue