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

Commit

Permalink
Introducing test cases for missing files in XML configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacBlanco committed Jul 11, 2016
1 parent 1ef3364 commit 44e493a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
7 changes: 4 additions & 3 deletions package/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def get_config():
dir_entries = glob.glob(conf_dir + "*.xml" )
for conf_file in dir_entries:
if os.path.isfile(conf_file):
head, tail = os.path.split(conf_file)
path, filename = os.path.split(conf_file)
name = os.path.splitext(filename)[0]
try:
params = read_xml_config(tail)
params = read_xml_config(filename)
except IOError:
pass
conf['configurations'][tail] = params
conf['configurations'][name] = params

return conf

Expand Down
28 changes: 24 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ def test_missing_header(self, mock1):
def test_missing_file(self, mock1):
try:
params = config.read_config('nofile')
assert 0
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:
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:
assert 0
Expand Down Expand Up @@ -61,6 +69,20 @@ def test_xml_tree(self, mock1):
except IOError as e:
self.fail(e)


@mock.patch('package.util.config.get_conf_dir', return_value='')
@mock.patch('glob.glob', return_value=['test-config-1.xml', 'nofile', 'nofile2'])
def test_xml_tree(self, mock1, mock2):
try:
conf = config.read_xml_config('res/config/test-conf-1.xml')

assert len(conf['configurations'].keys()) == 1
for i in range(1, 5):
assert (conf['configurations']['test-config-1']['name.prop.' + str(i)] == 'val' + str(i))
except IOError as e:
self.fail(e)


@mock.patch('package.util.config.get_conf_dir', return_value='')
def test_bad_xml_tree(self, mock1):
try:
Expand All @@ -86,9 +108,7 @@ def test_bad_xml_tree(self, mock1):
def test_xml_tree(self, mock1):
try:
conf = config.get_config()
print(conf.keys())
print(conf['configurations'].keys())
files = ['test-conf-1.xml', 'test-conf-2.xml']
files = ['test-conf-1', 'test-conf-2']
for f in files:
for i in range(1, 5):
assert (conf['configurations'][f]['name.prop.' + str(i)] == 'val' + str(i))
Expand Down

0 comments on commit 44e493a

Please sign in to comment.