Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Updating config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacBlanco committed Jul 21, 2016
1 parent 620236f commit 4601dfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 22 additions & 11 deletions demo_utils/demo_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#
# All params are read as strings

def read_config(configFile):
path = get_conf_dir() + configFile
def read_config(config_file):

if not os.path.isfile(path):
raise IOError('could not find file at ' + path )
path = get_path(config_file)

config = ConfigParser.ConfigParser()
config.read(path)
Expand All @@ -29,13 +27,8 @@ def read_config(configFile):

return params

def read_xml_config(configFile):

path = get_conf_dir() + configFile

if not os.path.isfile(path):
raise IOError('could not find file at ' + path )

def read_xml_config(config_file):
path = get_path(config_file)
config_root = ET.parse(path).getroot()
conf = {}
# Get all property elements
Expand All @@ -48,6 +41,24 @@ def read_xml_config(configFile):

return conf

# Raises an IOError if the file doesn't exist
# Returns the path to the file if it does
def get_path(config_file):
path = get_conf_dir() + config_file

exists = False

if os.path.isfile(path):
exists = True
elif os.path.isfile(config_file):
path = config_file
exists = True

if not exists:
raise IOError('Could not find file at ' + config_file + ' or ' + path)

return path

# returns a dict with dict['configurations'] containing
# another dict with a list of file names
# Under each filename is the parameters
Expand Down
4 changes: 2 additions & 2 deletions demo_utils/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def test_missing_file(self, mock1):
params = config.read_xml_config('nofile')
self.fail('Should have thrown IOError')
except IOError as e:
if 'could not find file' not in e.message:
if 'Could not find file' not in str(e):
assert 0

try:
params = config.read_xml_config('nofile')
self.fail('Should have thrown IOError')
except IOError as e:
if 'could not find file' not in e.message:
if 'Could not find file' not in str(e):
assert 0

@mock.patch('os.path.exists', return_value=False)
Expand Down

0 comments on commit 4601dfa

Please sign in to comment.