ganga-devs / ganga

Ganga is an easy-to-use frontend for job definition and management
GNU General Public License v3.0
100 stars 159 forks source link

Utility in GangaTest utils to check if required files are generated in the output directory #2297

Closed destrex271 closed 8 months ago

destrex271 commented 9 months ago

I was in the process of writing some tests for a job. I noticed that we have a function called file_contains to check if a file contains certain content. It might be helpful to have another function that checks if some specific files exist.

For example, let's say I have a job that generates files with similar names (like abc_12.txt, abc_13.txt, etc.). One step of a unit test could be to verify if these output files were generated by my job. Such a function would be a nice utility to have.

I will also like to work on this issue.

egede commented 9 months ago

But would it do anything beyond what os.path.isfile(path) does? To simply wrap a one line function in another function is not that helpful.

destrex271 commented 9 months ago

I was thinking more on the lines of using wildcards and eliminating the need for using os directly in the tests. It will be a small function that would take a list of filenames(also wildcard entries) and just return a true or false status. Might help in getting rid of a few extra lines of code just to check if certain files are present or not.

alexanderrichards commented 8 months ago

wildcard matching can be done simply with

if not glob.glob(<pattern>)

or indeed using fnmatch or the new pathlib.Path(<directory>).glob(<pattern>)

destrex271 commented 8 months ago

Oh Ok! This makes much more sense. Thanks!