1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-10 22:14:35 +00:00

fix: removing notes when running mp_zip, closes #88. .

Also adding 3 tests
This commit is contained in:
Allan Bowe
2021-11-18 18:21:43 +00:00
parent d0a0274990
commit 37ccc8a2aa
2 changed files with 129 additions and 8 deletions

View File

@@ -16,11 +16,18 @@
@li mp_dirlist.sas
@param in= unquoted filepath, dataset of files or directory to zip
@param type= FILE, DATASET, DIRECTORY. (FILE / DATASET not ready yet)
@param outname= output file to create, without .zip extension
@param outpath= location for output zip file
@param type= (FILE) Valid values:
@li FILE - /full/path/and/filename.extension to a particular file
@li DATASET - a dataset containing a list of files to zip (see `incol`)
@li DIRECTORY - a directory to zip
@param outname= (FILE) Output file to create, _without_ .zip extension
@param outpath= (%sysfunc(pathname(WORK))) Parent folder for output zip file
@param incol= if DATASET input, say which column contains the filepath
<h4> Related Macros </h4>
@li mp_unzip.sas
@li mp_zip.test.sas
@version 9.2
@author Allan Bowe
@source https://github.com/sasjs/core
@@ -51,9 +58,9 @@ ods package open nopf;
set &ds;
length __command $4000;
if file_or_folder='file';
command=cats('ods package add file="',filepath
__command=cats('ods package add file="',filepath
,'" mimetype="application/x-compress";');
call execute(command);
call execute(__command);
run;
/* tidy up */
%if &debug=NO %then %do;
@@ -64,11 +71,10 @@ ods package open nopf;
data _null_;
set &in;
length __command $4000;
command=cats('ods package add file="',&incol
__command=cats('ods package add file="',&incol
,'" mimetype="application/x-compress";');
call execute(command);
call execute(__command);
run;
ods package add file="&in" mimetype="application/x-compress";
%end;

View File

@@ -0,0 +1,115 @@
/**
@file
@brief Testing mp_zip macro
<h4> SAS Macros </h4>
@li mf_mkdir.sas
@li mp_assert.sas
@li mp_zip.sas
@li mp_unzip.sas
**/
%let work=%sysfunc(pathname(work));
%let root=&work/zipme;
/* TEST 1 - zip a file */
%mf_mkdir(&root)
data _null_;
file "&root/test.txt";
put "houston, this is a test";
run;
%mp_zip(in=&root/test.txt
,type=FILE
,outpath=&work
,outname=myFile
)
%mp_unzip(ziploc="&work/myFile.zip",outdir=&work)
data _null_;
infile "&work/test.txt";
input;
call symputx('content1',_infile_);
putlog _infile_;
run;
%mp_assert(
iftrue=(
%str(&content1)=%str(houston, this is a test)
),
desc=Checking if file zip / unzip works,
outds=work.test_results
)
/* TEST 2 - zip a dataset of files */
data _null_;
file "&root/test2.txt";
put "houston, this is test2";
run;
libname tmp "&root";
data tmp.test;
filepath="&root/test2.txt";
run;
%mp_zip(in=tmp.test
,incol=filepath
,type=DATASET
,outpath=&work
,outname=myFile2
)
%mp_unzip(ziploc="&work/myFile2.zip",outdir=&work)
data _null_;
infile "&work/test2.txt";
input;
call symputx('content2',_infile_);
putlog _infile_;
run;
%mp_assert(
iftrue=(
%str(&content2)=%str(houston, this is test2)
),
desc=Checking if file zip / unzip from a dataset works,
outds=work.test_results
)
/* TEST 3 - zip a dataset of files */
%mf_mkdir(&work/out3)
%mp_zip(in=&root
,type=DIRECTORY
,outpath=&work
,outname=myFile3
)
%mp_unzip(ziploc="&work/myFile3.zip",outdir=&work/out3)
data _null_;
infile "&work/out3/test.txt";
input;
call symputx('content3a',_infile_);
putlog _infile_;
run;
data _null_;
infile "&work/out3/test2.txt";
input;
call symputx('content3b',_infile_);
putlog _infile_;
run;
%mp_assert(
iftrue=(
%str(&content3a)=%str(houston, this is a test)
and
%str(&content3b)=%str(houston, this is test2)
),
desc=Checking if file zip / unzip from a directory works,
outds=work.test_results
)