Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pharo FileSystem: setUp of SUnit test which uses a file

I want to write a SUnit test which uses a file with the Pharo 4.0 FileSystem. I want to write a file and then later read it.

Something like this

fname := 'TabularTestExport1.xlsx'. (FileLocator temp / fname ) delete. TabularXSLXExport workbook: myWorkbook fileName: (FileLocator temp / fname ).

Questions

  1. temp directory What is the method to use for using a temporary file in a platform independant way. FileLocator temp or FileLocator tempDirectory is not implemented.

  2. deleting an existing test file How do I ensure that a file is deleted? I.e. How do I avoid a walkback in case the file does not exist.

  3. Alternatively everything could be done in the memory: 1. creation of test file, 2. exporting test file, 3. Importing test file back

like image 300
z-- Avatar asked Feb 09 '23 08:02

z--


1 Answers

For tests, unless you have a real big archive, is better to do things in memory. FileSystem provides you a way to do it, you just need to do:

fs := FileSystem memory. 

It will give you a compatible API so you can make your tests. If you want a file and not a directory, you can do:

file := FileSystem memory / 'myFile'.

EDIT: I forget a couple of things:

  1. FileLocator temp is implemented and should work fine for you. Why you say is not implemented? Are you not finding it for some reason, maybe?
  2. myFileReference ensureDelete will... well, ensure your file is deleted :)
like image 122
EstebanLM Avatar answered Feb 16 '23 02:02

EstebanLM