Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
ukbparse
Commits
413c3611
Commit
413c3611
authored
May 09, 2019
by
Paul McCarthy
🚵
Browse files
TEST: Test description file generation
parent
2bb4cd31
Changes
1
Hide whitespace changes
Inline
Side-by-side
ukbparse/tests/test_main.py
View file @
413c3611
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#
#
import
textwrap
as
tw
import
textwrap
as
tw
import
itertools
as
it
import
os.path
as
op
import
os.path
as
op
import
os
import
os
import
shlex
import
shlex
...
@@ -1609,3 +1610,82 @@ def test_main_argparse_bug_workaround():
...
@@ -1609,3 +1610,82 @@ def test_main_argparse_bug_workaround():
assert
np
.
all
(
got
[
'1-0.0'
]
==
range
(
11
,
16
))
assert
np
.
all
(
got
[
'1-0.0'
]
==
range
(
11
,
16
))
assert
np
.
all
(
got
[
'2-0.0'
]
==
range
(
-
11
,
-
16
,
-
1
))
assert
np
.
all
(
got
[
'2-0.0'
]
==
range
(
-
11
,
-
16
,
-
1
))
@
patch_logging
def
test_main_description_file
():
vartable
=
tw
.
dedent
(
"""
ID
\t
Type
\t
Description
\t
DataCoding
\t
NAValues
\t
RawLevels
\t
NewLevels
\t
ParentValues
\t
ChildValues
\t
Clean
1
\t\t
var one
2
\t\t
var two
3
\t\t
var three
4
"""
).
strip
()
proctable
=
tw
.
dedent
(
"""
Variable
\t
Process
1
\t
myprocess
2
\t
myprocess(metaproc='mymetaproc')
"""
)
@
custom
.
processor
()
def
myprocess
(
dtable
,
vids
):
columns
=
it
.
chain
(
*
[
dtable
.
columns
(
v
)
for
v
in
vids
])
add
=
[]
addvid
=
[]
addmeta
=
[]
for
col
in
columns
:
series
=
dtable
[:,
col
.
name
]
col
.
metadata
=
col
.
vid
+
20
newseries
=
pd
.
Series
(
series
+
5
,
name
=
col
.
name
+
'_a'
)
dtable
[:,
col
.
name
]
=
dtable
[:,
col
.
name
]
+
3
add
.
append
(
newseries
)
addvid
.
append
(
col
.
vid
)
addmeta
.
append
(
col
.
vid
+
40
)
return
[],
add
,
addvid
,
addmeta
@
custom
.
metaproc
()
def
mymetaproc
(
val
):
return
str
(
val
)
+
' metaprocced'
with
tempdir
():
with
open
(
'vartable.tsv'
,
'wt'
)
as
f
:
f
.
write
(
vartable
)
with
open
(
'proctable.tsv'
,
'wt'
)
as
f
:
f
.
write
(
proctable
)
gen_test_data
(
4
,
10
,
'data.tsv'
)
main
.
main
(
'-nb -vf vartable.tsv -pf proctable.tsv '
'-def descriptions.tsv '
'out.tsv data.tsv'
.
split
())
inp
=
pd
.
read_csv
(
'data.tsv'
,
delimiter
=
'
\t
'
,
index_col
=
0
)
got
=
pd
.
read_csv
(
'out.tsv'
,
delimiter
=
'
\t
'
,
index_col
=
0
)
descs
=
pd
.
read_csv
(
'descriptions.tsv'
,
delimiter
=
'
\t
'
,
index_col
=
0
,
header
=
None
,
names
=
(
'column'
,
'description'
))
assert
all
(
got
.
columns
==
[
'1-0.0'
,
'1-0.0_a'
,
'2-0.0'
,
'2-0.0_a'
,
'3-0.0'
,
'4-0.0'
])
assert
(
got
[
'1-0.0'
]
==
(
inp
[
'1-0.0'
]
+
3
)).
all
()
assert
(
got
[
'1-0.0_a'
]
==
(
inp
[
'1-0.0'
]
+
5
)).
all
()
assert
(
got
[
'2-0.0'
]
==
(
inp
[
'2-0.0'
]
+
3
)).
all
()
assert
(
got
[
'2-0.0_a'
]
==
(
inp
[
'2-0.0'
]
+
5
)).
all
()
assert
(
got
[
'3-0.0'
]
==
(
inp
[
'3-0.0'
]))
.
all
()
assert
(
got
[
'4-0.0'
]
==
(
inp
[
'4-0.0'
]))
.
all
()
assert
descs
.
loc
[
'1-0.0'
,
'description'
]
==
'var one (21)'
assert
descs
.
loc
[
'1-0.0_a'
,
'description'
]
==
'var one (41)'
assert
descs
.
loc
[
'2-0.0'
,
'description'
]
==
'var two (22)'
assert
descs
.
loc
[
'2-0.0_a'
,
'description'
]
==
'var two (42 metaprocced)'
assert
descs
.
loc
[
'3-0.0'
,
'description'
]
==
'var three (0.0)'
assert
descs
.
loc
[
'4-0.0'
,
'description'
]
==
'n/a (0.0)'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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