File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ Configuration
1414Files
1515-----
1616
17- ``gitlab `` looks up 2 configuration files by default:
17+ ``gitlab `` looks up 3 configuration files by default:
18+
19+ ``PYTHON_GITLAB_CFG `` environment variable
20+ An environment variable that contains the path to a configuration file
1821
1922``/etc/python-gitlab.cfg ``
2023 System-wide configuration file
Original file line number Diff line number Diff line change 1818import os
1919import configparser
2020
21- _DEFAULT_FILES = ["/etc/python-gitlab.cfg" , os .path .expanduser ("~/.python-gitlab.cfg" )]
21+
22+ def _env_config ():
23+ if "PYTHON_GITLAB_CFG" in os .environ :
24+ return [os .environ ["PYTHON_GITLAB_CFG" ]]
25+ return []
26+
27+
28+ _DEFAULT_FILES = _env_config () + [
29+ "/etc/python-gitlab.cfg" ,
30+ os .path .expanduser ("~/.python-gitlab.cfg" ),
31+ ]
2232
2333
2434class ConfigError (Exception ):
Original file line number Diff line number Diff line change 1515# You should have received a copy of the GNU Lesser General Public License
1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18+ import os
1819import unittest
1920
2021import mock
7273"""
7374
7475
76+ class TestEnvConfig (unittest .TestCase ):
77+ def test_env_present (self ):
78+ with mock .patch .dict (os .environ , {"PYTHON_GITLAB_CFG" : "/some/path" }):
79+ self .assertEqual (["/some/path" ], config ._env_config ())
80+
81+ def test_env_missing (self ):
82+ with mock .patch .dict (os .environ , {}, clear = True ):
83+ self .assertEqual ([], config ._env_config ())
84+
85+
7586class TestConfigParser (unittest .TestCase ):
7687 @mock .patch ("os.path.exists" )
7788 def test_missing_config (self , path_exists ):
You can’t perform that action at this time.
0 commit comments