File tree 4 files changed +23
-3
lines changed
Filter options
4 files changed +23
-3
lines changed
Original file line number Diff line number Diff line change 11
11
12
12
13
13
if PYVERSION >= (3 , 0 , 0 ):
14
- from configparser import ConfigParser
14
+ from configparser import ConfigParser , NoOptionError
15
15
text_type = str
16
16
else :
17
- from ConfigParser import SafeConfigParser as ConfigParser
17
+ from ConfigParser import SafeConfigParser as ConfigParser , NoOptionError
18
18
text_type = unicode
19
19
20
20
if PYVERSION >= (3 , 2 , 0 ):
@@ -134,7 +134,10 @@ def __contains__(self, key):
134
134
self .parser .has_option (self .SECTION , key ))
135
135
136
136
def __getitem__ (self , key ):
137
- return self .parser .get (self .SECTION , key )
137
+ try :
138
+ return self .parser .get (self .SECTION , key )
139
+ except NoOptionError :
140
+ raise KeyError (key )
138
141
139
142
140
143
class RepositoryEnv (RepositoryEmpty ):
Original file line number Diff line number Diff line change @@ -136,3 +136,7 @@ def test_env_with_quote(config):
136
136
assert '"Y"' == config ('KeyHasTwoDoubleQuote' )
137
137
assert '''"Y\' ''' == config ('KeyHasMixedQuotesAsData1' )
138
138
assert '''\' Y"''' == config ('KeyHasMixedQuotesAsData2' )
139
+
140
+ def test_env_repo_keyerror (config ):
141
+ with pytest .raises (KeyError ):
142
+ config .repository ['UndefinedKey' ]
Original file line number Diff line number Diff line change @@ -121,3 +121,8 @@ def test_ini_undefined_but_present_in_os_environ(config):
121
121
122
122
def test_ini_empty_string_means_false (config ):
123
123
assert False is config ('KeyEmpty' , cast = bool )
124
+
125
+
126
+ def test_ini_repo_keyerror (config ):
127
+ with pytest .raises (KeyError ):
128
+ config .repository ['UndefinedKey' ]
Original file line number Diff line number Diff line change 1
1
# coding: utf-8
2
2
import os
3
+ import pytest
3
4
4
5
from decouple import Config , RepositorySecret
5
6
@@ -28,3 +29,10 @@ def test_secret_overriden_by_environ():
28
29
os .environ ['db_user' ] = 'hi'
29
30
assert 'hi' == config ('db_user' )
30
31
del os .environ ['db_user' ]
32
+
33
+ def test_secret_repo_keyerror ():
34
+ path = os .path .join (os .path .dirname (__file__ ), 'secrets' )
35
+ repo = RepositorySecret (path )
36
+
37
+ with pytest .raises (KeyError ):
38
+ repo ['UndefinedKey' ]
You can’t perform that action at this time.
0 commit comments