Commit 825b9881 authored by Vincent Michel's avatar Vincent Michel
Browse files

Update file API

parent 8473a1c4
Pipeline #943 failed with stages
in 1 minute and 4 seconds
......@@ -409,13 +409,14 @@ def get_handel_version():
def get_config_files(path):
"""Return all the ini files in path (including subdirectories)."""
ext = b'.ini' if isinstance(path, bytes) else '.ini'
return [os.path.join(dp, f)
return [os.path.join(dp, f).lstrip(path).lstrip('/')
for dp, dn, fn in os.walk(path)
for f in fn
if f.endswith(ext)]
def get_config(filename):
def get_config(path, filename):
"""Read and return the given config file as a dictionary."""
filename = os.path.join(path, filename)
with open(filename) as f:
return parse_xia_ini_file(f.read())
......@@ -491,13 +491,21 @@ def test_get_handel_version(interface):
# Files
def test_get_config_files(interface):
assert interface.get_config_files('.') == ['./scripts/mercury.ini']
assert interface.get_config_files(b'.') == [b'./scripts/mercury.ini']
assert interface.get_config_files('.') == ['scripts/mercury.ini']
assert interface.get_config_files(b'.') == [b'scripts/mercury.ini']
def test_get_config(interface):
# Using string paths
filename = interface.get_config_files('.')[0]
conf = interface.get_config(filename)
conf = interface.get_config('.', filename)
assert conf['detector definitions'][0]['alias'] == 'detector1'
with pytest.raises(IOError):
interface.get_config('i_dont_exist.ini')
interface.get_config('.', 'i_dont_exist.ini')
# Using bytestring paths
filename = interface.get_config_files(b'.')[0]
conf = interface.get_config(b'.', filename)
assert conf['detector definitions'][0]['alias'] == 'detector1'
with pytest.raises(IOError):
interface.get_config(b'.', b'i_dont_exist.ini')
......@@ -53,10 +53,10 @@ END #1
def test_invalid_line():
content = 'hello world!'
content = 'hello!'
with pytest.raises(ValueError) as ctx:
parse(content)
assert 'Line not recognized' in str(ctx.value)
assert "Line not recognized: 'hello!'" in str(ctx.value)
def test_item_outside_of_section():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment