Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
python-handel
Commits
825b9881
Commit
825b9881
authored
Sep 08, 2017
by
Vincent Michel
Browse files
Update file API
parent
8473a1c4
Pipeline
#943
failed with stages
in 1 minute and 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
handel/interface.py
View file @
825b9881
...
...
@@ -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
())
tests/test_interface.py
View file @
825b9881
...
...
@@ -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'
)
tests/test_parser.py
View file @
825b9881
...
...
@@ -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
():
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment