Commit 413c3611 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: Test description file generation

parent 2bb4cd31
......@@ -6,6 +6,7 @@
#
import textwrap as tw
import itertools as it
import os.path as op
import os
import shlex
......@@ -1609,3 +1610,82 @@ def test_main_argparse_bug_workaround():
assert np.all(got['1-0.0'] == range( 11, 16))
assert np.all(got['2-0.0'] == range(-11, -16, -1))
@patch_logging
def test_main_description_file():
vartable = tw.dedent("""
ID\tType\tDescription\tDataCoding\tNAValues\tRawLevels\tNewLevels\tParentValues\tChildValues\tClean
1\t\tvar one
2\t\tvar two
3\t\tvar three
4
""").strip()
proctable = tw.dedent("""
Variable\tProcess
1\tmyprocess
2\tmyprocess(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)'
Supports Markdown
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