Type : CREATION_INTERNE
Todos los datos y archivos de prueba se generan dinámicamente en el directorio WORK o en un subdirectorio temporal ('zipme') durante la ejecución del script.
| 1 | %let work=%sysfunc(pathname(work)); |
| 2 | %let root=&work/zipme; |
| 3 | |
| 4 | /* TEST 1 - zip a file */ |
| 5 | %mf_mkdir(&root) |
| 6 | |
| 7 | DATA _null_; |
| 8 | file "&root/test.txt"; |
| 9 | put "houston, this is a test"; |
| 10 | RUN; |
| 1 | %mp_zip(in=&root/test.txt |
| 2 | ,type=FILE |
| 3 | ,outpath=&work |
| 4 | ,outname=myFile |
| 5 | ) |
| 6 | |
| 7 | %mp_unzip(ziploc="&work/myFile.zip",outdir=&work) |
| 8 | |
| 9 | DATA _null_; |
| 10 | INFILE "&work/test.txt"; |
| 11 | INPUT; |
| 12 | call symputx('content1',_infile_); |
| 13 | putlog _infile_; |
| 14 | RUN; |
| 15 | |
| 16 | %mp_assert( |
| 17 | iftrue=( |
| 18 | %str(&content1)=%str(houston, this is a test) |
| 19 | ), |
| 20 | desc=Checking IF file zip / unzip works, |
| 21 | outds=work.test_results |
| 22 | ) |
| 1 | /* TEST 2 - zip a dataset of files */ |
| 2 | DATA _null_; |
| 3 | file "&root/test2.txt"; |
| 4 | put "houston, this is test2"; |
| 5 | RUN; |
| 6 | LIBNAME tmp "&root"; |
| 7 | DATA tmp.test; |
| 8 | filepath="&root/test2.txt"; |
| 9 | RUN; |
| 1 | %mp_zip(in=tmp.test |
| 2 | ,incol=filepath |
| 3 | ,type=DATASET |
| 4 | ,outpath=&work |
| 5 | ,outname=myFile2 |
| 6 | ) |
| 7 | |
| 8 | %mp_unzip(ziploc="&work/myFile2.zip",outdir=&work) |
| 9 | |
| 10 | DATA _null_; |
| 11 | INFILE "&work/test2.txt"; |
| 12 | INPUT; |
| 13 | call symputx('content2',_infile_); |
| 14 | putlog _infile_; |
| 15 | RUN; |
| 16 | |
| 17 | %mp_assert( |
| 18 | iftrue=( |
| 19 | %str(&content2)=%str(houston, this is test2) |
| 20 | ), |
| 21 | desc=Checking IF file zip / unzip from a dataset works, |
| 22 | outds=work.test_results |
| 23 | ) |
| 1 | /* TEST 3 - zip a dataset of files */ |
| 2 | %mf_mkdir(&work/out3) |
| 3 | |
| 4 | %mp_zip(in=&root |
| 5 | ,type=DIRECTORY |
| 6 | ,outpath=&work |
| 7 | ,outname=myFile3 |
| 8 | ) |
| 9 | |
| 10 | %mp_unzip(ziploc="&work/myFile3.zip",outdir=&work/out3) |
| 11 | |
| 12 | DATA _null_; |
| 13 | INFILE "&work/out3/test.txt"; |
| 14 | INPUT; |
| 15 | call symputx('content3a',_infile_); |
| 16 | putlog _infile_; |
| 17 | RUN; |
| 18 | DATA _null_; |
| 19 | INFILE "&work/out3/test2.txt"; |
| 20 | INPUT; |
| 21 | call symputx('content3b',_infile_); |
| 22 | putlog _infile_; |
| 23 | RUN; |
| 24 | |
| 25 | %mp_assert( |
| 26 | iftrue=( |
| 27 | %str(&content3a)=%str(houston, this is a test) |
| 28 | and |
| 29 | %str(&content3b)=%str(houston, this is test2) |
| 30 | ), |
| 31 | desc=Checking IF file zip / unzip from a directory works, |
| 32 | outds=work.test_results |
| 33 | ) |