Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing: Assert that a file/path exists

I am attempting to create a regression test for my Installer. The regression test is a script written in Python. The test checks that the correct files have been installed in the correct place.

Is there a way to assert that a file/folder exists? I am getting a AssertionError error for the following code:

assert os.path.exists(LOCAL_INSTALL_DIR) == 1

Why am I getting this error and how can I fix it? My function:

def check_installation_files_exist():
    assert os.path.exists(LOCAL_INSTALL_DIR) == 1
    assert os.path.exists(INSTALL_DIR) == 1
    correct_install_files = normalise_file_names( os.listdir( LOCAL_INSTALL_DIR ) )
    installed_files       = normalise_file_names( os.listdir( INSTALL_DIR ) )
like image 785
sazr Avatar asked Apr 13 '13 00:04

sazr


1 Answers

The path described by LOCAL_INSTALL_DIR either does not exist, is a broken symbolic link, or you do not have permission to stat() it.

like image 58
Michael Hoffman Avatar answered Oct 21 '22 20:10

Michael Hoffman