Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

Directory not found during Tests even though the folders and files are created correctly with their correct contents

Nago (1690 points)
7 14 20
in HW4 by (1.7k points)
For all the test I get a file not found error for the the first instance of a txt file in the current test folder:
For example: Test01: FileNotFoundError: [Errno 2] No such file or directory: 'test01.out/The daily dinner misspells imagination..txt'

But when I run my own tests the folders and files are correctly created and translated in their corresponding folders.

For example in my own tests if I have a source root: '...\\desktop\\sapienza\\homework\\programming\\hw4req\\hw4req\\test01'
and a target root: '...\\desktop\\sapienza\\homework\\programming\\hw4req\\hw4req\\target'

The files will be correctly created in the 'target' directory

I don't know why this happens for the test and what I'm doing wrong.
I appreciate any help given.

1 Answer

andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
Have you created the destination directory if not existent?
Nago (1690 points)
7 14 20
by (1.7k points)

I tried by using os.path.isdir to the target_root and then use os.makedirs to the target root if it doesn't exist under the begining of the Umkansanize function.

But still it seems to be the same result

andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
Have you tried to use the '/' path separator, that works fine both on Unix and windows?

Have you opened the indexes with utf8 encoding?
andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
Do not change the current directory
Nago (1690 points)
7 14 20
by (1.7k points)
edited by

I correctly use utf8 and I use os.path.join when needed so the separators should be fine I think.

i tried to get the working directory in different parts of my code by using os.getcwd and it seems to stay in the same folder during the process of  the whole program 

If it's allowed to share it I have here my test's outputs in spyder unittest in txt form

andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
Please do not use chdir.

When you get an error or a timeout your current directory remain changed and following tests fail
andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
Notice that the paths present in the index files (source and destination) use the Unix separator '/' and you will fail tests if you use the windows separator '\\'