diff --git a/glymur/__init__.py b/glymur/__init__.py index 29e8cc4..3525b6a 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -16,24 +16,15 @@ def _glymurrc_fname(): if os.path.exists(fname): return fname - # environ var GLYMURCONFIGDIR - if 'GLYMURCONFIGDIR' in os.environ: - path = os.environ['GLYMURCONFIGDIR'] - if os.path.exists(path): - fname = os.path.join(path, 'glymurrc') - if os.path.exists(fname): - return fname - else: - msg = "glymurrc file hinted at by GLYMURCONFIGDIR does not " - msg += "exist." - warnings.warn(msg, UserWarning) - - # HOME/.glymur/glymurrc + # Either GLYMURCONFIGDIR/glymurrc or $HOME/.glymur/glymurrc confdir = _get_configdir() if confdir is not None: - fname = os.path.join(_get_configdir(), 'glymurrc') + fname = os.path.join(confdir, 'glymurrc') if os.path.exists(fname): return fname + else: + msg = "Configuration file '{0}' does not exist.".format(confdir) + warnings.warn(msg, UserWarning) # didn't find a configuration file. return None diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 5234e0b..49abd9f 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -597,6 +597,17 @@ class TestJp2k(unittest.TestCase): with self.assertWarns(UserWarning) as cw: imp.reload(glymur) + @unittest.skipIf(sys.hexversion < 0x03020000, + "Uses features introduced in 3.2.") + def test_home_dir_missing_config_dir(self): + # Verify no exception is raised if $HOME is missing .glymur directory. + with tempfile.TemporaryDirectory() as tdir: + with patch.dict('os.environ', {'HOME': tdir}): + # Misconfigured new configuration file should + # be rejected. + with self.assertWarns(UserWarning) as cw: + imp.reload(glymur) + if __name__ == "__main__": unittest.main()