@@ -44,14 +44,19 @@ def _test_source_xml_data():
4444 import base64
4545 return base64 .b64decode (data )
4646
47+ def gen_sourcexml_and_samplesmcplgz ():
48+ import pathlib
49+ pathlib .Path ('samples.mcpl.gz' ).write_bytes (_test_samples_mcpl_gz_data ())
50+ print ("Wrote samples.mcpl.gz" )
51+ pathlib .Path ('source.xml' ).write_bytes (_test_source_xml_data ())
52+ print ("Wrote source.xml" )
53+
4754def test_resample ():
4855 import pathlib
4956 import mcpl
5057 import numpy
5158 from .resample import resample_to_mcpl
52-
53- pathlib .Path ('samples.mcpl.gz' ).write_bytes (_test_samples_mcpl_gz_data ())
54- pathlib .Path ('source.xml' ).write_bytes (_test_source_xml_data ())
59+ gen_sourcexml_and_samplesmcplgz ()
5560 outfn = 'foo_tmp_testfile.mcpl.gz'
5661 outpath = pathlib .Path (outfn )
5762 if outpath .is_file ():
@@ -89,10 +94,42 @@ def test_all():
8994 test_importpyapi ()
9095 print ("==> All tests ended OK" )
9196
97+ def gen_test_mainc (dst ):
98+ import pathlib
99+ import textwrap
100+ content = textwrap .dedent ("""
101+ #include "kdsource/kdsource.h"
102+ int main( int argc, char** argv ) {
103+ if ( argc != 2 )
104+ return 1;
105+ KDSource* kds = KDS_open(argv[1]);
106+ mcpl_outfile_t file = mcpl_create_outfile("foobar");
107+ double w_crit = KDS_w_mean(kds, 1000, NULL);
108+ printf("Resampling...\\ n");
109+ uint64_t i;
110+ mcpl_particle_t* part = mcpl_get_empty_particle(file);
111+ for(i=0; i<17; ++i){
112+ KDS_sample2(kds, part, 1, w_crit, NULL, 1);
113+ mcpl_add_particle(file, part);
114+ }
115+ mcpl_closeandgzip_outfile(file);
116+ KDS_destroy(kds);
117+ printf("Successfully sampled particles.\\ n");
118+ return 0;
119+ }
120+ """ )
121+ dst = pathlib .Path ( dst )
122+ dst .write_text ( content )
123+ print (f"Wrote { dst } " )
124+ gen_sourcexml_and_samplesmcplgz ()
125+
92126def main (argv = None ):
93127 if argv is None :
94128 import sys
95129 argv = sys .argv
130+ if '--gentestmainc' in argv [1 :]:
131+ gen_test_mainc ('main.c' )
132+ return
96133 if '--cwd' in argv [1 :]:
97134 test_all ()
98135 else :
0 commit comments